27#ifndef MYGUI_U_STRING_H_
28#define MYGUI_U_STRING_H_
75#ifdef __STDC_ISO_10646__
79#if defined( __WIN32__ ) || defined( _WIN32 )
82#if WCHAR_MAX <= 0xFFFF
91#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
97# if defined(_NATIVE_WCHAR_T_DEFINED)
98# define MYGUI_IS_NATIVE_WCHAR_T 1
100# define MYGUI_IS_NATIVE_WCHAR_T 0
105# define MYGUI_IS_NATIVE_WCHAR_T 1
137 static const unsigned char _lead1 = 0xC0;
138 static const unsigned char _lead1_mask = 0x1F;
139 static const unsigned char _lead2 = 0xE0;
140 static const unsigned char _lead2_mask = 0x0F;
141 static const unsigned char _lead3 = 0xF0;
142 static const unsigned char _lead3_mask = 0x07;
143 static const unsigned char _lead4 = 0xF8;
144 static const unsigned char _lead4_mask = 0x03;
145 static const unsigned char _lead5 = 0xFC;
146 static const unsigned char _lead5_mask = 0x01;
147 static const unsigned char _cont = 0x80;
148 static const unsigned char _cont_mask = 0x3F;
165 using dstring = std::basic_string<code_point>;
174 explicit invalid_data(
const std::string& _Message ): std::runtime_error( _Message ) {
192 bool _test_begin()
const;
193 bool _test_end()
const;
425#if MYGUI_IS_NATIVE_WCHAR_T
432 UString(
const std::wstring& wstr );
438 UString(
const std::string& str );
480#if MYGUI_IS_NATIVE_WCHAR_T
490 void push_back(
char val );
500 const std::string& asUTF8()
const;
502 const char* asUTF8_c_str()
const;
508 const std::wstring& asWStr()
const;
510 const wchar_t* asWStr_c_str()
const;
578 UString& assign(
const std::wstring& wstr );
579#if MYGUI_IS_NATIVE_WCHAR_T
586 UString& assign(
const std::string& str );
590 UString& assign(
const char* c_str );
611#if MYGUI_IS_NATIVE_WCHAR_T
635 mData.
insert( index, str );
639 UString& insert( size_type index1,
const UString& str, size_type index2, size_type num );
641 void insert( iterator i, iterator start, iterator end );
643 UString& insert( size_type index,
const code_point* str, size_type num );
644#if MYGUI_IS_NATIVE_WCHAR_T
652#if MYGUI_IS_NATIVE_WCHAR_T
662#if MYGUI_IS_NATIVE_WCHAR_T
707 int compare(
const UString& str )
const;
716#if MYGUI_IS_NATIVE_WCHAR_T
737#if MYGUI_IS_NATIVE_WCHAR_T
748#if MYGUI_IS_NATIVE_WCHAR_T
763#if MYGUI_IS_NATIVE_WCHAR_T
771#if MYGUI_IS_NATIVE_WCHAR_T
789#if MYGUI_IS_NATIVE_WCHAR_T
802#if MYGUI_IS_NATIVE_WCHAR_T
815 return find_last_of(
static_cast<code_point>( ch ), index );
817#if MYGUI_IS_NATIVE_WCHAR_T
830#if MYGUI_IS_NATIVE_WCHAR_T
860#if MYGUI_IS_NATIVE_WCHAR_T
877 operator std::string()
const;
879 operator std::wstring()
const;
887 static bool _utf16_independent_char(
code_point cp );
889 static bool _utf16_surrogate_lead(
code_point cp );
891 static bool _utf16_surrogate_follow(
code_point cp );
893 static size_t _utf16_char_length(
code_point cp );
916 static bool _utf8_start_char(
unsigned char cp );
918 static size_t _utf8_char_length(
unsigned char cp );
923 static size_t _utf8_to_utf32(
const unsigned char in_cp[6],
unicode_char& out_uc );
925 static size_t _utf32_to_utf8(
const unicode_char& in_uc,
unsigned char out_cp[6] );
928 static size_type _verifyUTF8(
const unsigned char* c_str );
930 static size_type _verifyUTF8(
const std::string& str );
951 void _cleanBuffer()
const;
954 void _getBufferStr()
const;
956 void _getBufferWStr()
const;
958 void _getBufferUTF32Str()
const;
960 void _load_buffer_UTF8()
const;
961 void _load_buffer_WStr()
const;
962 void _load_buffer_UTF32()
const;
964 mutable BufferType m_bufferType;
965 mutable size_t m_bufferSize;
993#if MYGUI_IS_NATIVE_WCHAR_T
1011#if MYGUI_IS_NATIVE_WCHAR_T
1066 inline std::ostream& operator << ( std::ostream& os,
const UString& s ) {
1071 inline std::wostream& operator << ( std::wostream& os,
const UString& s ) {
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...
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
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 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)
float len(float x, float y)
bool operator<(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)