diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2024-08-28 20:47:43 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2024-08-28 20:47:43 -0400 |
commit | cde1174345224d33d6b45b1e3243fa39043223e5 (patch) | |
tree | 6c8db6e0499622d8c7206a11c997eb173ebd478f /indra/llcommon/llstring.h | |
parent | 6f454ad8366ed33bbe199c3fc3ed69e6d3448cec (diff) | |
parent | 35efadf78315f9b351415930dca4fae251ef4dd0 (diff) |
Merge branch 'main' into release/luau-scripting.
Diffstat (limited to 'indra/llcommon/llstring.h')
-rw-r--r-- | indra/llcommon/llstring.h | 140 |
1 files changed, 71 insertions, 69 deletions
diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h index cd8b2a2dcd..e49e293756 100644 --- a/indra/llcommon/llstring.h +++ b/indra/llcommon/llstring.h @@ -28,8 +28,9 @@ #define LL_LLSTRING_H #include <boost/call_traits.hpp> -#include <boost/optional/optional.hpp> +#include <optional> #include <string> +#include <string_view> #include <cstdio> #include <cwchar> // std::wcslen() //#include <locale> @@ -327,7 +328,7 @@ public: static void toLower(string_type& string); // True if this is the head of s. - static BOOL isHead( const string_type& string, const T* s ); + static bool isHead( const string_type& string, const T* s ); /** * @brief Returns true if string starts with substr @@ -358,7 +359,7 @@ public: * (key is always UTF-8) * detect absence by (! return value) */ - static boost::optional<string_type> getoptenv(const std::string& key); + static std::optional<string_type> getoptenv(const std::string& key); static void addCRLF(string_type& string); static void removeCRLF(string_type& string); @@ -371,7 +372,7 @@ public: static string_type capitalize(const string_type& str); static void capitalize(string_type& str); - static BOOL containsNonprintable(const string_type& string); + static bool containsNonprintable(const string_type& string); static void stripNonprintable(string_type& string); /** @@ -397,15 +398,15 @@ public: static void _makeASCII(string_type& string); // Conversion to other data types - static BOOL convertToBOOL(const string_type& string, BOOL& value); - static BOOL convertToU8(const string_type& string, U8& value); - static BOOL convertToS8(const string_type& string, S8& value); - static BOOL convertToS16(const string_type& string, S16& value); - static BOOL convertToU16(const string_type& string, U16& value); - static BOOL convertToU32(const string_type& string, U32& value); - static BOOL convertToS32(const string_type& string, S32& value); - static BOOL convertToF32(const string_type& string, F32& value); - static BOOL convertToF64(const string_type& string, F64& value); + static bool convertToBOOL(const string_type& string, bool& value); + static bool convertToU8(const string_type& string, U8& value); + static bool convertToS8(const string_type& string, S8& value); + static bool convertToS16(const string_type& string, S16& value); + static bool convertToU16(const string_type& string, U16& value); + static bool convertToU32(const string_type& string, U32& value); + static bool convertToS32(const string_type& string, S32& value); + static bool convertToF32(const string_type& string, F32& value); + static bool convertToF64(const string_type& string, F64& value); ///////////////////////////////////////////////////////////////////////////////////////// // Utility functions for working with char*'s and strings @@ -430,7 +431,7 @@ public: static S32 compareDictInsensitive(const string_type& a, const string_type& b); // Puts compareDict() in a form appropriate for LL container classes to use for sorting. - static BOOL precedesDict( const string_type& a, const string_type& b ); + static bool precedesDict( const string_type& a, const string_type& b ); // A replacement for strncpy. // If the dst buffer is dst_size bytes long or more, ensures that dst is null terminated and holds @@ -457,6 +458,7 @@ template<class T> std::string LLStringUtilBase<T>::sLocale; typedef LLStringUtilBase<char> LLStringUtil; typedef LLStringUtilBase<llwchar> LLWStringUtil; typedef std::basic_string<llwchar> LLWString; +typedef std::basic_string_view<llwchar> LLWStringView; //@ 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 @@ -474,7 +476,7 @@ struct LLDictionaryLess public: bool operator()(const std::string& a, const std::string& b) const { - return (LLStringUtil::precedesDict(a, b) ? true : false); + return (LLStringUtil::precedesDict(a, b)); } }; @@ -731,7 +733,7 @@ LL_COMMON_API S32 utf16str_wstring_length(const llutf16string &utf16str, S32 len LL_COMMON_API S32 wstring_utf16_length(const LLWString & wstr, S32 woffset, S32 wlen); // Length in wstring (i.e., llwchar count) of a part of a wstring specified by utf16 length (i.e., utf16 units.) -LL_COMMON_API S32 wstring_wstring_length_from_utf16_length(const LLWString & wstr, S32 woffset, S32 utf16_length, BOOL *unaligned = NULL); +LL_COMMON_API S32 wstring_wstring_length_from_utf16_length(const LLWString & wstr, S32 woffset, S32 utf16_length, bool *unaligned = nullptr); /** * @brief Properly truncate a utf8 string to a maximum byte count. @@ -785,7 +787,7 @@ LL_COMMON_API llwchar utf8str_to_wchar(const std::string& utf8str, size_t offset LL_COMMON_API std::string utf8str_showBytesUTF8(const std::string& utf8str); -LL_COMMON_API bool wstring_has_emoji(const LLWString& wstr); +LL_COMMON_API bool wstring_has_emoji(LLWStringView wstr); LL_COMMON_API bool wstring_remove_emojis(LLWString& wstr); @@ -872,11 +874,11 @@ STRING windows_message() { return windows_message<STRING>(GetLastError()); } //@} -LL_COMMON_API boost::optional<std::wstring> llstring_getoptenv(const std::string& key); +LL_COMMON_API std::optional<std::wstring> llstring_getoptenv(const std::string& key); #else // ! LL_WINDOWS -LL_COMMON_API boost::optional<std::string> llstring_getoptenv(const std::string& key); +LL_COMMON_API std::optional<std::string> llstring_getoptenv(const std::string& key); #endif // ! LL_WINDOWS @@ -1415,7 +1417,7 @@ S32 LLStringUtilBase<T>::compareDictInsensitive(const string_type& astr, const s // Puts compareDict() in a form appropriate for LL container classes to use for sorting. // static template<class T> -BOOL LLStringUtilBase<T>::precedesDict( const string_type& a, const string_type& b ) +bool LLStringUtilBase<T>::precedesDict( const string_type& a, const string_type& b ) { if( a.size() && b.size() ) { @@ -1725,15 +1727,15 @@ void LLStringUtilBase<T>::capitalize(string_type& str) //static template<class T> -BOOL LLStringUtilBase<T>::containsNonprintable(const string_type& string) +bool LLStringUtilBase<T>::containsNonprintable(const string_type& string) { const char MIN = 32; - BOOL rv = FALSE; + bool rv = false; for (size_type i = 0; i < string.size(); i++) { if(string[i] < MIN) { - rv = TRUE; + rv = true; break; } } @@ -1862,12 +1864,12 @@ void LLStringUtilBase<T>::copyInto(string_type& dst, const string_type& src, siz // True if this is the head of s. //static template<class T> -BOOL LLStringUtilBase<T>::isHead( const string_type& string, const T* s ) +bool LLStringUtilBase<T>::isHead( const string_type& string, const T* s ) { if( string.empty() ) { // Early exit - return FALSE; + return false; } else { @@ -1903,17 +1905,17 @@ bool LLStringUtilBase<T>::endsWith( // static template<class T> -auto LLStringUtilBase<T>::getoptenv(const std::string& key) -> boost::optional<string_type> +auto LLStringUtilBase<T>::getoptenv(const std::string& key) -> std::optional<string_type> { auto found(llstring_getoptenv(key)); if (found) { - // return populated boost::optional + // return populated std::optional return { ll_convert_to<string_type>(*found) }; } else { - // empty boost::optional + // empty std::optional return {}; } } @@ -1934,11 +1936,11 @@ auto LLStringUtilBase<T>::getenv(const std::string& key, const string_type& dflt } template<class T> -BOOL LLStringUtilBase<T>::convertToBOOL(const string_type& string, BOOL& value) +bool LLStringUtilBase<T>::convertToBOOL(const string_type& string, bool& value) { if( string.empty() ) { - return FALSE; + return false; } string_type temp( string ); @@ -1951,8 +1953,8 @@ BOOL LLStringUtilBase<T>::convertToBOOL(const string_type& string, BOOL& value) (temp == "true") || (temp == "True") ) { - value = TRUE; - return TRUE; + value = true; + return true; } else if( @@ -1963,71 +1965,71 @@ BOOL LLStringUtilBase<T>::convertToBOOL(const string_type& string, BOOL& value) (temp == "false") || (temp == "False") ) { - value = FALSE; - return TRUE; + value = false; + return true; } - return FALSE; + return false; } template<class T> -BOOL LLStringUtilBase<T>::convertToU8(const string_type& string, U8& value) +bool LLStringUtilBase<T>::convertToU8(const string_type& string, U8& value) { S32 value32 = 0; - BOOL success = convertToS32(string, value32); + bool success = convertToS32(string, value32); if( success && (U8_MIN <= value32) && (value32 <= U8_MAX) ) { value = (U8) value32; - return TRUE; + return true; } - return FALSE; + return false; } template<class T> -BOOL LLStringUtilBase<T>::convertToS8(const string_type& string, S8& value) +bool LLStringUtilBase<T>::convertToS8(const string_type& string, S8& value) { S32 value32 = 0; - BOOL success = convertToS32(string, value32); + bool success = convertToS32(string, value32); if( success && (S8_MIN <= value32) && (value32 <= S8_MAX) ) { value = (S8) value32; - return TRUE; + return true; } - return FALSE; + return false; } template<class T> -BOOL LLStringUtilBase<T>::convertToS16(const string_type& string, S16& value) +bool LLStringUtilBase<T>::convertToS16(const string_type& string, S16& value) { S32 value32 = 0; - BOOL success = convertToS32(string, value32); + bool success = convertToS32(string, value32); if( success && (S16_MIN <= value32) && (value32 <= S16_MAX) ) { value = (S16) value32; - return TRUE; + return true; } - return FALSE; + return false; } template<class T> -BOOL LLStringUtilBase<T>::convertToU16(const string_type& string, U16& value) +bool LLStringUtilBase<T>::convertToU16(const string_type& string, U16& value) { S32 value32 = 0; - BOOL success = convertToS32(string, value32); + bool success = convertToS32(string, value32); if( success && (U16_MIN <= value32) && (value32 <= U16_MAX) ) { value = (U16) value32; - return TRUE; + return true; } - return FALSE; + return false; } template<class T> -BOOL LLStringUtilBase<T>::convertToU32(const string_type& string, U32& value) +bool LLStringUtilBase<T>::convertToU32(const string_type& string, U32& value) { if( string.empty() ) { - return FALSE; + return false; } string_type temp( string ); @@ -2037,17 +2039,17 @@ BOOL LLStringUtilBase<T>::convertToU32(const string_type& string, U32& value) if(i_stream >> v) { value = v; - return TRUE; + return true; } - return FALSE; + return false; } template<class T> -BOOL LLStringUtilBase<T>::convertToS32(const string_type& string, S32& value) +bool LLStringUtilBase<T>::convertToS32(const string_type& string, S32& value) { if( string.empty() ) { - return FALSE; + return false; } string_type temp( string ); @@ -2060,34 +2062,34 @@ BOOL LLStringUtilBase<T>::convertToS32(const string_type& string, S32& value) //if((LONG_MAX == v) || (LONG_MIN == v)) //{ // // Underflow or overflow - // return FALSE; + // return false; //} value = v; - return TRUE; + return true; } - return FALSE; + return false; } template<class T> -BOOL LLStringUtilBase<T>::convertToF32(const string_type& string, F32& value) +bool LLStringUtilBase<T>::convertToF32(const string_type& string, F32& value) { F64 value64 = 0.0; - BOOL success = convertToF64(string, value64); + bool success = convertToF64(string, value64); if( success && (-F32_MAX <= value64) && (value64 <= F32_MAX) ) { value = (F32) value64; - return TRUE; + return true; } - return FALSE; + return false; } template<class T> -BOOL LLStringUtilBase<T>::convertToF64(const string_type& string, F64& value) +bool LLStringUtilBase<T>::convertToF64(const string_type& string, F64& value) { if( string.empty() ) { - return FALSE; + return false; } string_type temp( string ); @@ -2100,13 +2102,13 @@ BOOL LLStringUtilBase<T>::convertToF64(const string_type& string, F64& value) //if( ((-HUGE_VAL == v) || (HUGE_VAL == v))) ) //{ // // Underflow or overflow - // return FALSE; + // return false; //} value = v; - return TRUE; + return true; } - return FALSE; + return false; } template<class T> |