27#ifndef MYGUI_U_STRING_H_
28#define MYGUI_U_STRING_H_
76#ifdef __STDC_ISO_10646__
80 #if defined(__WIN32__) || defined(_WIN32)
83 #if WCHAR_MAX <= 0xFFFF
92#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
98 #if defined(_NATIVE_WCHAR_T_DEFINED)
99 #define MYGUI_IS_NATIVE_WCHAR_T 1
101 #define MYGUI_IS_NATIVE_WCHAR_T 0
106 #define MYGUI_IS_NATIVE_WCHAR_T 1
111#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
113 #pragma warning(push)
114 #pragma warning(disable : 4275)
146 static const unsigned char _lead1 = 0xC0;
147 static const unsigned char _lead1_mask = 0x1F;
148 static const unsigned char _lead2 = 0xE0;
149 static const unsigned char _lead2_mask = 0x0F;
150 static const unsigned char _lead3 = 0xF0;
151 static const unsigned char _lead3_mask = 0x07;
152 static const unsigned char _lead4 = 0xF8;
153 static const unsigned char _lead4_mask = 0x03;
154 static const unsigned char _lead5 = 0xFC;
155 static const unsigned char _lead5_mask = 0x01;
156 static const unsigned char _cont = 0x80;
157 static const unsigned char _cont_mask = 0x3F;
163 static const size_type npos = std::numeric_limits<size_t>::max();
174 using dstring = std::basic_string<code_point>;
185 std::runtime_error(_message)
203 bool _test_begin()
const;
204 bool _test_end()
const;
221 class _const_fwd_iterator;
427#if MYGUI_IS_NATIVE_WCHAR_T
434 UString(
const std::wstring& wstr);
440 UString(
const std::string& str);
444 template<
size_type num>
451 UString(str.data(), str.size())
463 size_type size()
const;
465 size_type length()
const;
468 size_type length_Characters()
const;
470 size_type max_size()
const;
472 void reserve(size_type size);
474 void resize(size_type num,
const code_point& val = 0);
480 const code_point* c_str()
const;
482 const code_point* data()
const;
484 size_type capacity()
const;
489 UString substr(size_type index, size_type num = npos)
const;
491 void push_back(unicode_char val);
492#if MYGUI_IS_NATIVE_WCHAR_T
502 void push_back(
char val);
512 const std::string& asUTF8()
const;
514 const char* asUTF8_c_str()
const;
520 const std::wstring& asWStr()
const;
522 const wchar_t* asWStr_c_str()
const;
590 UString& assign(
const std::wstring& wstr);
591#if MYGUI_IS_NATIVE_WCHAR_T
600 return assign(str.data(), str.size());
603 UString& assign(
const utf32string& str);
605 UString& assign(
const char* c_str, size_type num);
615 UString& append(
const code_point* str);
617 UString& append(
const UString& str, size_type index, size_type len);
619 UString& append(
const code_point* str, size_type num);
621 UString& append(size_type num, code_point ch);
623 UString& append(iterator start, iterator end);
624#if MYGUI_IS_NATIVE_WCHAR_T
653 UString& insert(size_type index1,
const UString& str, size_type index2, size_type num);
655 void insert(iterator i, iterator start, iterator end);
657 UString& insert(size_type index,
const code_point* str, size_type num);
658#if MYGUI_IS_NATIVE_WCHAR_T
666#if MYGUI_IS_NATIVE_WCHAR_T
676#if MYGUI_IS_NATIVE_WCHAR_T
721 int compare(
const UString& str)
const;
730#if MYGUI_IS_NATIVE_WCHAR_T
751#if MYGUI_IS_NATIVE_WCHAR_T
762#if MYGUI_IS_NATIVE_WCHAR_T
777#if MYGUI_IS_NATIVE_WCHAR_T
785#if MYGUI_IS_NATIVE_WCHAR_T
803#if MYGUI_IS_NATIVE_WCHAR_T
816#if MYGUI_IS_NATIVE_WCHAR_T
830 return find_last_of(
static_cast<code_point>(ch), index);
832#if MYGUI_IS_NATIVE_WCHAR_T
845#if MYGUI_IS_NATIVE_WCHAR_T
875#if MYGUI_IS_NATIVE_WCHAR_T
892 operator std::string()
const;
894 operator std::wstring()
const;
896 operator std::string_view()
const
907 static bool _utf16_independent_char(code_point cp);
909 static bool _utf16_surrogate_lead(code_point cp);
911 static bool _utf16_surrogate_follow(code_point cp);
913 static size_t _utf16_char_length(code_point cp);
915 static size_t _utf16_char_length(unicode_char uc);
921 static size_t _utf16_to_utf32(
const code_point in_cp[2], unicode_char& out_uc);
928 static size_t _utf32_to_utf16(
const unicode_char& in_uc, code_point out_cp[2]);
936 static bool _utf8_start_char(
unsigned char cp);
938 static size_t _utf8_char_length(
unsigned char cp);
940 static size_t _utf8_char_length(unicode_char uc);
943 static size_t _utf8_to_utf32(
const unsigned char in_cp[6], unicode_char& out_uc);
945 static size_t _utf32_to_utf8(
const unicode_char& in_uc,
unsigned char out_cp[6]);
948 static size_type _verifyUTF8(
const unsigned char* c_str);
952 return _verifyUTF8(str.data(), str.size());
955 static size_type _verifyUTF8(
const char* c_str, size_type num);
976 void _cleanBuffer()
const;
979 void _getBufferStr()
const;
981 void _getBufferWStr()
const;
983 void _getBufferUTF32Str()
const;
985 void _load_buffer_UTF8()
const;
986 void _load_buffer_WStr()
const;
987 void _load_buffer_UTF32()
const;
989 mutable BufferType m_bufferType;
990 mutable size_t m_bufferSize;
1022#if MYGUI_IS_NATIVE_WCHAR_T
1044#if MYGUI_IS_NATIVE_WCHAR_T
1129#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
1130 #pragma warning(pop)
base iterator class for UString
ptrdiff_t difference_type
const forward iterator for UString
const reverse iterator for UString
forward iterator for UString
forward iterator for UString
This exception is used when invalid data streams are encountered.
invalid_data(const std::string &_message)
constructor takes a string message that can be later retrieved by the what() function
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
UString operator+(UString::code_point c, const UString &s2)
string addition operator
iterator insert(iterator i, const code_point &ch)
inserts ch before the code point denoted by i
size_type find(wchar_t ch, size_type index=0) const
returns the index of the first occurrence ch within the current string, starting at index; returns US...
int compare(size_type index, size_type length, const wchar_t *w_str, size_type length2) const
compare a substring of str to a substring of the current string, where the substring of str begins at...
static size_type _verifyUTF8(std::string_view str)
verifies a UTF-8 stream, returning the total number of Unicode characters found
UString & assign(const wchar_t *w_str)
assign w_str to the current string
UString & assign(std::string_view str)
assign str to the current string (str is treated as a UTF-8 stream)
UString & assign(const wchar_t *w_str, size_type num)
assign the first num characters of w_str to the current string
UString & insert(size_type index, const code_point *str)
inserts str into the current string, at location index
UString operator+(const UString &s1, UString::unicode_char c)
string addition operator
std::wstring * mWStrBuffer
UString operator+(wchar_t c, const UString &s2)
string addition operator
UString & insert(size_type index, size_type num, wchar_t ch)
inserts num copies of ch into the current string, at location index
size_type find_last_of(char ch, size_type index=npos) const
returns the index of the first occurrence of ch in the current string, doing a reverse search from in...
code_point value_type
value type typedef for use in iterators
size_type find_first_of(wchar_t ch, size_type index=0) const
returns the index of the first occurrence of ch in the current string, starting the search at index; ...
size_type rfind(wchar_t ch, size_type index=0) const
returns the location of the first occurrence of ch in the current string, doing a reverse search from...
std::basic_string< unicode_char > utf32string
string type used for returning UTF-32 formatted data
UString operator+(UString::unicode_char c, const UString &s2)
string addition operator
std::ostream & operator<<(std::ostream &os, const UString &s)
std::ostream write operator
UString(std::string_view str)
UString & append(size_type num, wchar_t ch)
appends num repetitions of ch on to the end of the current string
size_type rfind(const wchar_t *w_str, size_type index, size_type num) const
returns the location of the first occurrence of str in the current string, doing a reverse search fro...
UString operator+(const UString &s1, char c)
string addition operator
UString operator+(const UString &s1, const UString &s2)
string addition operator
size_type find_first_not_of(wchar_t ch, size_type index=0) const
returns the index of the first character within the current string that does not match ch,...
UString & insert(size_type index, const wchar_t *w_str, size_type num)
inserts num code points of str into the current string, at location index
std::basic_string< code_point > dstring
UString(const wchar_t *w_str, size_type length)
duplicate of w_str, length characters long
uint16 code_point
a single UTF-16 code point
uint32 unicode_char
a single 32-bit Unicode character
void insert(iterator i, size_type num, const wchar_t &ch)
inserts num copies of ch into the current string, before the code point denoted by i
const std::wstring & asWStr() const
returns the current string in the native form of std::wstring
utf32string * mUTF32StrBuffer
UString & operator=(wchar_t ch)
assignment operator
size_type find_last_of(wchar_t ch, size_type index=npos) const
returns the index of the first occurrence of ch in the current string, doing a reverse search from in...
void push_back(wchar_t val)
appends val to the end of the string
size_type find(const wchar_t *w_str, size_type index, size_type length) const
returns the index of the first occurrence of str within the current string and within length code poi...
UString & append(const UString &str)
appends str on to the end of the current string
UString & append(const wchar_t *w_str, size_type num)
appends num characters of str on to the end of the current string
size_t size_type
size type used to indicate string size and character positions within the string
const std::string & asUTF8() const
returns the current string in UTF-8 form within a std::string
UString operator+(const UString &s1, UString::code_point c)
string addition operator
size_type find_last_not_of(wchar_t ch, size_type index=npos) const
returns the index of the last occurrence of a character that does not match ch in the current string,...
UString(const char(&str)[num])
UString operator+(const UString &s1, wchar_t c)
string addition operator
std::wostream & operator<<(std::wostream &os, const UString &s)
std::wostream write operator
UString operator+(char c, const UString &s2)
string addition operator
UString(const wchar_t *w_str)
duplicate of nul-terminated wchar_t array
UString::size_type operator-(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator<=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator==(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator>=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator>(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator!=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator<(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)