27#ifndef MYGUI_U_STRING_H_
28#define MYGUI_U_STRING_H_
37#if __cplusplus >= 201703L
78#ifdef __STDC_ISO_10646__
82#if defined( __WIN32__ ) || defined( _WIN32 )
85#if WCHAR_MAX <= 0xFFFF
94#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
100# if defined(_NATIVE_WCHAR_T_DEFINED)
101# define MYGUI_IS_NATIVE_WCHAR_T 1
103# define MYGUI_IS_NATIVE_WCHAR_T 0
108# define MYGUI_IS_NATIVE_WCHAR_T 1
113#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
115# pragma warning (push)
116# pragma warning (disable : 4275)
147 static const unsigned char _lead1 = 0xC0;
148 static const unsigned char _lead1_mask = 0x1F;
149 static const unsigned char _lead2 = 0xE0;
150 static const unsigned char _lead2_mask = 0x0F;
151 static const unsigned char _lead3 = 0xF0;
152 static const unsigned char _lead3_mask = 0x07;
153 static const unsigned char _lead4 = 0xF8;
154 static const unsigned char _lead4_mask = 0x03;
155 static const unsigned char _lead5 = 0xFC;
156 static const unsigned char _lead5_mask = 0x01;
157 static const unsigned char _cont = 0x80;
158 static const unsigned char _cont_mask = 0x3F;
175 using dstring = std::basic_string<code_point>;
202 bool _test_begin()
const;
203 bool _test_end()
const;
435#if MYGUI_IS_NATIVE_WCHAR_T
452 template <
size_type num>
455#if __cplusplus >= 201703L
467 size_type size()
const;
469 size_type length()
const;
472 size_type length_Characters()
const;
474 size_type max_size()
const;
476 void reserve( size_type size );
478 void resize( size_type num,
const code_point& val = 0 );
480 void swap( UString& from );
484 const code_point* c_str()
const;
486 const code_point* data()
const;
488 size_type capacity()
const;
493 UString substr( size_type index, size_type num = npos )
const;
495 void push_back( unicode_char val );
496#if MYGUI_IS_NATIVE_WCHAR_T
506 void push_back(
char val );
516 const std::string& asUTF8()
const;
518 const char* asUTF8_c_str()
const;
524 const std::wstring& asWStr()
const;
526 const wchar_t* asWStr_c_str()
const;
595#if MYGUI_IS_NATIVE_WCHAR_T
606 UString& assign(
const char* c_str );
627#if MYGUI_IS_NATIVE_WCHAR_T
657 void insert( iterator
i, iterator start, iterator end );
659 UString& insert( size_type index,
const code_point*
str, size_type
num );
660#if MYGUI_IS_NATIVE_WCHAR_T
668#if MYGUI_IS_NATIVE_WCHAR_T
678#if MYGUI_IS_NATIVE_WCHAR_T
732#if MYGUI_IS_NATIVE_WCHAR_T
753#if MYGUI_IS_NATIVE_WCHAR_T
764#if MYGUI_IS_NATIVE_WCHAR_T
779#if MYGUI_IS_NATIVE_WCHAR_T
787#if MYGUI_IS_NATIVE_WCHAR_T
805#if MYGUI_IS_NATIVE_WCHAR_T
818#if MYGUI_IS_NATIVE_WCHAR_T
831 return find_last_of(
static_cast<code_point>(
ch ), index );
833#if MYGUI_IS_NATIVE_WCHAR_T
846#if MYGUI_IS_NATIVE_WCHAR_T
876#if MYGUI_IS_NATIVE_WCHAR_T
893 operator std::string()
const;
895 operator std::wstring()
const;
932 static bool _utf8_start_char(
unsigned char cp );
934 static size_t _utf8_char_length(
unsigned char cp );
944 static size_type _verifyUTF8(
const unsigned char* c_str );
969 void _cleanBuffer()
const;
972 void _getBufferStr()
const;
974 void _getBufferWStr()
const;
976 void _getBufferUTF32Str()
const;
978 void _load_buffer_UTF8()
const;
979 void _load_buffer_WStr()
const;
980 void _load_buffer_UTF32()
const;
982 mutable BufferType m_bufferType;
983 mutable size_t m_bufferSize;
1011#if MYGUI_IS_NATIVE_WCHAR_T
1029#if MYGUI_IS_NATIVE_WCHAR_T
1085 return os <<
s.asUTF8();
1090 return os <<
s.asWStr();
1093#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
1094# 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...
UString & assign(const wchar_t *w_str)
assign w_str to the current string
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...
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
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
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
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
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)