diff options
Diffstat (limited to 'indra/llcommon')
34 files changed, 421 insertions, 636 deletions
diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index 5be3919898..e83473216a 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -129,7 +129,7 @@ void ll_apr_assert_status(apr_status_t status) } // File I/O -apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, S32* sizep, apr_pool_t* pool) +apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags, S32* sizep, apr_pool_t* pool) { apr_file_t* apr_file; apr_status_t s; @@ -160,15 +160,15 @@ apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, S32* s return apr_file; } -apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, S32* sizep) +apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags, S32* sizep) { return ll_apr_file_open(filename, flags, sizep, NULL); } -apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, apr_pool_t* pool) +apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags, apr_pool_t* pool) { return ll_apr_file_open(filename, flags, NULL, pool); } -apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags) +apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags) { return ll_apr_file_open(filename, flags, NULL, NULL); } @@ -188,7 +188,7 @@ S32 ll_apr_file_read(apr_file_t* apr_file, void *buf, S32 nbytes) } } -S32 ll_apr_file_read_ex(const LLString& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes) +S32 ll_apr_file_read_ex(const std::string& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes) { if (pool == NULL) pool = gAPRPoolp; apr_file_t* filep = ll_apr_file_open(filename, APR_READ|APR_BINARY, pool); @@ -230,7 +230,7 @@ S32 ll_apr_file_write(apr_file_t* apr_file, const void *buf, S32 nbytes) } } -S32 ll_apr_file_write_ex(const LLString& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes) +S32 ll_apr_file_write_ex(const std::string& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes) { if (pool == NULL) pool = gAPRPoolp; apr_int32_t flags = APR_CREATE|APR_WRITE|APR_BINARY; @@ -287,7 +287,7 @@ S32 ll_apr_file_seek(apr_file_t* apr_file, apr_seek_where_t where, S32 offset) } } -bool ll_apr_file_remove(const LLString& filename, apr_pool_t* pool) +bool ll_apr_file_remove(const std::string& filename, apr_pool_t* pool) { apr_status_t s; if (pool == NULL) pool = gAPRPoolp; @@ -301,7 +301,7 @@ bool ll_apr_file_remove(const LLString& filename, apr_pool_t* pool) return true; } -bool ll_apr_file_rename(const LLString& filename, const LLString& newname, apr_pool_t* pool) +bool ll_apr_file_rename(const std::string& filename, const std::string& newname, apr_pool_t* pool) { apr_status_t s; if (pool == NULL) pool = gAPRPoolp; @@ -315,7 +315,7 @@ bool ll_apr_file_rename(const LLString& filename, const LLString& newname, apr_p return true; } -bool ll_apr_file_exists(const LLString& filename, apr_pool_t* pool) +bool ll_apr_file_exists(const std::string& filename, apr_pool_t* pool) { apr_file_t* apr_file; apr_status_t s; @@ -332,7 +332,7 @@ bool ll_apr_file_exists(const LLString& filename, apr_pool_t* pool) } } -S32 ll_apr_file_size(const LLString& filename, apr_pool_t* pool) +S32 ll_apr_file_size(const std::string& filename, apr_pool_t* pool) { apr_file_t* apr_file; apr_finfo_t info; @@ -358,7 +358,7 @@ S32 ll_apr_file_size(const LLString& filename, apr_pool_t* pool) } } -bool ll_apr_dir_make(const LLString& dirname, apr_pool_t* pool) +bool ll_apr_dir_make(const std::string& dirname, apr_pool_t* pool) { apr_status_t s; if (pool == NULL) pool = gAPRPoolp; @@ -372,7 +372,7 @@ bool ll_apr_dir_make(const LLString& dirname, apr_pool_t* pool) return true; } -bool ll_apr_dir_remove(const LLString& dirname, apr_pool_t* pool) +bool ll_apr_dir_remove(const std::string& dirname, apr_pool_t* pool) { apr_status_t s; if (pool == NULL) pool = gAPRPoolp; diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index 3927d5f014..403d504932 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -130,24 +130,24 @@ typedef LLAtomic32<S32> LLAtomicS32; #define LL_APR_WB (APR_CREATE|APR_TRUNCATE|APR_WRITE|APR_BINARY) // "wb" #define LL_APR_RPB (APR_READ|APR_WRITE|APR_BINARY) // "r+b" #define LL_APR_WPB (APR_CREATE|APR_TRUNCATE|APR_READ|APR_WRITE|APR_BINARY) // "w+b" -apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, S32* sizep, apr_pool_t* pool); -apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, S32* sizep); -apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags, apr_pool_t* pool); -apr_file_t* ll_apr_file_open(const LLString& filename, apr_int32_t flags); +apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags, S32* sizep, apr_pool_t* pool); +apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags, S32* sizep); +apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags, apr_pool_t* pool); +apr_file_t* ll_apr_file_open(const std::string& filename, apr_int32_t flags); // Returns actual offset, -1 if seek fails S32 ll_apr_file_seek(apr_file_t* apr_file, apr_seek_where_t where, S32 offset); // Returns bytes read/written, 0 if read/write fails: S32 ll_apr_file_read(apr_file_t* apr_file, void* buf, S32 nbytes); -S32 ll_apr_file_read_ex(const LLString& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes); +S32 ll_apr_file_read_ex(const std::string& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes); S32 ll_apr_file_write(apr_file_t* apr_file, const void* buf, S32 nbytes); -S32 ll_apr_file_write_ex(const LLString& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes); +S32 ll_apr_file_write_ex(const std::string& filename, apr_pool_t* pool, void *buf, S32 offset, S32 nbytes); // returns false if failure: -bool ll_apr_file_remove(const LLString& filename, apr_pool_t* pool = NULL); -bool ll_apr_file_rename(const LLString& filename, const LLString& newname, apr_pool_t* pool = NULL); -bool ll_apr_file_exists(const LLString& filename, apr_pool_t* pool = NULL); -S32 ll_apr_file_size(const LLString& filename, apr_pool_t* pool = NULL); -bool ll_apr_dir_make(const LLString& dirname, apr_pool_t* pool = NULL); -bool ll_apr_dir_remove(const LLString& dirname, apr_pool_t* pool = NULL); +bool ll_apr_file_remove(const std::string& filename, apr_pool_t* pool = NULL); +bool ll_apr_file_rename(const std::string& filename, const std::string& newname, apr_pool_t* pool = NULL); +bool ll_apr_file_exists(const std::string& filename, apr_pool_t* pool = NULL); +S32 ll_apr_file_size(const std::string& filename, apr_pool_t* pool = NULL); +bool ll_apr_dir_make(const std::string& dirname, apr_pool_t* pool = NULL); +bool ll_apr_dir_remove(const std::string& dirname, apr_pool_t* pool = NULL); /** * @brief Function which approprately logs error or remains quiet on diff --git a/indra/llcommon/llassettype.cpp b/indra/llcommon/llassettype.cpp index 06504b53fd..368c85acb0 100644 --- a/indra/llcommon/llassettype.cpp +++ b/indra/llcommon/llassettype.cpp @@ -75,7 +75,7 @@ asset_info_t asset_types[] = LLAssetType::EType LLAssetType::getType(const std::string& sin) { std::string s = sin; - LLString::toUpper(s); + LLStringUtil::toUpper(s); for (S32 idx = 0; ;idx++) { asset_info_t* info = asset_types + idx; @@ -181,9 +181,14 @@ const char* LLAssetType::lookup( LLAssetType::EType type ) // static LLAssetType::EType LLAssetType::lookup( const char* name ) { + return lookup(ll_safe_string(name)); +} + +LLAssetType::EType LLAssetType::lookup( const std::string& name ) +{ for( S32 i = 0; i < AT_COUNT; i++ ) { - if( 0 == strcmp(name, mAssetTypeNames[i]) ) + if( name == mAssetTypeNames[i] ) { // match return (EType)i; @@ -208,9 +213,14 @@ const char* LLAssetType::lookupHumanReadable(LLAssetType::EType type) // static LLAssetType::EType LLAssetType::lookupHumanReadable( const char* name ) { + return lookupHumanReadable(ll_safe_string(name)); +} + +LLAssetType::EType LLAssetType::lookupHumanReadable( const std::string& name ) +{ for( S32 i = 0; i < AT_COUNT; i++ ) { - if( 0 == strcmp(name, mAssetTypeHumanNames[i]) ) + if( name == mAssetTypeHumanNames[i] ) { // match return (EType)i; diff --git a/indra/llcommon/llassettype.h b/indra/llcommon/llassettype.h index f71e0b98cd..ad254703f0 100644 --- a/indra/llcommon/llassettype.h +++ b/indra/llcommon/llassettype.h @@ -145,11 +145,13 @@ public: }; // machine transation between type and strings - static EType lookup(const char* name); + static EType lookup(const char* name); // safe conversion to std::string, *TODO: deprecate + static EType lookup(const std::string& name); static const char* lookup(EType type); // translation from a type to a human readable form. - static EType lookupHumanReadable( const char* name ); + static EType lookupHumanReadable( const char* name ); // safe conversion to std::string, *TODO: deprecate + static EType lookupHumanReadable( const std::string& name ); static const char* lookupHumanReadable(EType type); static EDragAndDropType lookupDragAndDropType( EType ); diff --git a/indra/llcommon/llchat.h b/indra/llcommon/llchat.h index 0ae16380b4..b6f84b25b5 100644 --- a/indra/llcommon/llchat.h +++ b/indra/llcommon/llchat.h @@ -68,7 +68,7 @@ typedef enum e_chat_audible_level class LLChat { public: - LLChat(const LLString& text = LLString::null) + LLChat(const std::string& text = LLStringUtil::null) : mText(text), mFromName(), mFromID(), @@ -80,8 +80,8 @@ public: mPosAgent() { } - LLString mText; // UTF-8 line of text - LLString mFromName; // agent or object name + std::string mText; // UTF-8 line of text + std::string mFromName; // agent or object name LLUUID mFromID; // agent id or object id EChatSourceType mSourceType; EChatType mChatType; diff --git a/indra/llcommon/llcrc.cpp b/indra/llcommon/llcrc.cpp index 0836ccb66b..ea90b4f22f 100644 --- a/indra/llcommon/llcrc.cpp +++ b/indra/llcommon/llcrc.cpp @@ -163,9 +163,9 @@ void LLCRC::update(const U8* buffer, size_t buffer_size) } } -void LLCRC::update(const char* filename) +void LLCRC::update(const std::string& filename) { - if (!filename) + if (filename.empty()) { llerrs << "No filename specified" << llendl; return; diff --git a/indra/llcommon/llcrc.h b/indra/llcommon/llcrc.h index 287c1fbc41..8eab84799f 100644 --- a/indra/llcommon/llcrc.h +++ b/indra/llcommon/llcrc.h @@ -60,7 +60,7 @@ public: U32 getCRC() const; void update(U8 next_byte); void update(const U8* buffer, size_t buffer_size); - void update(const char *filename); + void update(const std::string& filename); #ifdef _DEBUG // This function runs tests to make sure the crc is diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp index 1d85bc0e70..b3d3122397 100644 --- a/indra/llcommon/llerror.cpp +++ b/indra/llcommon/llerror.cpp @@ -102,7 +102,7 @@ namespace { public: RecordToFile(const std::string& filename) { - mFile.open(filename.c_str(), llofstream::out | llofstream::app); + mFile.open(filename, llofstream::out | llofstream::app); if (!mFile) { llinfos << "Error setting log file to " << filename << llendl; @@ -196,7 +196,7 @@ namespace { virtual void recordMessage(LLError::ELevel level, const std::string& message) { - mBuffer.addLine(message.c_str()); + mBuffer.addLine(message); } private: @@ -305,7 +305,7 @@ namespace std::string file = dirBase + "logcontrol-dev.xml"; llstat stat_info; - if (LLFile::stat(file.c_str(), &stat_info)) { + if (LLFile::stat(file, &stat_info)) { // NB: stat returns non-zero if it can't read the file, for example // if it doesn't exist. LLFile has no better abstraction for // testing for file existence. @@ -321,7 +321,7 @@ namespace LLSD configuration; { - llifstream file(filename().c_str()); + llifstream file(filename()); if (file.is_open()) { LLSDSerialize::fromXML(configuration, file); diff --git a/indra/llcommon/llevent.cpp b/indra/llcommon/llevent.cpp index 292d0909a4..4f3962154e 100644 --- a/indra/llcommon/llevent.cpp +++ b/indra/llcommon/llevent.cpp @@ -219,7 +219,7 @@ std::vector<LLListenerEntry> LLSimpleDispatcher::getListeners() const bool LLSimpleDispatcher::fireEvent(LLPointer<LLEvent> event, LLSD filter) { std::vector<LLListenerEntry>::iterator itor; - LLString filter_string = filter.asString(); + std::string filter_string = filter.asString(); for (itor=mListeners.begin(); itor!=mListeners.end(); ++itor) { LLListenerEntry& entry = *itor; diff --git a/indra/llcommon/llfile.cpp b/indra/llcommon/llfile.cpp index 6b8f8e68c5..8f7a8ded63 100644 --- a/indra/llcommon/llfile.cpp +++ b/indra/llcommon/llfile.cpp @@ -44,7 +44,7 @@ using namespace std; // static -int LLFile::mkdir(const char* dirname, int perms) +int LLFile::mkdir(const std::string& dirname, int perms) { #if LL_WINDOWS // permissions are ignored on Windows @@ -52,12 +52,12 @@ int LLFile::mkdir(const char* dirname, int perms) llutf16string utf16dirname = utf8str_to_utf16str(utf8dirname); return _wmkdir(utf16dirname.c_str()); #else - return ::mkdir(dirname, (mode_t)perms); + return ::mkdir(dirname.c_str(), (mode_t)perms); #endif } // static -int LLFile::rmdir(const char* dirname) +int LLFile::rmdir(const std::string& dirname) { #if LL_WINDOWS // permissions are ignored on Windows @@ -65,29 +65,29 @@ int LLFile::rmdir(const char* dirname) llutf16string utf16dirname = utf8str_to_utf16str(utf8dirname); return _wrmdir(utf16dirname.c_str()); #else - return ::rmdir(dirname); + return ::rmdir(dirname.c_str()); #endif } // static -LLFILE* LLFile::fopen(const char* filename, const char* mode) /* Flawfinder: ignore */ +LLFILE* LLFile::fopen(const std::string& filename, const char* mode) /* Flawfinder: ignore */ { #if LL_WINDOWS std::string utf8filename = filename; - std::string utf8mode = mode; + std::string utf8mode = std::string(mode); llutf16string utf16filename = utf8str_to_utf16str(utf8filename); llutf16string utf16mode = utf8str_to_utf16str(utf8mode); return _wfopen(utf16filename.c_str(),utf16mode.c_str()); #else - return ::fopen(filename,mode); /* Flawfinder: ignore */ + return ::fopen(filename.c_str(),mode); /* Flawfinder: ignore */ #endif } -LLFILE* LLFile::_fsopen(const char* filename, const char* mode, int sharingFlag) +LLFILE* LLFile::_fsopen(const std::string& filename, const char* mode, int sharingFlag) { #if LL_WINDOWS std::string utf8filename = filename; - std::string utf8mode = mode; + std::string utf8mode = std::string(mode); llutf16string utf16filename = utf8str_to_utf16str(utf8filename); llutf16string utf16mode = utf8str_to_utf16str(utf8mode); return _wfsopen(utf16filename.c_str(),utf16mode.c_str(),sharingFlag); @@ -97,18 +97,18 @@ LLFILE* LLFile::_fsopen(const char* filename, const char* mode, int sharingFlag) #endif } -int LLFile::remove(const char* filename) +int LLFile::remove(const std::string& filename) { #if LL_WINDOWS std::string utf8filename = filename; llutf16string utf16filename = utf8str_to_utf16str(utf8filename); return _wremove(utf16filename.c_str()); #else - return ::remove(filename); + return ::remove(filename.c_str()); #endif } -int LLFile::rename(const char* filename, const char* newname) +int LLFile::rename(const std::string& filename, const std::string& newname) { #if LL_WINDOWS std::string utf8filename = filename; @@ -117,29 +117,29 @@ int LLFile::rename(const char* filename, const char* newname) llutf16string utf16newname = utf8str_to_utf16str(utf8newname); return _wrename(utf16filename.c_str(),utf16newname.c_str()); #else - return ::rename(filename,newname); + return ::rename(filename.c_str(),newname.c_str()); #endif } -int LLFile::stat(const char* filename, llstat* filestatus) +int LLFile::stat(const std::string& filename, llstat* filestatus) { #if LL_WINDOWS std::string utf8filename = filename; llutf16string utf16filename = utf8str_to_utf16str(utf8filename); return _wstat(utf16filename.c_str(),filestatus); #else - return ::stat(filename,filestatus); + return ::stat(filename.c_str(),filestatus); #endif } -bool LLFile::isdir(const char *filename) +bool LLFile::isdir(const std::string& filename) { llstat st; return stat(filename, &st) == 0 && S_ISDIR(st.st_mode); } -bool LLFile::isfile(const char *filename) +bool LLFile::isfile(const std::string& filename) { llstat st; @@ -181,7 +181,7 @@ const char *LLFile::tmpdir() #if USE_LLFILESTREAMS -LLFILE * LLFile::_Fiopen(const char *filename, std::ios::openmode mode,int) // protection currently unused +LLFILE * LLFile::_Fiopen(const std::string& filename, std::ios::openmode mode,int) // protection currently unused { // open a file static const char *mods[] = { // fopen mode strings corresponding to valid[i] @@ -250,7 +250,7 @@ void llifstream::close() } } -void llifstream::open(const char* _Filename, /* Flawfinder: ignore */ +void llifstream::open(const std::string& _Filename, /* Flawfinder: ignore */ ios_base::openmode _Mode, int _Prot) { // open a C stream with specified mode @@ -282,7 +282,7 @@ llifstream::~llifstream() delete _Filebuffer; } -llifstream::llifstream(const char *_Filename, +llifstream::llifstream(const std::string& _Filename, ios_base::openmode _Mode, int _Prot) : std::basic_istream< char , std::char_traits< char > >(NULL,true),_Filebuffer(NULL),_ShouldClose(false) @@ -301,7 +301,7 @@ bool llofstream::is_open() const return false; } -void llofstream::open(const char* _Filename, /* Flawfinder: ignore */ +void llofstream::open(const std::string& _Filename, /* Flawfinder: ignore */ ios_base::openmode _Mode, int _Prot) { // open a C stream with specified mode @@ -327,7 +327,7 @@ void llofstream::close() } } -llofstream::llofstream(const char *_Filename, +llofstream::llofstream(const std::string& _Filename, std::ios_base::openmode _Mode, int _Prot) : std::basic_ostream<char,std::char_traits < char > >(NULL,true),_Filebuffer(NULL),_ShouldClose(false) diff --git a/indra/llcommon/llfile.h b/indra/llcommon/llfile.h index bd51ac2aa9..a196dad814 100644 --- a/indra/llcommon/llfile.h +++ b/indra/llcommon/llfile.h @@ -67,24 +67,27 @@ typedef struct stat llstat; # define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR) #endif +#include "llstring.h" // safe char* -> std::string conversion + class LLFile { public: // All these functions take UTF8 path/filenames. - static LLFILE* fopen(const char* filename,const char* accessmode); /* Flawfinder: ignore */ - static LLFILE* _fsopen(const char* filename,const char* accessmode,int sharingFlag); + static LLFILE* fopen(const std::string& filename,const char* accessmode); /* Flawfinder: ignore */ + static LLFILE* _fsopen(const std::string& filename,const char* accessmode,int sharingFlag); // perms is a permissions mask like 0777 or 0700. In most cases it will // be overridden by the user's umask. It is ignored on Windows. - static int mkdir(const char* filename, int perms = 0700); - - static int rmdir(const char* filename); - static int remove(const char* filename); - static int rename(const char* filename,const char* newname); - static int stat(const char* filename,llstat* file_status); - static bool isdir(const char* filename); - static bool isfile(const char* filename); - static LLFILE * _Fiopen(const char *filename, std::ios::openmode mode,int); // protection currently unused + static int mkdir(const std::string& filename, int perms = 0700); + + static int rmdir(const std::string& filename); + static int remove(const std::string& filename); + static int rename(const std::string& filename,const std::string& newname); + static int stat(const std::string& filename,llstat* file_status); + static bool isdir(const std::string& filename); + static bool isfile(const std::string& filename); + static LLFILE * _Fiopen(const std::string& filename, std::ios::openmode mode,int); // protection currently unused + static const char * tmpdir(); }; @@ -104,7 +107,7 @@ public: { // construct unopened } - explicit llifstream(const char *_Filename, + explicit llifstream(const std::string& _Filename, ios_base::openmode _Mode = ios_base::in, int _Prot = (int)ios_base::_Openprot); @@ -121,7 +124,7 @@ public: return _Filebuffer; } bool is_open() const; - void open(const char* _Filename, /* Flawfinder: ignore */ + void open(const std::string& _Filename, /* Flawfinder: ignore */ ios_base::openmode _Mode = ios_base::in, int _Prot = (int)ios_base::_Openprot); void close(); @@ -144,7 +147,7 @@ public: { // construct unopened } - explicit llofstream(const char *_Filename, + explicit llofstream(const std::string& _Filename, std::ios_base::openmode _Mode = ios_base::out, int _Prot = (int)std::ios_base::_Openprot); @@ -165,7 +168,7 @@ public: bool is_open() const; - void open(const char *_Filename,ios_base::openmode _Mode = ios_base::out,int _Prot = (int)ios_base::_Openprot); /* Flawfinder: ignore */ + void open(const std::string& _Filename,ios_base::openmode _Mode = ios_base::out,int _Prot = (int)ios_base::_Openprot); /* Flawfinder: ignore */ void close(); @@ -178,8 +181,45 @@ private: #else //Use standard file streams on non windows platforms -#define llifstream std::ifstream -#define llofstream std::ofstream +//#define llifstream std::ifstream +//#define llofstream std::ofstream + +class llifstream : public std::ifstream +{ +public: + llifstream() : std::ifstream() + { + } + + explicit llifstream(const std::string& _Filename, std::_Ios_Openmode _Mode = in) + : std::ifstream(_Filename.c_str(), _Mode) + { + } + void open(const std::string& _Filename, std::_Ios_Openmode _Mode = in) /* Flawfinder: ignore */ + { + std::ifstream::open(_Filename.c_str(), _Mode); + } +}; + + +class llofstream : public std::ofstream +{ +public: + llofstream() : std::ofstream() + { + } + + explicit llofstream(const std::string& _Filename, std::_Ios_Openmode _Mode = out) + : std::ofstream(_Filename.c_str(), _Mode) + { + } + + void open(const std::string& _Filename, std::_Ios_Openmode _Mode = out) /* Flawfinder: ignore */ + { + std::ofstream::open(_Filename.c_str(), _Mode); + } + +}; #endif diff --git a/indra/llcommon/llfixedbuffer.cpp b/indra/llcommon/llfixedbuffer.cpp index 44bb953f80..fde4db98a1 100644 --- a/indra/llcommon/llfixedbuffer.cpp +++ b/indra/llcommon/llfixedbuffer.cpp @@ -54,7 +54,7 @@ void LLFixedBuffer::clear() } -void LLFixedBuffer::addLine(const LLString& utf8line) +void LLFixedBuffer::addLine(const std::string& utf8line) { LLWString wstring = utf8str_to_wstring(utf8line); LLFixedBuffer::addLine(wstring); diff --git a/indra/llcommon/llfixedbuffer.h b/indra/llcommon/llfixedbuffer.h index 148c0e60db..0a23fb30d1 100644 --- a/indra/llcommon/llfixedbuffer.h +++ b/indra/llcommon/llfixedbuffer.h @@ -52,7 +52,7 @@ public: std::deque<S32> mLineLengths; void clear(); // Clear the buffer, and reset it. - virtual void addLine(const LLString& utf8line); + virtual void addLine(const std::string& utf8line); virtual void addLine(const LLWString& line); // Get lines currently in the buffer, up to max_size chars, max_length lines diff --git a/indra/llcommon/llliveappconfig.cpp b/indra/llcommon/llliveappconfig.cpp index 76432770a3..418a34b662 100644 --- a/indra/llcommon/llliveappconfig.cpp +++ b/indra/llcommon/llliveappconfig.cpp @@ -51,7 +51,7 @@ void LLLiveAppConfig::loadFile() { llinfos << "LLLiveAppConfig::loadFile(): reading from " << filename() << llendl; - llifstream file(filename().c_str()); + llifstream file(filename()); LLSD config; if (file.is_open()) { diff --git a/indra/llcommon/lllivefile.cpp b/indra/llcommon/lllivefile.cpp index cb3ce0f8d2..8c625bce90 100644 --- a/indra/llcommon/lllivefile.cpp +++ b/indra/llcommon/lllivefile.cpp @@ -93,7 +93,7 @@ bool LLLiveFile::Impl::check() // Stat the file to see if it exists and when it was last modified. llstat stat_data; - int res = LLFile::stat(mFilename.c_str(), &stat_data); + int res = LLFile::stat(mFilename, &stat_data); if (res) { diff --git a/indra/llcommon/llprocessor.cpp b/indra/llcommon/llprocessor.cpp index 29a3cf32a8..87c6e57fdd 100644 --- a/indra/llcommon/llprocessor.cpp +++ b/indra/llcommon/llprocessor.cpp @@ -2216,12 +2216,12 @@ bool CProcessor::CPUInfoToText(char *strBuffer, unsigned int uiMaxLen) return true; } -// bool CProcessor::WriteInfoTextFile(const char *strFilename) +// bool CProcessor::WriteInfoTextFile(const std::string& strFilename) // =========================================================== // Takes use of CProcessor::CPUInfoToText and saves the string to a // file /////////////////////////////////////////////////////////////////// -bool CProcessor::WriteInfoTextFile(const char *strFilename) +bool CProcessor::WriteInfoTextFile(const std::string& strFilename) { char buf[16384]; /* Flawfinder: ignore */ diff --git a/indra/llcommon/llprocessor.h b/indra/llcommon/llprocessor.h index 6b966c5339..30bc14d6ce 100644 --- a/indra/llcommon/llprocessor.h +++ b/indra/llcommon/llprocessor.h @@ -188,7 +188,7 @@ public: F64 GetCPUFrequency(unsigned int uiMeasureMSecs); const ProcessorInfo *GetCPUInfo(); bool CPUInfoToText(char *strBuffer, unsigned int uiMaxLen); - bool WriteInfoTextFile(const char *strFilename); + bool WriteInfoTextFile(const std::string& strFilename); }; diff --git a/indra/llcommon/llsd.h b/indra/llcommon/llsd.h index 307d73608c..0382fb1360 100644 --- a/indra/llcommon/llsd.h +++ b/indra/llcommon/llsd.h @@ -394,7 +394,7 @@ std::ostream& operator<<(std::ostream& s, const LLSD& llsd); - as UTF8 encoded strings (making not like UUID<->String) - as Base64 or Base96 encoded (making like UUID<->String) - Conversions to std::string and LLUUID do not result in easy assignment - to std::string, LLString or LLUUID due to non-unique conversion paths + to std::string, std::string or LLUUID due to non-unique conversion paths */ #endif // LL_LLSD_NEW_H diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index 6bb75439a2..d496230dd8 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -1230,8 +1230,7 @@ void LLSDFormatter::realFormat(const std::string& format) void LLSDFormatter::formatReal(LLSD::Real real, std::ostream& ostr) const { - char buffer[MAX_STRING]; /* Flawfinder: ignore */ - snprintf(buffer, MAX_STRING, mRealFormat.c_str(), real); /* Flawfinder: ignore */ + std::string buffer = llformat(mRealFormat.c_str(), real); ostr << buffer; } diff --git a/indra/llcommon/llsdserialize_xml.cpp b/indra/llcommon/llsdserialize_xml.cpp index 592dfc9bc0..e23f765957 100644 --- a/indra/llcommon/llsdserialize_xml.cpp +++ b/indra/llcommon/llsdserialize_xml.cpp @@ -63,7 +63,7 @@ S32 LLSDXMLFormatter::format(const LLSD& data, std::ostream& ostr, U32 options) { std::streamsize old_precision = ostr.precision(25); - LLString post = ""; + std::string post; if (options & LLSDFormatter::OPTIONS_PRETTY) { post = "\n"; @@ -79,8 +79,8 @@ S32 LLSDXMLFormatter::format(const LLSD& data, std::ostream& ostr, U32 options) S32 LLSDXMLFormatter::format_impl(const LLSD& data, std::ostream& ostr, U32 options, U32 level) const { S32 format_count = 1; - LLString pre = ""; - LLString post = ""; + std::string pre; + std::string post; if (options & LLSDFormatter::OPTIONS_PRETTY) { diff --git a/indra/llcommon/llsdutil.cpp b/indra/llcommon/llsdutil.cpp index 6f26447695..137539cc04 100644 --- a/indra/llcommon/llsdutil.cpp +++ b/indra/llcommon/llsdutil.cpp @@ -145,12 +145,11 @@ LLSD ll_binary_from_string(const LLSD& sd) { std::vector<U8> binary_value; - LLString string_value = sd.asString(); - const char* string_p = string_value.c_str(); - while (*string_p) + std::string string_value = sd.asString(); + for (std::string::iterator iter = string_value.begin(); + iter != string_value.end(); ++iter) { - binary_value.push_back(*string_p); - string_p++; + binary_value.push_back(*iter); } binary_value.push_back('\0'); diff --git a/indra/llcommon/llsecondlifeurls.cpp b/indra/llcommon/llsecondlifeurls.cpp index bf09453c16..207d704f2a 100644 --- a/indra/llcommon/llsecondlifeurls.cpp +++ b/indra/llcommon/llsecondlifeurls.cpp @@ -32,56 +32,56 @@ #include "linden_common.h" #include "llsecondlifeurls.h" -const char CREATE_ACCOUNT_URL[] = - "http://secondlife.com/registration/"; +const std::string CREATE_ACCOUNT_URL ( + "http://secondlife.com/registration/"); -const char MANAGE_ACCOUNT[] = - "http://secondlife.com/account/"; +const std::string MANAGE_ACCOUNT ( + "http://secondlife.com/account/"); -const char AUCTION_URL[] = - "http://secondlife.com/auctions/auction-detail.php?id="; +const std::string AUCTION_URL ( + "http://secondlife.com/auctions/auction-detail.php?id="); -const char EVENTS_URL[] = - "http://secondlife.com/events/"; +const std::string EVENTS_URL ( + "http://secondlife.com/events/"); -const char TIER_UP_URL[] = - "http://secondlife.com/app/landtier"; +const std::string TIER_UP_URL ( + "http://secondlife.com/app/landtier"); -const char LAND_URL[] = - "http://secondlife.com/app/landtier"; +const std::string LAND_URL ( + "http://secondlife.com/app/landtier"); -const char UPGRADE_TO_PREMIUM_URL[] = - "http://secondlife.com/app/upgrade/"; +const std::string UPGRADE_TO_PREMIUM_URL ( + "http://secondlife.com/app/upgrade/"); -const char DIRECTX_9_URL[] = - "http://secondlife.com/support/"; +const std::string DIRECTX_9_URL ( + "http://secondlife.com/support/"); -const char AMD_AGP_URL[] = - "http://secondlife.com/support/"; +const std::string AMD_AGP_URL ( + "http://secondlife.com/support/"); -const char VIA_URL[] = - "http://secondlife.com/support/"; +const std::string VIA_URL ( + "http://secondlife.com/support/"); -const char SUPPORT_URL[] = - "http://secondlife.com/support/"; +const std::string SUPPORT_URL ( + "http://secondlife.com/support/"); -const char INTEL_CHIPSET_URL[] = - "http://secondlife.com/support/"; +const std::string INTEL_CHIPSET_URL ( + "http://secondlife.com/support/"); -const char SIS_CHIPSET_URL[] = - "http://secondlife.com/support/"; +const std::string SIS_CHIPSET_URL ( + "http://secondlife.com/support/"); -const char BLOGS_URL[] = - "http://blog.secondlife.com/"; +const std::string BLOGS_URL ( + "http://blog.secondlife.com/"); -const char BUY_CURRENCY_URL[] = - "http://secondlife.com/app/currency/"; +const std::string BUY_CURRENCY_URL ( + "http://secondlife.com/app/currency/"); -const char LSL_DOC_URL[] = - "http://secondlife.com/app/lsldoc/"; +const std::string LSL_DOC_URL ( + "http://secondlife.com/app/lsldoc/"); -const char SL_KB_URL[] = - "http://secondlife.com/knowledgebase/"; +const std::string SL_KB_URL ( + "http://secondlife.com/knowledgebase/"); -const char RELEASE_NOTES[] = "releasenotes.txt"; +const std::string RELEASE_NOTES ( "releasenotes.txt"); diff --git a/indra/llcommon/llsecondlifeurls.h b/indra/llcommon/llsecondlifeurls.h index b8d8aa2402..0847c8378b 100644 --- a/indra/llcommon/llsecondlifeurls.h +++ b/indra/llcommon/llsecondlifeurls.h @@ -33,46 +33,46 @@ #define LL_LLSECONDLIFEURLS_H // Account registration web page -extern const char CREATE_ACCOUNT_URL[]; +extern const std::string CREATE_ACCOUNT_URL; // Manage Account -extern const char MANAGE_ACCOUNT[]; +extern const std::string MANAGE_ACCOUNT; -extern const char AUCTION_URL[]; +extern const std::string AUCTION_URL; -extern const char EVENTS_URL[]; +extern const std::string EVENTS_URL; // Tier up to a new land level. -extern const char TIER_UP_URL[]; +extern const std::string TIER_UP_URL; // Tier up to a new land level. -extern const char LAND_URL[]; +extern const std::string LAND_URL; // Upgrade from basic membership to premium membership -extern const char UPGRADE_TO_PREMIUM_URL[]; +extern const std::string UPGRADE_TO_PREMIUM_URL; // How to get DirectX 9 -extern const char DIRECTX_9_URL[]; +extern const std::string DIRECTX_9_URL; // Out of date VIA chipset -extern const char VIA_URL[]; +extern const std::string VIA_URL; // Support URL -extern const char SUPPORT_URL[]; +extern const std::string SUPPORT_URL; // Linden Blogs page -extern const char BLOGS_URL[]; +extern const std::string BLOGS_URL; // Currency page -extern const char BUY_CURRENCY_URL[]; +extern const std::string BUY_CURRENCY_URL; // LSL script wiki -extern const char LSL_DOC_URL[]; +extern const std::string LSL_DOC_URL; // SL KnowledgeBase page -extern const char SL_KB_URL[]; +extern const std::string SL_KB_URL; // Local Url Release Notes -extern const char RELEASE_NOTES[]; +extern const std::string RELEASE_NOTES; #endif diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp index 3a8756a31f..0d50919e26 100644 --- a/indra/llcommon/llstring.cpp +++ b/indra/llcommon/llstring.cpp @@ -1,6 +1,6 @@ /** * @file llstring.cpp - * @brief String utility functions and the LLString class. + * @brief String utility functions and the std::string class. * * $LicenseInfo:firstyear=2001&license=viewergpl$ * @@ -47,6 +47,12 @@ std::string ll_safe_string(const char* in) return std::string(); } +std::string ll_safe_string(const char* in, S32 maxlen) +{ + if(in) return std::string(in, maxlen); + return std::string(); +} + U8 hex_as_nybble(char hex) { if((hex >= '0') && (hex <= '9')) @@ -65,7 +71,7 @@ U8 hex_as_nybble(char hex) } -bool _read_file_into_string(std::string& str, const char* filename) +bool _read_file_into_string(std::string& str, const std::string& filename) { llifstream ifs(filename, llifstream::binary); if (!ifs.is_open()) @@ -174,20 +180,6 @@ S32 utf16chars_to_wchar(const U16* inchars, llwchar* outchar) return inchars - base; } -S32 utf16chars_to_utf8chars(const U16* inchars, char* outchars, S32* nchars8p) -{ - // Get 32 bit char32 - llwchar char32; - S32 nchars16 = utf16chars_to_wchar(inchars, &char32); - // Convert to utf8 - S32 nchars8 = wchar_to_utf8chars(char32, outchars); - if (nchars8p) - { - *nchars8p = nchars8; - } - return nchars16; -} - llutf16string wstring_to_utf16str(const LLWString &utf32str, S32 len) { llutf16string out; @@ -216,7 +208,7 @@ llutf16string wstring_to_utf16str(const LLWString &utf32str) return wstring_to_utf16str(utf32str, len); } -llutf16string utf8str_to_utf16str ( const LLString& utf8str ) +llutf16string utf8str_to_utf16str ( const std::string& utf8str ) { LLWString wstr = utf8str_to_wstring ( utf8str ); return wstring_to_utf16str ( wstr ); @@ -492,210 +484,10 @@ std::string utf16str_to_utf8str(const llutf16string& utf16str, S32 len) return wstring_to_utf8str(utf16str_to_wstring(utf16str, len), len); } - -//LLWString wstring_truncate(const LLWString &wstr, const S32 max_len) -//{ -// return wstr.substr(0, llmin((S32)wstr.length(), max_len)); -//} -// -// -//LLWString wstring_trim(const LLWString &wstr) -//{ -// LLWString outstr; -// outstr = wstring_trimhead(wstr); -// outstr = wstring_trimtail(outstr); -// return outstr; -//} -// -// -//LLWString wstring_trimhead(const LLWString &wstr) -//{ -// if(wstr.empty()) -// { -// return wstr; -// } -// -// S32 i = 0; -// while((i < (S32)wstr.length()) && iswspace(wstr[i])) -// { -// i++; -// } -// return wstr.substr(i, wstr.length() - i); -//} -// -// -//LLWString wstring_trimtail(const LLWString &wstr) -//{ -// if(wstr.empty()) -// { -// return wstr; -// } -// -// S32 len = (S32)wstr.length(); -// -// S32 i = len - 1; -// while (i >= 0 && iswspace(wstr[i])) -// { -// i--; -// } -// -// if (i >= 0) -// { -// return wstr.substr(0, i + 1); -// } -// return wstr; -//} -// -// -//LLWString wstring_copyinto(const LLWString &dest, const LLWString &src, const S32 insert_offset) -//{ -// llassert( insert_offset <= (S32)dest.length() ); -// -// LLWString out_str = dest.substr(0, insert_offset); -// out_str += src; -// LLWString tail = dest.substr(insert_offset); -// out_str += tail; -// -// return out_str; -//} - - -//LLWString wstring_detabify(const LLWString &wstr, const S32 num_spaces) -//{ -// LLWString out_str; -// // Replace tabs with spaces -// for (S32 i = 0; i < (S32)wstr.length(); i++) -// { -// if (wstr[i] == '\t') -// { -// for (S32 j = 0; j < num_spaces; j++) -// out_str += ' '; -// } -// else -// { -// out_str += wstr[i]; -// } -// } -// return out_str; -//} - - -//LLWString wstring_makeASCII(const LLWString &wstr) -//{ -// // Replace non-ASCII chars with replace_char -// LLWString out_str = wstr; -// for (S32 i = 0; i < (S32)out_str.length(); i++) -// { -// if (out_str[i] > 0x7f) -// { -// out_str[i] = LL_UNKNOWN_CHAR; -// } -// } -// return out_str; -//} - - -//LLWString wstring_substChar(const LLWString &wstr, const llwchar target_char, const llwchar replace_char) -//{ -// // Replace all occurences of target_char with replace_char -// LLWString out_str = wstr; -// for (S32 i = 0; i < (S32)out_str.length(); i++) -// { -// if (out_str[i] == target_char) -// { -// out_str[i] = replace_char; -// } -// } -// return out_str; -//} -// -// -//LLWString wstring_tolower(const LLWString &wstr) -//{ -// LLWString out_str = wstr; -// for (S32 i = 0; i < (S32)out_str.length(); i++) -// { -// out_str[i] = towlower(out_str[i]); -// } -// return out_str; -//} -// -// -//LLWString wstring_convert_to_lf(const LLWString &wstr) -//{ -// const llwchar CR = 13; -// // Remove carriage returns from string with CRLF -// LLWString out_str; -// -// for (S32 i = 0; i < (S32)wstr.length(); i++) -// { -// if (wstr[i] != CR) -// { -// out_str += wstr[i]; -// } -// } -// return out_str; -//} -// -// -//LLWString wstring_convert_to_crlf(const LLWString &wstr) -//{ -// const llwchar LF = 10; -// const llwchar CR = 13; -// // Remove carriage returns from string with CRLF -// LLWString out_str; -// -// for (S32 i = 0; i < (S32)wstr.length(); i++) -// { -// if (wstr[i] == LF) -// { -// out_str += CR; -// } -// out_str += wstr[i]; -// } -// return out_str; -//} - - -//S32 wstring_compare_insensitive(const LLWString &lhs, const LLWString &rhs) -//{ -// -// if (lhs == rhs) -// { -// return 0; -// } -// -// if (lhs.empty()) -// { -// return rhs.empty() ? 0 : 1; -// } -// -// if (rhs.empty()) -// { -// return -1; -// } -// -//#ifdef LL_LINUX -// // doesn't work because gcc 2.95 doesn't correctly implement c_str(). Sigh... -// llerrs << "wstring_compare_insensitive doesn't work on Linux!" << llendl; -// return 0; -//#else -// LLWString lhs_lower = lhs; -// LLWString::toLower(lhs_lower); -// std::string lhs_lower = wstring_to_utf8str(lhs_lower); -// LLWString rhs_lower = lhs; -// LLWString::toLower(rhs_lower); -// std::string rhs_lower = wstring_to_utf8str(rhs_lower); -// -// return strcmp(lhs_lower.c_str(), rhs_lower.c_str()); -//#endif -//} - - std::string utf8str_trim(const std::string& utf8str) { LLWString wstr = utf8str_to_wstring(utf8str); - LLWString::trim(wstr); + LLWStringUtil::trim(wstr); return wstring_to_utf8str(wstr); } @@ -703,7 +495,7 @@ std::string utf8str_trim(const std::string& utf8str) std::string utf8str_tolower(const std::string& utf8str) { LLWString out_str = utf8str_to_wstring(utf8str); - LLWString::toLower(out_str); + LLWStringUtil::toLower(out_str); return wstring_to_utf8str(out_str); } @@ -712,7 +504,7 @@ S32 utf8str_compare_insensitive(const std::string& lhs, const std::string& rhs) { LLWString wlhs = utf8str_to_wstring(lhs); LLWString wrhs = utf8str_to_wstring(rhs); - return LLWString::compareInsensitive(wlhs.c_str(), wrhs.c_str()); + return LLWStringUtil::compareInsensitive(wlhs, wrhs); } std::string utf8str_truncate(const std::string& utf8str, const S32 max_len) @@ -756,7 +548,7 @@ std::string utf8str_substChar( const llwchar replace_char) { LLWString wstr = utf8str_to_wstring(utf8str); - LLWString::replaceChar(wstr, target_char, replace_char); + LLWStringUtil::replaceChar(wstr, target_char, replace_char); //wstr = wstring_substChar(wstr, target_char, replace_char); return wstring_to_utf8str(wstr); } @@ -764,7 +556,7 @@ std::string utf8str_substChar( std::string utf8str_makeASCII(const std::string& utf8str) { LLWString wstr = utf8str_to_wstring(utf8str); - LLWString::_makeASCII(wstr); + LLWStringUtil::_makeASCII(wstr); return wstring_to_utf8str(wstr); } @@ -964,19 +756,19 @@ namespace LLStringFn #ifdef _DEBUG template<class T> -void LLStringBase<T>::testHarness() +void LLStringUtilBase<T>::testHarness() { - LLString s1; + std::string s1; llassert( s1.c_str() == NULL ); llassert( s1.size() == 0 ); llassert( s1.empty() ); - LLString s2( "hello"); + std::string s2( "hello"); llassert( !strcmp( s2.c_str(), "hello" ) ); llassert( s2.size() == 5 ); llassert( !s2.empty() ); - LLString s3( s2 ); + std::string s3( s2 ); llassert( "hello" == s2 ); llassert( s2 == "hello" ); @@ -985,12 +777,12 @@ void LLStringBase<T>::testHarness() llassert( "gello" != s2 ); llassert( s2 != "gello" ); - LLString s4 = s2; + std::string s4 = s2; llassert( !s4.empty() ); s4.empty(); llassert( s4.empty() ); - LLString s5(""); + std::string s5(""); llassert( s5.empty() ); llassert( isValidIndex(s5, 0) ); @@ -1004,8 +796,8 @@ void LLStringBase<T>::testHarness() llassert( s4 == "hello again!hello again!" ); - LLString s6 = s2 + " " + s2; - LLString s7 = s6; + std::string s6 = s2 + " " + s2; + std::string s7 = s6; llassert( s6 == s7 ); llassert( !( s6 != s7) ); llassert( !(s6 < s7) ); @@ -1028,10 +820,10 @@ void LLStringBase<T>::testHarness() s2.insert( 1, "awn, don't yel"); llassert( s2 == "yawn, don't yell"); - LLString s8 = s2.substr( 6, 5 ); + std::string s8 = s2.substr( 6, 5 ); llassert( s8 == "don't" ); - LLString s9 = " \t\ntest \t\t\n "; + std::string s9 = " \t\ntest \t\t\n "; trim(s9); llassert( s9 == "test" ); @@ -1046,17 +838,17 @@ void LLStringBase<T>::testHarness() llassert( s9 == "abc123&*(abc" ); - LLString s10( 10, 'x' ); + std::string s10( 10, 'x' ); llassert( s10 == "xxxxxxxxxx" ); - LLString s11( "monkey in the middle", 7, 2 ); + std::string s11( "monkey in the middle", 7, 2 ); llassert( s11 == "in" ); - LLString s12; //empty + std::string s12; //empty s12 += "foo"; llassert( s12 == "foo" ); - LLString s13; //empty + std::string s13; //empty s13 += 'f'; llassert( s13 == "f" ); } diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h index 18cfe4b64c..50681b7967 100644 --- a/indra/llcommon/llstring.h +++ b/indra/llcommon/llstring.h @@ -1,6 +1,6 @@ /** * @file llstring.h - * @brief String utility functions and LLString class. + * @brief String utility functions and std::string class. * * $LicenseInfo:firstyear=2001&license=viewergpl$ * @@ -155,50 +155,19 @@ public: static BOOL isDigit(llwchar a) { return iswdigit(a) != 0; } }; -//RN: I used a templated base class instead of a pure interface class to minimize code duplication -// but it might be worthwhile to just go with two implementations (LLString and LLWString) of -// an interface class, unless we can think of a good reason to have a std::basic_string polymorphic base - -// **************************************************************** -// NOTA BENE: do *NOT* dynamically allocate memory inside of LLStringBase as the {*()^#%*)#%W^*)#%*)STL implentation -// of basic_string doesn't provide a virtual destructor. If we need to allocate resources specific to LLString -// then we should either customize std::basic_string to linden::basic_string or change LLString to be a wrapper -// that contains an instance of std::basic_string. Similarly, overriding methods defined in std::basic_string will *not* -// be called in a polymorphic manner (passing an instance of basic_string to a particular function) -// **************************************************************** - template <class T> -class LLStringBase : public std::basic_string<T> +class LLStringUtilBase { public: typedef typename std::basic_string<T>::size_type size_type; - // naming convention follows those set for LLUUID -// static LLStringBase null; // deprecated for std::string compliance -// static LLStringBase zero_length; // deprecated for std::string compliance - - - // standard constructors - LLStringBase() : std::basic_string<T>() {} - LLStringBase(const LLStringBase& s): std::basic_string<T>(s) {} - LLStringBase(const std::basic_string<T>& s) : std::basic_string<T>(s) {} - LLStringBase(const std::basic_string<T>& s, size_type pos, size_type n = std::basic_string<T>::npos) - : std::basic_string<T>(s, pos, n) {} - LLStringBase(size_type count, const T& c) : std::basic_string<T>() { assign(count, c);} - // custom constructors - LLStringBase(const T* s); - LLStringBase(const T* s, size_type n); - LLStringBase(const T* s, size_type pos, size_type n ); - - bool operator==(const T* _Right) const { return _Right ? (std::basic_string<T>::compare(_Right) == 0) : this->empty(); } - public: ///////////////////////////////////////////////////////////////////////////////////////// // Static Utility functions that operate on std::strings - static LLStringBase null; + static std::basic_string<T> null; - typedef std::map<std::string, std::string> format_map_t; + typedef std::map<std::basic_string<T>, std::basic_string<T> > format_map_t; static S32 format(std::basic_string<T>& s, const format_map_t& fmt_map); static BOOL isValidIndex(const std::basic_string<T>& string, size_type i) @@ -230,8 +199,8 @@ public: /** * @brief Unsafe way to make ascii characters. You should probably * only call this when interacting with the host operating system. - * The 1 byte LLString does not work correctly. - * The 2 and 4 byte LLString probably work, so LLWString::_makeASCII + * The 1 byte std::string does not work correctly. + * The 2 and 4 byte std::string probably work, so LLWStringUtil::_makeASCII * should work. */ static void _makeASCII(std::basic_string<T>& string); @@ -253,11 +222,13 @@ public: // Like strcmp but also handles empty strings. Uses // current locale. static S32 compareStrings(const T* lhs, const T* rhs); + static S32 compareStrings(const std::basic_string<T>& lhs, const std::basic_string<T>& rhs); // case insensitive version of above. Uses current locale on // Win32, and falls back to a non-locale aware comparison on // Linux. static S32 compareInsensitive(const T* lhs, const T* rhs); + static S32 compareInsensitive(const std::basic_string<T>& lhs, const std::basic_string<T>& rhs); // Case sensitive comparison with good handling of numbers. Does not use current locale. // a.k.a. strdictcmp() @@ -284,21 +255,21 @@ public: }; -template<class T> LLStringBase<T> LLStringBase<T>::null; +template<class T> std::basic_string<T> LLStringUtilBase<T>::null; -typedef LLStringBase<char> LLString; -typedef LLStringBase<llwchar> LLWString; +typedef LLStringUtilBase<char> LLStringUtil; +typedef LLStringUtilBase<llwchar> LLWStringUtil; +typedef std::basic_string<llwchar> LLWString; //@ Use this where we want to disallow input in the form of "foo" // This is used to catch places where english text is embedded in the code // instead of in a translatable XUI file. -class LLStringExplicit : public LLString +class LLStringExplicit : public std::string { public: - explicit LLStringExplicit(const char* s) : LLString(s) {} - LLStringExplicit(const LLString& s) : LLString(s) {} - LLStringExplicit(const std::string& s) : LLString(s) {} - LLStringExplicit(const std::string& s, size_type pos, size_type n = std::string::npos) : LLString(s, pos, n) {} + explicit LLStringExplicit(const char* s) : std::string(s) {} + LLStringExplicit(const std::string& s) : std::string(s) {} + LLStringExplicit(const std::string& s, size_type pos, size_type n = std::string::npos) : std::string(s, pos, n) {} }; struct LLDictionaryLess @@ -306,7 +277,7 @@ struct LLDictionaryLess public: bool operator()(const std::string& a, const std::string& b) { - return (LLString::precedesDict(a, b) ? true : false); + return (LLStringUtil::precedesDict(a, b) ? true : false); } }; @@ -335,6 +306,7 @@ inline std::string chop_tail_copy( * pointer is NULL. */ std::string ll_safe_string(const char* in); +std::string ll_safe_string(const char* in, S32 maxlen); /** * @brief This translates a nybble stored as a hex value from 0-f back @@ -351,7 +323,7 @@ U8 hex_as_nybble(char hex); * @param filename The full name of the file to read. * @return Returns true on success. If false, str is unmodified. */ -bool _read_file_into_string(std::string& str, const char* filename); +bool _read_file_into_string(std::string& str, const std::string& filename); /** * Unicode support @@ -373,20 +345,17 @@ LLWString utf16str_to_wstring(const llutf16string &utf16str); llutf16string wstring_to_utf16str(const LLWString &utf32str, S32 len); llutf16string wstring_to_utf16str(const LLWString &utf32str); -llutf16string utf8str_to_utf16str ( const LLString& utf8str, S32 len); -llutf16string utf8str_to_utf16str ( const LLString& utf8str ); +llutf16string utf8str_to_utf16str ( const std::string& utf8str, S32 len); +llutf16string utf8str_to_utf16str ( const std::string& utf8str ); LLWString utf8str_to_wstring(const std::string &utf8str, S32 len); LLWString utf8str_to_wstring(const std::string &utf8str); // Same function, better name. JC inline LLWString utf8string_to_wstring(const std::string& utf8_string) { return utf8str_to_wstring(utf8_string); } -// Special hack for llfilepicker.cpp: -S32 utf16chars_to_utf8chars(const U16* inchars, char* outchars, S32* nchars8 = 0); -S32 utf16chars_to_wchar(const U16* inchars, llwchar* outchar); +// S32 wchar_to_utf8chars(llwchar inchar, char* outchars); -// std::string wstring_to_utf8str(const LLWString &utf32str, S32 len); std::string wstring_to_utf8str(const LLWString &utf32str); @@ -448,15 +417,6 @@ std::string mbcsstring_makeASCII(const std::string& str); std::string utf8str_removeCRLF(const std::string& utf8str); -template <class T> -std::ostream& operator<<(std::ostream &s, const LLStringBase<T> &str) -{ - s << ((std::basic_string<T>)str); - return s; -} - -std::ostream& operator<<(std::ostream &s, const LLWString &wstr); - #if LL_WINDOWS /* @name Windows string helpers */ @@ -492,7 +452,7 @@ std::string ll_convert_wide_to_string(const wchar_t* in); #endif // LL_WINDOWS /** - * Many of the 'strip' and 'replace' methods of LLStringBase need + * Many of the 'strip' and 'replace' methods of LLStringUtilBase need * specialization to work with the signed char type. * Sadly, it is not possible (AFAIK) to specialize a single method of * a template class. @@ -558,11 +518,12 @@ namespace LLStringFn // static template<class T> -S32 LLStringBase<T>::format(std::basic_string<T>& s, const format_map_t& fmt_map) +S32 LLStringUtilBase<T>::format(std::basic_string<T>& s, const format_map_t& fmt_map) { typedef typename std::basic_string<T>::size_type string_size_type_t; + typedef typename format_map_t::const_iterator format_map_const_iterator_t; S32 res = 0; - for (format_map_t::const_iterator iter = fmt_map.begin(); iter != fmt_map.end(); ++iter) + for (format_map_const_iterator_t iter = fmt_map.begin(); iter != fmt_map.end(); ++iter) { U32 fmtlen = iter->first.size(); string_size_type_t n = 0; @@ -584,7 +545,7 @@ S32 LLStringBase<T>::format(std::basic_string<T>& s, const format_map_t& fmt_map // static template<class T> -S32 LLStringBase<T>::compareStrings(const T* lhs, const T* rhs) +S32 LLStringUtilBase<T>::compareStrings(const T* lhs, const T* rhs) { S32 result; if( lhs == rhs ) @@ -608,9 +569,16 @@ S32 LLStringBase<T>::compareStrings(const T* lhs, const T* rhs) return result; } +//static +template<class T> +S32 LLStringUtilBase<T>::compareStrings(const std::basic_string<T>& lhs, const std::basic_string<T>& rhs) +{ + return LLStringOps::collate(lhs.c_str(), rhs.c_str()); +} + // static template<class T> -S32 LLStringBase<T>::compareInsensitive(const T* lhs, const T* rhs ) +S32 LLStringUtilBase<T>::compareInsensitive(const T* lhs, const T* rhs ) { S32 result; if( lhs == rhs ) @@ -629,22 +597,32 @@ S32 LLStringBase<T>::compareInsensitive(const T* lhs, const T* rhs ) } else { - LLStringBase<T> lhs_string(lhs); - LLStringBase<T> rhs_string(rhs); - LLStringBase<T>::toUpper(lhs_string); - LLStringBase<T>::toUpper(rhs_string); + std::basic_string<T> lhs_string(lhs); + std::basic_string<T> rhs_string(rhs); + LLStringUtilBase<T>::toUpper(lhs_string); + LLStringUtilBase<T>::toUpper(rhs_string); result = LLStringOps::collate(lhs_string.c_str(), rhs_string.c_str()); } return result; } +//static +template<class T> +S32 LLStringUtilBase<T>::compareInsensitive(const std::basic_string<T>& lhs, const std::basic_string<T>& rhs) +{ + std::basic_string<T> lhs_string(lhs); + std::basic_string<T> rhs_string(rhs); + LLStringUtilBase<T>::toUpper(lhs_string); + LLStringUtilBase<T>::toUpper(rhs_string); + return LLStringOps::collate(lhs_string.c_str(), rhs_string.c_str()); +} // Case sensitive comparison with good handling of numbers. Does not use current locale. // a.k.a. strdictcmp() //static template<class T> -S32 LLStringBase<T>::compareDict(const std::basic_string<T>& astr, const std::basic_string<T>& bstr) +S32 LLStringUtilBase<T>::compareDict(const std::basic_string<T>& astr, const std::basic_string<T>& bstr) { const T* a = astr.c_str(); const T* b = bstr.c_str(); @@ -683,8 +661,9 @@ S32 LLStringBase<T>::compareDict(const std::basic_string<T>& astr, const std::ba return ca-cb; } +// static template<class T> -S32 LLStringBase<T>::compareDictInsensitive(const std::basic_string<T>& astr, const std::basic_string<T>& bstr) +S32 LLStringUtilBase<T>::compareDictInsensitive(const std::basic_string<T>& astr, const std::basic_string<T>& bstr) { const T* a = astr.c_str(); const T* b = bstr.c_str(); @@ -719,11 +698,11 @@ S32 LLStringBase<T>::compareDictInsensitive(const std::basic_string<T>& astr, co // Puts compareDict() in a form appropriate for LL container classes to use for sorting. // static template<class T> -BOOL LLStringBase<T>::precedesDict( const std::basic_string<T>& a, const std::basic_string<T>& b ) +BOOL LLStringUtilBase<T>::precedesDict( const std::basic_string<T>& a, const std::basic_string<T>& b ) { if( a.size() && b.size() ) { - return (LLStringBase<T>::compareDict(a.c_str(), b.c_str()) < 0); + return (LLStringUtilBase<T>::compareDict(a.c_str(), b.c_str()) < 0); } else { @@ -731,28 +710,9 @@ BOOL LLStringBase<T>::precedesDict( const std::basic_string<T>& a, const std::ba } } -// Constructors -template<class T> -LLStringBase<T>::LLStringBase(const T* s ) : std::basic_string<T>() -{ - if (s) assign(s); -} - -template<class T> -LLStringBase<T>::LLStringBase(const T* s, size_type n ) : std::basic_string<T>() -{ - if (s) assign(s, n); -} - -// Init from a substring -template<class T> -LLStringBase<T>::LLStringBase(const T* s, size_type pos, size_type n ) -: std::basic_string<T>( (s ? s : std::basic_string<T>() ), pos, n ) -{ } - //static template<class T> -void LLStringBase<T>::toUpper(std::basic_string<T>& string) +void LLStringUtilBase<T>::toUpper(std::basic_string<T>& string) { if( !string.empty() ) { @@ -766,7 +726,7 @@ void LLStringBase<T>::toUpper(std::basic_string<T>& string) //static template<class T> -void LLStringBase<T>::toLower(std::basic_string<T>& string) +void LLStringUtilBase<T>::toLower(std::basic_string<T>& string) { if( !string.empty() ) { @@ -780,7 +740,7 @@ void LLStringBase<T>::toLower(std::basic_string<T>& string) //static template<class T> -void LLStringBase<T>::trimHead(std::basic_string<T>& string) +void LLStringUtilBase<T>::trimHead(std::basic_string<T>& string) { if( !string.empty() ) { @@ -795,7 +755,7 @@ void LLStringBase<T>::trimHead(std::basic_string<T>& string) //static template<class T> -void LLStringBase<T>::trimTail(std::basic_string<T>& string) +void LLStringUtilBase<T>::trimTail(std::basic_string<T>& string) { if( string.size() ) { @@ -814,7 +774,7 @@ void LLStringBase<T>::trimTail(std::basic_string<T>& string) // Replace line feeds with carriage return-line feed pairs. //static template<class T> -void LLStringBase<T>::addCRLF(std::basic_string<T>& string) +void LLStringUtilBase<T>::addCRLF(std::basic_string<T>& string) { const T LF = 10; const T CR = 13; @@ -855,7 +815,7 @@ void LLStringBase<T>::addCRLF(std::basic_string<T>& string) // Remove all carriage returns //static template<class T> -void LLStringBase<T>::removeCRLF(std::basic_string<T>& string) +void LLStringUtilBase<T>::removeCRLF(std::basic_string<T>& string) { const T CR = 13; @@ -876,7 +836,7 @@ void LLStringBase<T>::removeCRLF(std::basic_string<T>& string) //static template<class T> -void LLStringBase<T>::replaceChar( std::basic_string<T>& string, T target, T replacement ) +void LLStringUtilBase<T>::replaceChar( std::basic_string<T>& string, T target, T replacement ) { size_type found_pos = 0; for (found_pos = string.find(target, found_pos); @@ -889,7 +849,7 @@ void LLStringBase<T>::replaceChar( std::basic_string<T>& string, T target, T rep //static template<class T> -void LLStringBase<T>::replaceNonstandardASCII( std::basic_string<T>& string, T replacement ) +void LLStringUtilBase<T>::replaceNonstandardASCII( std::basic_string<T>& string, T replacement ) { const char LF = 10; const S8 MIN = 32; @@ -909,12 +869,12 @@ void LLStringBase<T>::replaceNonstandardASCII( std::basic_string<T>& string, T r //static template<class T> -void LLStringBase<T>::replaceTabsWithSpaces( std::basic_string<T>& str, size_type spaces_per_tab ) +void LLStringUtilBase<T>::replaceTabsWithSpaces( std::basic_string<T>& str, size_type spaces_per_tab ) { const T TAB = '\t'; const T SPACE = ' '; - LLStringBase<T> out_str; + std::basic_string<T> out_str; // Replace tabs with spaces for (size_type i = 0; i < str.length(); i++) { @@ -933,7 +893,7 @@ void LLStringBase<T>::replaceTabsWithSpaces( std::basic_string<T>& str, size_typ //static template<class T> -BOOL LLStringBase<T>::containsNonprintable(const std::basic_string<T>& string) +BOOL LLStringUtilBase<T>::containsNonprintable(const std::basic_string<T>& string) { const char MIN = 32; BOOL rv = FALSE; @@ -950,7 +910,7 @@ BOOL LLStringBase<T>::containsNonprintable(const std::basic_string<T>& string) //static template<class T> -void LLStringBase<T>::stripNonprintable(std::basic_string<T>& string) +void LLStringUtilBase<T>::stripNonprintable(std::basic_string<T>& string) { const char MIN = 32; size_type j = 0; @@ -981,7 +941,7 @@ void LLStringBase<T>::stripNonprintable(std::basic_string<T>& string) } template<class T> -void LLStringBase<T>::_makeASCII(std::basic_string<T>& string) +void LLStringUtilBase<T>::_makeASCII(std::basic_string<T>& string) { // Replace non-ASCII chars with LL_UNKNOWN_CHAR for (size_type i = 0; i < string.length(); i++) @@ -995,7 +955,7 @@ void LLStringBase<T>::_makeASCII(std::basic_string<T>& string) // static template<class T> -void LLStringBase<T>::copy( T* dst, const T* src, size_type dst_size ) +void LLStringUtilBase<T>::copy( T* dst, const T* src, size_type dst_size ) { if( dst_size > 0 ) { @@ -1011,7 +971,7 @@ void LLStringBase<T>::copy( T* dst, const T* src, size_type dst_size ) // static template<class T> -void LLStringBase<T>::copyInto(std::basic_string<T>& dst, const std::basic_string<T>& src, size_type offset) +void LLStringUtilBase<T>::copyInto(std::basic_string<T>& dst, const std::basic_string<T>& src, size_type offset) { if ( offset == dst.length() ) { @@ -1032,7 +992,7 @@ void LLStringBase<T>::copyInto(std::basic_string<T>& dst, const std::basic_strin // True if this is the head of s. //static template<class T> -BOOL LLStringBase<T>::isHead( const std::basic_string<T>& string, const T* s ) +BOOL LLStringUtilBase<T>::isHead( const std::basic_string<T>& string, const T* s ) { if( string.empty() ) { @@ -1046,14 +1006,14 @@ BOOL LLStringBase<T>::isHead( const std::basic_string<T>& string, const T* s ) } template<class T> -BOOL LLStringBase<T>::convertToBOOL(const std::basic_string<T>& string, BOOL& value) +BOOL LLStringUtilBase<T>::convertToBOOL(const std::basic_string<T>& string, BOOL& value) { if( string.empty() ) { return FALSE; } - LLStringBase<T> temp( string ); + std::basic_string<T> temp( string ); trim(temp); if( (temp == "1") || @@ -1083,7 +1043,7 @@ BOOL LLStringBase<T>::convertToBOOL(const std::basic_string<T>& string, BOOL& va } template<class T> -BOOL LLStringBase<T>::convertToU8(const std::basic_string<T>& string, U8& value) +BOOL LLStringUtilBase<T>::convertToU8(const std::basic_string<T>& string, U8& value) { S32 value32 = 0; BOOL success = convertToS32(string, value32); @@ -1096,7 +1056,7 @@ BOOL LLStringBase<T>::convertToU8(const std::basic_string<T>& string, U8& value) } template<class T> -BOOL LLStringBase<T>::convertToS8(const std::basic_string<T>& string, S8& value) +BOOL LLStringUtilBase<T>::convertToS8(const std::basic_string<T>& string, S8& value) { S32 value32 = 0; BOOL success = convertToS32(string, value32); @@ -1109,7 +1069,7 @@ BOOL LLStringBase<T>::convertToS8(const std::basic_string<T>& string, S8& value) } template<class T> -BOOL LLStringBase<T>::convertToS16(const std::basic_string<T>& string, S16& value) +BOOL LLStringUtilBase<T>::convertToS16(const std::basic_string<T>& string, S16& value) { S32 value32 = 0; BOOL success = convertToS32(string, value32); @@ -1122,7 +1082,7 @@ BOOL LLStringBase<T>::convertToS16(const std::basic_string<T>& string, S16& valu } template<class T> -BOOL LLStringBase<T>::convertToU16(const std::basic_string<T>& string, U16& value) +BOOL LLStringUtilBase<T>::convertToU16(const std::basic_string<T>& string, U16& value) { S32 value32 = 0; BOOL success = convertToS32(string, value32); @@ -1135,14 +1095,14 @@ BOOL LLStringBase<T>::convertToU16(const std::basic_string<T>& string, U16& valu } template<class T> -BOOL LLStringBase<T>::convertToU32(const std::basic_string<T>& string, U32& value) +BOOL LLStringUtilBase<T>::convertToU32(const std::basic_string<T>& string, U32& value) { if( string.empty() ) { return FALSE; } - LLStringBase<T> temp( string ); + std::basic_string<T> temp( string ); trim(temp); U32 v; std::basic_istringstream<T> i_stream((std::basic_string<T>)temp); @@ -1162,14 +1122,14 @@ BOOL LLStringBase<T>::convertToU32(const std::basic_string<T>& string, U32& valu } template<class T> -BOOL LLStringBase<T>::convertToS32(const std::basic_string<T>& string, S32& value) +BOOL LLStringUtilBase<T>::convertToS32(const std::basic_string<T>& string, S32& value) { if( string.empty() ) { return FALSE; } - LLStringBase<T> temp( string ); + std::basic_string<T> temp( string ); trim(temp); S32 v; std::basic_istringstream<T> i_stream((std::basic_string<T>)temp); @@ -1189,7 +1149,7 @@ BOOL LLStringBase<T>::convertToS32(const std::basic_string<T>& string, S32& valu } template<class T> -BOOL LLStringBase<T>::convertToF32(const std::basic_string<T>& string, F32& value) +BOOL LLStringUtilBase<T>::convertToF32(const std::basic_string<T>& string, F32& value) { F64 value64 = 0.0; BOOL success = convertToF64(string, value64); @@ -1202,14 +1162,14 @@ BOOL LLStringBase<T>::convertToF32(const std::basic_string<T>& string, F32& valu } template<class T> -BOOL LLStringBase<T>::convertToF64(const std::basic_string<T>& string, F64& value) +BOOL LLStringUtilBase<T>::convertToF64(const std::basic_string<T>& string, F64& value) { if( string.empty() ) { return FALSE; } - LLStringBase<T> temp( string ); + std::basic_string<T> temp( string ); trim(temp); F64 v; std::basic_istringstream<T> i_stream((std::basic_string<T>)temp); @@ -1229,7 +1189,7 @@ BOOL LLStringBase<T>::convertToF64(const std::basic_string<T>& string, F64& valu } template<class T> -void LLStringBase<T>::truncate(std::basic_string<T>& string, size_type count) +void LLStringUtilBase<T>::truncate(std::basic_string<T>& string, size_type count) { size_type cur_size = string.size(); string.resize(count < cur_size ? count : cur_size); diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp index 8700d9681e..d78a8591cb 100644 --- a/indra/llcommon/llsys.cpp +++ b/indra/llcommon/llsys.cpp @@ -143,28 +143,22 @@ LLOSInfo::LLOSInfo() : std::string csdversion = utf16str_to_utf8str(osvi.szCSDVersion); // Display version, service pack (if any), and build number. - char tmp[MAX_STRING]; /* Flawfinder: ignore */ + std::string tmpstr; if(osvi.dwMajorVersion <= 4) { - snprintf( /* Flawfinder: ignore */ - tmp, - sizeof(tmp), - "version %d.%d %s (Build %d)", - osvi.dwMajorVersion, - osvi.dwMinorVersion, - csdversion.c_str(), - (osvi.dwBuildNumber & 0xffff)); + tmpstr = llformat("version %d.%d %s (Build %d)", + osvi.dwMajorVersion, + osvi.dwMinorVersion, + csdversion.c_str(), + (osvi.dwBuildNumber & 0xffff)); } else { - snprintf( /* Flawfinder: ignore */ - tmp, - sizeof(tmp), - "%s (Build %d)", - csdversion.c_str(), - (osvi.dwBuildNumber & 0xffff)); + tmpstr = llformat("%s (Build %d)", + csdversion.c_str(), + (osvi.dwBuildNumber & 0xffff)); } - mOSString = mOSStringSimple + tmp; + mOSString = mOSStringSimple + tmpstr; } break; @@ -397,7 +391,7 @@ LLCPUInfo::LLCPUInfo() mCPUString = out.str(); #elif LL_LINUX - std::map< LLString, LLString > cpuinfo; + std::map< std::string, std::string > cpuinfo; LLFILE* cpuinfo_fp = LLFile::fopen(CPUINFO_FILE, "rb"); if(cpuinfo_fp) { @@ -420,21 +414,21 @@ LLCPUInfo::LLCPUInfo() if (nlspot == NULL) nlspot = line + strlen( line ); // Fallback to terminating NUL std::string linename( line, tabspot ); - LLString llinename(linename); - LLString::toLower(llinename); + std::string llinename(linename); + LLStringUtil::toLower(llinename); std::string lineval( spacespot + 1, nlspot ); cpuinfo[ llinename ] = lineval; } fclose(cpuinfo_fp); } # if LL_X86 - LLString flags = " " + cpuinfo["flags"] + " "; - LLString::toLower(flags); + std::string flags = " " + cpuinfo["flags"] + " "; + LLStringUtil::toLower(flags); mHasSSE = ( flags.find( " sse " ) != std::string::npos ); mHasSSE2 = ( flags.find( " sse2 " ) != std::string::npos ); F64 mhz; - if (LLString::convertToF64(cpuinfo["cpu mhz"], mhz) + if (LLStringUtil::convertToF64(cpuinfo["cpu mhz"], mhz) && 200.0 < mhz && mhz < 10000.0) { mCPUMhz = (S32)llrint(mhz); @@ -658,18 +652,17 @@ std::ostream& operator<<(std::ostream& s, const LLMemoryInfo& info) return s; } -BOOL gunzip_file(const char *srcfile, const char *dstfile) +BOOL gunzip_file(const std::string& srcfile, const std::string& dstfile) { - char tmpfile[LL_MAX_PATH]; /* Flawfinder: ignore */ + std::string tmpfile; const S32 UNCOMPRESS_BUFFER_SIZE = 32768; BOOL retval = FALSE; gzFile src = NULL; U8 buffer[UNCOMPRESS_BUFFER_SIZE]; LLFILE *dst = NULL; S32 bytes = 0; - (void *) strcpy(tmpfile, dstfile); /* Flawfinder: ignore */ - (void *) strncat(tmpfile, ".t", sizeof(tmpfile) - strlen(tmpfile) -1); /* Flawfinder: ignore */ - src = gzopen(srcfile, "rb"); + tmpfile = dstfile + ".t"; + src = gzopen(srcfile.c_str(), "rb"); if (! src) goto err; dst = LLFile::fopen(tmpfile, "wb"); /* Flawfinder: ignore */ if (! dst) goto err; @@ -693,18 +686,17 @@ err: return retval; } -BOOL gzip_file(const char *srcfile, const char *dstfile) +BOOL gzip_file(const std::string& srcfile, const std::string& dstfile) { const S32 COMPRESS_BUFFER_SIZE = 32768; - char tmpfile[LL_MAX_PATH]; /* Flawfinder: ignore */ + std::string tmpfile; BOOL retval = FALSE; U8 buffer[COMPRESS_BUFFER_SIZE]; gzFile dst = NULL; LLFILE *src = NULL; S32 bytes = 0; - (void *) strcpy(tmpfile, dstfile); /* Flawfinder: ignore */ - (void *) strncat(tmpfile, ".t", sizeof(tmpfile) - strlen(tmpfile) -1); /* Flawfinder: ignore */ - dst = gzopen(tmpfile, "wb"); /* Flawfinder: ignore */ + tmpfile = dstfile + ".t"; + dst = gzopen(tmpfile.c_str(), "wb"); /* Flawfinder: ignore */ if (! dst) goto err; src = LLFile::fopen(srcfile, "rb"); /* Flawfinder: ignore */ if (! src) goto err; diff --git a/indra/llcommon/llsys.h b/indra/llcommon/llsys.h index 332d62c186..a56ba2bdda 100644 --- a/indra/llcommon/llsys.h +++ b/indra/llcommon/llsys.h @@ -127,9 +127,9 @@ std::ostream& operator<<(std::ostream& s, const LLCPUInfo& info); std::ostream& operator<<(std::ostream& s, const LLMemoryInfo& info); // gunzip srcfile into dstfile. Returns FALSE on error. -BOOL gunzip_file(const char *srcfile, const char *dstfile); +BOOL gunzip_file(const std::string& srcfile, const std::string& dstfile); // gzip srcfile into dstfile. Returns FALSE on error. -BOOL gzip_file(const char *srcfile, const char *dstfile); +BOOL gzip_file(const std::string& srcfile, const std::string& dstfile); extern LLCPUInfo gSysCPU; diff --git a/indra/llcommon/lltimer.cpp b/indra/llcommon/lltimer.cpp index 3d05699cd6..77d683adc0 100644 --- a/indra/llcommon/lltimer.cpp +++ b/indra/llcommon/lltimer.cpp @@ -483,7 +483,7 @@ struct tm* utc_to_pacific_time(time_t utc_time, BOOL pacific_daylight_time) } -void microsecondsToTimecodeString(U64 current_time, char *tcstring) +void microsecondsToTimecodeString(U64 current_time, std::string& tcstring) { U64 hours; U64 minutes; @@ -501,11 +501,11 @@ void microsecondsToTimecodeString(U64 current_time, char *tcstring) subframes = current_time / (U64)42; subframes %= 100; - sprintf(tcstring,"%3.3d:%2.2d:%2.2d:%2.2d.%2.2d",(int)hours,(int)minutes,(int)seconds,(int)frames,(int)subframes); /* Flawfinder: ignore */ + tcstring = llformat("%3.3d:%2.2d:%2.2d:%2.2d.%2.2d",(int)hours,(int)minutes,(int)seconds,(int)frames,(int)subframes); } -void secondsToTimecodeString(F32 current_time, char *tcstring) +void secondsToTimecodeString(F32 current_time, std::string& tcstring) { microsecondsToTimecodeString((U64)((F64)(SEC_TO_MICROSEC*current_time)), tcstring); } diff --git a/indra/llcommon/lltimer.h b/indra/llcommon/lltimer.h index 41562f4a51..d3a83339f0 100644 --- a/indra/llcommon/lltimer.h +++ b/indra/llcommon/lltimer.h @@ -162,8 +162,8 @@ BOOL is_daylight_savings(); // struct tm* internal_time = utc_to_pacific_time(utc_time, gDaylight); struct tm* utc_to_pacific_time(time_t utc_time, BOOL pacific_daylight_time); -void microsecondsToTimecodeString(U64 current_time, char *tcstring); -void secondsToTimecodeString(F32 current_time, char *tcstring); +void microsecondsToTimecodeString(U64 current_time, std::string& tcstring); +void secondsToTimecodeString(F32 current_time, std::string& tcstring); // class for scheduling a function to be called at a given frequency (approximate, inprecise) class LLEventTimer diff --git a/indra/llcommon/lluuid.cpp b/indra/llcommon/lluuid.cpp index 3f86681315..51e27e0708 100644 --- a/indra/llcommon/lluuid.cpp +++ b/indra/llcommon/lluuid.cpp @@ -149,9 +149,9 @@ U32 janky_fast_random_seeded_bytes(U32 seed, U32 val) #endif // Common to all UUID implementations -void LLUUID::toString(char *out) const +void LLUUID::toString(std::string& out) const { - sprintf(out, + out = llformat( "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", (U8)(mData[0]), (U8)(mData[1]), @@ -171,6 +171,23 @@ void LLUUID::toString(char *out) const (U8)(mData[15])); } +// *TODO: deprecate +void LLUUID::toString(char *out) const +{ + std::string buffer; + toString(buffer); + strcpy(out,buffer.c_str()); /* Flawfinder: ignore */ +} + +void LLUUID::toCompressedString(std::string& out) const +{ + char bytes[UUID_BYTES+1]; + memcpy(bytes, mData, UUID_BYTES); /* Flawfinder: ignore */ + bytes[UUID_BYTES] = '\0'; + out = bytes; +} + +// *TODO: deprecate void LLUUID::toCompressedString(char *out) const { memcpy(out, mData, UUID_BYTES); /* Flawfinder: ignore */ @@ -184,38 +201,32 @@ std::string LLUUID::getString() const std::string LLUUID::asString() const { - char str[UUID_STR_SIZE]; /* Flawfinder: ignore */ + std::string str; toString(str); - return std::string(str); + return str; } -BOOL LLUUID::set(const std::string& in_string, BOOL emit) +BOOL LLUUID::set(const char* in_string, BOOL emit) { - return set(in_string.c_str(), emit); + return set(ll_safe_string(in_string)); } -BOOL LLUUID::set(const char *in_string, BOOL emit) +BOOL LLUUID::set(const std::string& in_string, BOOL emit) { BOOL broken_format = FALSE; - if (!in_string) - { - llerrs << "No string pointer in LLUUID::set!" << llendl; - setNull(); - return FALSE; - } // empty strings should make NULL uuid - if (!in_string[0]) + if (in_string.empty()) { setNull(); return TRUE; } - if (strlen(in_string) != (UUID_STR_LENGTH - 1)) /* Flawfinder: ignore */ + if (in_string.length() != (UUID_STR_LENGTH - 1)) /* Flawfinder: ignore */ { // I'm a moron. First implementation didn't have the right UUID format. // Shouldn't see any of these any more - if (strlen(in_string) == (UUID_STR_LENGTH - 2)) /* Flawfinder: ignore */ + if (in_string.length() == (UUID_STR_LENGTH - 2)) /* Flawfinder: ignore */ { if(emit) { @@ -251,17 +262,17 @@ BOOL LLUUID::set(const char *in_string, BOOL emit) mData[i] = 0; - if ((*(in_string + cur_pos) >= '0') && (*(in_string+cur_pos) <= '9')) + if ((in_string[cur_pos] >= '0') && (in_string[cur_pos] <= '9')) { - mData[i] += (U8)(*(in_string + cur_pos) - '0'); + mData[i] += (U8)(in_string[cur_pos] - '0'); } - else if ((*(in_string + cur_pos) >= 'a') && (*(in_string+cur_pos) <='f')) + else if ((in_string[cur_pos] >= 'a') && (in_string[cur_pos] <='f')) { - mData[i] += (U8)(10 + *(in_string + cur_pos) - 'a'); + mData[i] += (U8)(10 + in_string[cur_pos] - 'a'); } - else if ((*(in_string + cur_pos) >= 'A') && (*(in_string+cur_pos) <='F')) + else if ((in_string[cur_pos] >= 'A') && (in_string[cur_pos] <='F')) { - mData[i] += (U8)(10 + *(in_string + cur_pos) - 'A'); + mData[i] += (U8)(10 + in_string[cur_pos] - 'A'); } else { @@ -276,17 +287,17 @@ BOOL LLUUID::set(const char *in_string, BOOL emit) mData[i] = mData[i] << 4; cur_pos++; - if ((*(in_string + cur_pos) >= '0') && (*(in_string+cur_pos) <= '9')) + if ((in_string[cur_pos] >= '0') && (in_string[cur_pos] <= '9')) { - mData[i] += (U8)(*(in_string + cur_pos) - '0'); + mData[i] += (U8)(in_string[cur_pos] - '0'); } - else if ((*(in_string + cur_pos) >= 'a') && (*(in_string+cur_pos) <='f')) + else if ((in_string[cur_pos] >= 'a') && (in_string[cur_pos] <='f')) { - mData[i] += (U8)(10 + *(in_string + cur_pos) - 'a'); + mData[i] += (U8)(10 + in_string[cur_pos] - 'a'); } - else if ((*(in_string + cur_pos) >= 'A') && (*(in_string+cur_pos) <='F')) + else if ((in_string[cur_pos] >= 'A') && (in_string[cur_pos] <='F')) { - mData[i] += (U8)(10 + *(in_string + cur_pos) - 'A'); + mData[i] += (U8)(10 + in_string[cur_pos] - 'A'); } else { @@ -305,20 +316,11 @@ BOOL LLUUID::set(const char *in_string, BOOL emit) BOOL LLUUID::validate(const std::string& in_string) { - return validate(in_string.c_str()); -} - -BOOL LLUUID::validate(const char *in_string) -{ BOOL broken_format = FALSE; - if (!in_string) - { - return FALSE; - } - if (strlen(in_string) != (UUID_STR_LENGTH - 1)) /* Flawfinder: ignore */ + if (in_string.length() != (UUID_STR_LENGTH - 1)) /* Flawfinder: ignore */ { // I'm a moron. First implementation didn't have the right UUID format. - if (strlen(in_string) == (UUID_STR_LENGTH - 2)) /* Flawfinder: ignore */ + if (in_string.length() == (UUID_STR_LENGTH - 2)) /* Flawfinder: ignore */ { broken_format = TRUE; } @@ -329,8 +331,7 @@ BOOL LLUUID::validate(const char *in_string) } U8 cur_pos = 0; - U32 i; - for (i = 0; i < 16; i++) + for (U32 i = 0; i < 16; i++) { if ((i == 4) || (i == 6) || (i == 8) || (i == 10)) { @@ -342,13 +343,13 @@ BOOL LLUUID::validate(const char *in_string) } } - if ((*(in_string + cur_pos) >= '0') && (*(in_string+cur_pos) <= '9')) + if ((in_string[cur_pos] >= '0') && (in_string[cur_pos] <= '9')) { } - else if ((*(in_string + cur_pos) >= 'a') && (*(in_string+cur_pos) <='f')) + else if ((in_string[cur_pos] >= 'a') && (in_string[cur_pos] <='f')) { } - else if ((*(in_string + cur_pos) >= 'A') && (*(in_string+cur_pos) <='F')) + else if ((in_string[cur_pos] >= 'A') && (in_string[cur_pos] <='F')) { } else @@ -358,13 +359,13 @@ BOOL LLUUID::validate(const char *in_string) cur_pos++; - if ((*(in_string + cur_pos) >= '0') && (*(in_string+cur_pos) <= '9')) + if ((in_string[cur_pos] >= '0') && (in_string[cur_pos] <= '9')) { } - else if ((*(in_string + cur_pos) >= 'a') && (*(in_string+cur_pos) <='f')) + else if ((in_string[cur_pos] >= 'a') && (in_string[cur_pos] <='f')) { } - else if ((*(in_string + cur_pos) >= 'A') && (*(in_string+cur_pos) <='F')) + else if ((in_string[cur_pos] >= 'A') && (in_string[cur_pos] <='F')) { } else @@ -412,8 +413,7 @@ LLUUID LLUUID::combine(const LLUUID &other) const std::ostream& operator<<(std::ostream& s, const LLUUID &uuid) { - char uuid_str[UUID_STR_LENGTH]; - + std::string uuid_str; uuid.toString(uuid_str); s << uuid_str; return s; @@ -428,7 +428,7 @@ std::istream& operator>>(std::istream &s, LLUUID &uuid) s >> uuid_str[i]; } uuid_str[i] = '\0'; - uuid.set(uuid_str); + uuid.set(std::string(uuid_str)); return s; } @@ -891,15 +891,15 @@ U32 LLUUID::getRandomSeed() return(*(U32 *)seed); } -BOOL LLUUID::parseUUID(const char* buf, LLUUID* value) +BOOL LLUUID::parseUUID(const std::string& buf, LLUUID* value) { - if( buf == NULL || buf[0] == '\0' || value == NULL) + if( buf.empty() || value == NULL) { return FALSE; } - LLString temp( buf ); - LLString::trim(temp); + std::string temp( buf ); + LLStringUtil::trim(temp); if( LLUUID::validate( temp ) ) { value->set( temp ); diff --git a/indra/llcommon/lluuid.h b/indra/llcommon/lluuid.h index 2f82ec9a93..b2fcce5161 100644 --- a/indra/llcommon/lluuid.h +++ b/indra/llcommon/lluuid.h @@ -106,7 +106,9 @@ public: friend std::istream& operator>>(std::istream& s, LLUUID &uuid); void toString(char *out) const; // Does not allocate memory, needs 36 characters (including \0) + void toString(std::string& out) const; void toCompressedString(char *out) const; // Does not allocate memory, needs 17 characters (including \0) + void toCompressedString(std::string& out) const; std::string asString() const; std::string getString() const; @@ -115,14 +117,13 @@ public: U32 getCRC32() const; static BOOL validate(const std::string& in_string); // Validate that the UUID string is legal. - static BOOL validate(const char *in_string); // Validate that the UUID string is legal. static const LLUUID null; static U32 getRandomSeed(); static S32 getNodeID(unsigned char * node_id); - static BOOL parseUUID(const char* buf, LLUUID* value); + static BOOL parseUUID(const std::string& buf, LLUUID* value); U8 mData[UUID_BYTES]; }; diff --git a/indra/llcommon/metapropertyt.h b/indra/llcommon/metapropertyt.h index 488a60c22f..158d0cebec 100644 --- a/indra/llcommon/metapropertyt.h +++ b/indra/llcommon/metapropertyt.h @@ -86,13 +86,6 @@ inline const LLReflective* LLMetaPropertyT<std::string>::get(const LLReflective* } template <> -inline const LLReflective* LLMetaPropertyT<LLString>::get(const LLReflective* object) const -{ - checkObjectClass(object); - return NULL; -} - -template <> inline const LLReflective* LLMetaPropertyT<LLUUID>::get(const LLReflective* object) const { checkObjectClass(object); @@ -112,12 +105,6 @@ inline LLSD LLMetaPropertyT<std::string>::getLLSD(const LLReflective* object) co } template <> -inline LLSD LLMetaPropertyT<LLString>::getLLSD(const LLReflective* object) const -{ - return *(getProperty(object)); -} - -template <> inline LLSD LLMetaPropertyT<LLUUID>::getLLSD(const LLReflective* object) const { return *(getProperty(object)); diff --git a/indra/llcommon/u64.cpp b/indra/llcommon/u64.cpp index f3422770ae..b23c74b79e 100644 --- a/indra/llcommon/u64.cpp +++ b/indra/llcommon/u64.cpp @@ -34,10 +34,10 @@ #include "u64.h" -U64 str_to_U64(const char *str) +U64 str_to_U64(const std::string& str) { U64 result = 0; - const char *aptr = strpbrk(str,"0123456789"); + const char *aptr = strpbrk(str.c_str(),"0123456789"); if (!aptr) { @@ -54,8 +54,9 @@ U64 str_to_U64(const char *str) } -char* U64_to_str(U64 value, char* result, S32 result_size) -{ +std::string U64_to_str(U64 value) +{ + std::string res; U32 part1,part2,part3; part3 = (U32)(value % (U64)10000000); @@ -70,31 +71,26 @@ char* U64_to_str(U64 value, char* result, S32 result_size) if (part1) { - snprintf( /* Flawfinder: ignore */ - result, - result_size, - "%u%07u%07u", - part1,part2,part3); + res = llformat("%u%07u%07u",part1,part2,part3); } else if (part2) { - snprintf( /* Flawfinder: ignore */ - result, - result_size, - "%u%07u", - part2,part3); + res = llformat("%u%07u",part2,part3); } else { - snprintf( /* Flawfinder: ignore */ - result, - result_size, - "%u", - part3); + res = llformat("%u",part3); } - return (result); + return res; } +char* U64_to_str(U64 value, char* result, S32 result_size) +{ + std::string res = U64_to_str(value); + LLStringUtil::copy(result, res.c_str(), result_size); + return result; +} + F64 U64_to_F64(const U64 value) { S64 top_bits = (S64)(value >> 1); diff --git a/indra/llcommon/u64.h b/indra/llcommon/u64.h index f4580513bc..3b833a4587 100644 --- a/indra/llcommon/u64.h +++ b/indra/llcommon/u64.h @@ -38,7 +38,14 @@ * @param str The string to parse. * @return Returns the first U64 value found in the string or 0 on failure. */ -U64 str_to_U64(const char* str); +U64 str_to_U64(const std::string& str); + +/** + * @brief Given a U64 value, return a printable representation. + * @param value The U64 to turn into a printable character array. + * @return Returns the result string. + */ +std::string U64_to_str(U64 value); /** * @brief Given a U64 value, return a printable representation. |