27 #ifndef MYGUI_U_STRING_H_
28 #define MYGUI_U_STRING_H_
39 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
41 # pragma warning (push)
42 # pragma warning (disable : 4275)
52 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC && (1300 <= MYGUI_COMP_VER && MYGUI_COMP_VER <= 1310)
54 # if defined(_DLL_CPPLIB)
58 template class _CRTIMP2 basic_string<unsigned short, char_traits<unsigned short>,
59 allocator<unsigned short> >;
61 template class _CRTIMP2 basic_string<__wchar_t, char_traits<__wchar_t>,
62 allocator<__wchar_t> >;
65 # endif // defined(_DLL_CPPLIB)
67 #endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC && MYGUI_COMP_VER == 1300
106 #ifdef __STDC_ISO_10646__
109 #else // #ifdef __STDC_ISO_10646__
110 #if defined( __WIN32__ ) || defined( _WIN32 )
111 #define WCHAR_UTF16 // All currently known Windows platforms utilize UTF-16 encoding in wchar_t
112 #else // #if defined( __WIN32__ ) || defined( _WIN32 )
113 #if MYGUI_COMPILER != MYGUI_COMPILER_GCCE
114 #if WCHAR_MAX <= 0xFFFF // this is a last resort fall back test; WCHAR_MAX is defined in <wchar.h>
115 #define WCHAR_UTF16 // best we can tell, wchar_t is not larger than 16-bit
116 #endif // #if WCHAR_MAX <= 0xFFFF
118 #endif // #if defined( __WIN32__ ) || defined( _WIN32 )
119 #endif // #ifdef __STDC_ISO_10646__
124 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
130 # if defined(_NATIVE_WCHAR_T_DEFINED)
131 # define MYGUI_IS_NATIVE_WCHAR_T 1
133 # define MYGUI_IS_NATIVE_WCHAR_T 0
135 #else // MYGUI_COMPILER != MYGUI_COMPILER_MSVC
138 # define MYGUI_IS_NATIVE_WCHAR_T 1
140 #endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC
170 static const unsigned char _lead1 = 0xC0;
171 static const unsigned char _lead1_mask = 0x1F;
172 static const unsigned char _lead2 = 0xE0;
173 static const unsigned char _lead2_mask = 0x0F;
174 static const unsigned char _lead3 = 0xF0;
175 static const unsigned char _lead3_mask = 0x07;
176 static const unsigned char _lead4 = 0xF8;
177 static const unsigned char _lead4_mask = 0x03;
178 static const unsigned char _lead5 = 0xFC;
179 static const unsigned char _lead5_mask = 0x01;
180 static const unsigned char _cont = 0x80;
181 static const unsigned char _cont_mask = 0x3F;
198 using dstring = std::basic_string<code_point>;
207 explicit invalid_data(
const std::string& _Message ): std::runtime_error( _Message ) {
225 bool _test_begin()
const;
226 bool _test_end()
const;
458 #if MYGUI_IS_NATIVE_WCHAR_T
459 UString(
const wchar_t* w_str );
464 UString(
const std::wstring& wstr );
471 UString(
const std::string& str );
511 #if MYGUI_IS_NATIVE_WCHAR_T
512 void push_back(
wchar_t val );
521 void push_back(
char val );
530 const std::string& asUTF8()
const;
533 const char* asUTF8_c_str()
const;
539 const std::wstring& asWStr()
const;
541 const wchar_t* asWStr_c_str()
const;
609 UString& assign(
const std::wstring& wstr );
610 #if MYGUI_IS_NATIVE_WCHAR_T
611 UString& assign(
const wchar_t* w_str );
616 UString& assign(
const std::string& str );
619 UString& assign(
const char* c_str );
640 #if MYGUI_IS_NATIVE_WCHAR_T
664 mData.
insert( index, str );
668 UString& insert( size_type index1,
const UString& str, size_type index2, size_type num );
670 void insert( iterator i, iterator start, iterator end );
672 UString& insert( size_type index,
const code_point* str, size_type num );
673 #if MYGUI_IS_NATIVE_WCHAR_T
674 UString& insert( size_type index,
const wchar_t* w_str, size_type num );
677 UString& insert( size_type index,
const char* c_str, size_type num );
680 UString& insert( size_type index, size_type num, code_point ch );
681 #if MYGUI_IS_NATIVE_WCHAR_T
682 UString& insert( size_type index, size_type num,
wchar_t ch );
685 UString& insert( size_type index, size_type num,
char ch );
688 UString& insert( size_type index, size_type num, unicode_char ch );
690 void insert( iterator i, size_type num,
const code_point& ch );
691 #if MYGUI_IS_NATIVE_WCHAR_T
692 void insert( iterator i, size_type num,
const wchar_t& ch );
695 void insert( iterator i, size_type num,
const char& ch );
698 void insert( iterator i, size_type num,
const unicode_char& ch );
705 iterator erase( iterator loc );
708 iterator erase( iterator start, iterator end );
710 UString& erase( size_type index = 0, size_type num = npos );
717 UString& replace( size_type index1, size_type num1,
const UString& str );
720 UString& replace( size_type index1, size_type num1,
const UString& str, size_type num2 );
722 UString& replace( size_type index1, size_type num1,
const UString& str, size_type index2, size_type num2 );
724 UString& replace( iterator start, iterator end,
const UString& str, size_type num = npos );
726 UString& replace( size_type index, size_type num1, size_type num2, code_point ch );
728 UString& replace( iterator start, iterator end, size_type num, code_point ch );
735 int compare(
const UString& str )
const;
738 int compare(
const code_point* str )
const;
740 int compare( size_type index, size_type length,
const UString& str )
const;
742 int compare( size_type index, size_type length,
const UString& str, size_type index2, size_type length2 )
const;
744 int compare( size_type index, size_type length,
const code_point* str, size_type length2 )
const;
745 #if MYGUI_IS_NATIVE_WCHAR_T
746 int compare( size_type index, size_type length,
const wchar_t* w_str, size_type length2 )
const;
749 int compare( size_type index, size_type length,
const char* c_str, size_type length2 )
const;
759 size_type find(
const UString& str, size_type index = 0 )
const;
762 size_type find(
const code_point* cp_str, size_type index, size_type length )
const;
765 size_type find(
const char* c_str, size_type index, size_type length )
const;
766 #if MYGUI_IS_NATIVE_WCHAR_T
777 #if MYGUI_IS_NATIVE_WCHAR_T
792 #if MYGUI_IS_NATIVE_WCHAR_T
800 #if MYGUI_IS_NATIVE_WCHAR_T
818 #if MYGUI_IS_NATIVE_WCHAR_T
831 #if MYGUI_IS_NATIVE_WCHAR_T
844 return find_last_of(
static_cast<code_point>( ch ), index );
846 #if MYGUI_IS_NATIVE_WCHAR_T
847 size_type find_last_of(
wchar_t ch, size_type index = npos )
const;
850 size_type find_last_of( unicode_char ch, size_type index = npos )
const;
854 size_type find_last_not_of(
const UString& str, size_type index = npos, size_type num = npos )
const;
856 size_type find_last_not_of( code_point ch, size_type index = npos )
const;
858 size_type find_last_not_of(
char ch, size_type index = npos )
const;
859 #if MYGUI_IS_NATIVE_WCHAR_T
860 size_type find_last_not_of(
wchar_t ch, size_type index = npos )
const;
863 size_type find_last_not_of( unicode_char ch, size_type index = npos )
const;
886 UString& operator=( code_point ch );
889 #if MYGUI_IS_NATIVE_WCHAR_T
890 UString& operator=(
wchar_t ch );
893 UString& operator=( unicode_char ch );
896 code_point& operator[]( size_type index );
898 const code_point& operator[]( size_type index )
const;
905 operator std::string()
const;
908 operator std::wstring()
const;
915 static bool _utf16_independent_char( code_point cp );
918 static bool _utf16_surrogate_lead( code_point cp );
920 static bool _utf16_surrogate_follow( code_point cp );
922 static size_t _utf16_char_length( code_point cp );
924 static size_t _utf16_char_length( unicode_char uc );
930 static size_t _utf16_to_utf32(
const code_point in_cp[2], unicode_char& out_uc );
937 static size_t _utf32_to_utf16(
const unicode_char& in_uc, code_point out_cp[2] );
944 static bool _utf8_start_char(
unsigned char cp );
947 static size_t _utf8_char_length(
unsigned char cp );
949 static size_t _utf8_char_length( unicode_char uc );
952 static size_t _utf8_to_utf32(
const unsigned char in_cp[6], unicode_char& out_uc );
954 static size_t _utf32_to_utf8(
const unicode_char& in_uc,
unsigned char out_cp[6] );
957 static size_type _verifyUTF8(
const unsigned char* c_str );
959 static size_type _verifyUTF8(
const std::string& str );
980 void _cleanBuffer()
const;
983 void _getBufferStr()
const;
985 void _getBufferWStr()
const;
987 void _getBufferUTF32Str()
const;
989 void _load_buffer_UTF8()
const;
990 void _load_buffer_WStr()
const;
991 void _load_buffer_UTF32()
const;
993 mutable BufferType m_bufferType;
994 mutable size_t m_bufferSize;
1022 #if MYGUI_IS_NATIVE_WCHAR_T
1040 #if MYGUI_IS_NATIVE_WCHAR_T
1095 inline std::ostream& operator << ( std::ostream& os,
const UString& s ) {
1100 inline std::wostream& operator << ( std::wostream& os,
const UString& s ) {
1106 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
1107 # pragma warning (pop)
1110 #endif // __MYGUI_U_STRING_H__