summaryrefslogtreecommitdiff
path: root/indra/llcommon/llstring.h
diff options
context:
space:
mode:
authorErik Kundiman <erik@megapahit.org>2024-07-27 15:17:57 +0800
committerErik Kundiman <erik@megapahit.org>2024-07-28 08:24:59 +0800
commit96a81b5ecbe3bffb582ded930752c0523df5e80a (patch)
treea87a0bd09fd980562e88150dbfea3819d28d9f12 /indra/llcommon/llstring.h
parent06e8f0c443c1ba7858d000c6d695b7e988e02053 (diff)
parented73208eb96b862b97fa285036edea1e792ca3c6 (diff)
Merge remote-tracking branch 'secondlife/release/2024.06-atlasaurus' into 2024.06-atlasaurus
Diffstat (limited to 'indra/llcommon/llstring.h')
-rw-r--r--indra/llcommon/llstring.h140
1 files changed, 71 insertions, 69 deletions
diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h
index 6503da2e77..123f4184b5 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>
@@ -317,7 +318,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
@@ -348,7 +349,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);
@@ -361,7 +362,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);
/**
@@ -387,15 +388,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
@@ -420,7 +421,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
@@ -447,6 +448,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
@@ -464,7 +466,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));
}
};
@@ -694,7 +696,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.
@@ -748,7 +750,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);
@@ -835,11 +837,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
@@ -1378,7 +1380,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() )
{
@@ -1634,15 +1636,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;
}
}
@@ -1771,12 +1773,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
{
@@ -1812,17 +1814,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<string_type>(*found) };
}
else
{
- // empty boost::optional
+ // empty std::optional
return {};
}
}
@@ -1843,11 +1845,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 );
@@ -1860,8 +1862,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(
@@ -1872,71 +1874,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 );
@@ -1946,17 +1948,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 );
@@ -1969,34 +1971,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 );
@@ -2009,13 +2011,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>