27 #ifndef __MYGUI_U_STRING_H__
28 #define __MYGUI_U_STRING_H__
39 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
41 # pragma warning (disable : 4275)
51 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC && (1300 <= MYGUI_COMP_VER && MYGUI_COMP_VER <= 1310)
53 # if defined(_DLL_CPPLIB)
57 template class _CRTIMP2 basic_string<unsigned short, char_traits<unsigned short>,
58 allocator<unsigned short> >;
60 template class _CRTIMP2 basic_string<__wchar_t, char_traits<__wchar_t>,
61 allocator<__wchar_t> >;
64 # endif // defined(_DLL_CPPLIB)
66 #endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC && MYGUI_COMP_VER == 1300
105 #ifdef __STDC_ISO_10646__
108 #else // #ifdef __STDC_ISO_10646__
109 #if defined( __WIN32__ ) || defined( _WIN32 )
110 #define WCHAR_UTF16 // All currently known Windows platforms utilize UTF-16 encoding in wchar_t
111 #else // #if defined( __WIN32__ ) || defined( _WIN32 )
112 #if MYGUI_COMPILER != MYGUI_COMPILER_GCCE
113 #if WCHAR_MAX <= 0xFFFF // this is a last resort fall back test; WCHAR_MAX is defined in <wchar.h>
114 #define WCHAR_UTF16 // best we can tell, wchar_t is not larger than 16-bit
115 #endif // #if WCHAR_MAX <= 0xFFFF
117 #endif // #if defined( __WIN32__ ) || defined( _WIN32 )
118 #endif // #ifdef __STDC_ISO_10646__
123 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
129 # if defined(_NATIVE_WCHAR_T_DEFINED)
130 # define MYGUI_IS_NATIVE_WCHAR_T 1
132 # define MYGUI_IS_NATIVE_WCHAR_T 0
134 #elif MYGUI_PLATFORM == MYGUI_PLATFORM_SYMBIAN
135 # define MYGUI_IS_NATIVE_WCHAR_T 0
136 #else // MYGUI_COMPILER != MYGUI_COMPILER_MSVC
139 # define MYGUI_IS_NATIVE_WCHAR_T 1
141 #endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC
171 static const unsigned char _lead1 = 0xC0;
172 static const unsigned char _lead1_mask = 0x1F;
173 static const unsigned char _lead2 = 0xE0;
174 static const unsigned char _lead2_mask = 0x0F;
175 static const unsigned char _lead3 = 0xF0;
176 static const unsigned char _lead3_mask = 0x07;
177 static const unsigned char _lead4 = 0xF8;
178 static const unsigned char _lead4_mask = 0x03;
179 static const unsigned char _lead5 = 0xFC;
180 static const unsigned char _lead5_mask = 0x01;
181 static const unsigned char _cont = 0x80;
182 static const unsigned char _cont_mask = 0x3F;
199 typedef std::basic_string<code_point>
dstring;
208 explicit invalid_data(
const std::string& _Message ): std::runtime_error( _Message ) {
223 bool _test_begin()
const;
224 bool _test_end()
const;
274 value_type& operator[]( difference_type n )
const;
320 const value_type& operator[]( difference_type n )
const;
381 value_type& operator[]( difference_type n )
const;
414 const value_type& operator[]( difference_type n )
const;
453 #if MYGUI_IS_NATIVE_WCHAR_T
454 UString(
const wchar_t* w_str );
459 UString(
const std::wstring& wstr );
466 UString(
const std::string& str );
506 #if MYGUI_IS_NATIVE_WCHAR_T
507 void push_back(
wchar_t val );
516 void push_back(
char val );
525 const std::string& asUTF8()
const;
528 const char* asUTF8_c_str()
const;
534 const std::wstring& asWStr()
const;
536 const wchar_t* asWStr_c_str()
const;
604 UString& assign(
const std::wstring& wstr );
605 #if MYGUI_IS_NATIVE_WCHAR_T
606 UString& assign(
const wchar_t* w_str );
611 UString& assign(
const std::string& str );
614 UString& assign(
const char* c_str );
635 #if MYGUI_IS_NATIVE_WCHAR_T
659 mData.
insert( index, str );
663 UString& insert( size_type index1,
const UString& str, size_type index2, size_type num );
665 void insert( iterator i, iterator start, iterator end );
667 UString& insert( size_type index,
const code_point* str, size_type num );
668 #if MYGUI_IS_NATIVE_WCHAR_T
669 UString& insert( size_type index,
const wchar_t* w_str, size_type num );
672 UString& insert( size_type index,
const char* c_str, size_type num );
675 UString& insert( size_type index, size_type num, code_point ch );
676 #if MYGUI_IS_NATIVE_WCHAR_T
677 UString& insert( size_type index, size_type num,
wchar_t ch );
680 UString& insert( size_type index, size_type num,
char ch );
683 UString& insert( size_type index, size_type num, unicode_char ch );
685 void insert( iterator i, size_type num,
const code_point& ch );
686 #if MYGUI_IS_NATIVE_WCHAR_T
687 void insert( iterator i, size_type num,
const wchar_t& ch );
690 void insert( iterator i, size_type num,
const char& ch );
693 void insert( iterator i, size_type num,
const unicode_char& ch );
700 iterator erase( iterator loc );
703 iterator erase( iterator start, iterator end );
705 UString& erase( size_type index = 0, size_type num = npos );
712 UString& replace( size_type index1, size_type num1,
const UString& str );
715 UString& replace( size_type index1, size_type num1,
const UString& str, size_type num2 );
717 UString& replace( size_type index1, size_type num1,
const UString& str, size_type index2, size_type num2 );
719 UString& replace( iterator start, iterator end,
const UString& str, size_type num = npos );
721 UString& replace( size_type index, size_type num1, size_type num2, code_point ch );
723 UString& replace( iterator start, iterator end, size_type num, code_point ch );
730 int compare(
const UString& str )
const;
733 int compare(
const code_point* str )
const;
735 int compare( size_type index, size_type length,
const UString& str )
const;
737 int compare( size_type index, size_type length,
const UString& str, size_type index2, size_type length2 )
const;
739 int compare( size_type index, size_type length,
const code_point* str, size_type length2 )
const;
740 #if MYGUI_IS_NATIVE_WCHAR_T
741 int compare( size_type index, size_type length,
const wchar_t* w_str, size_type length2 )
const;
744 int compare( size_type index, size_type length,
const char* c_str, size_type length2 )
const;
754 size_type find(
const UString& str, size_type index = 0 )
const;
757 size_type find(
const code_point* cp_str, size_type index, size_type length )
const;
760 size_type find(
const char* c_str, size_type index, size_type length )
const;
761 #if MYGUI_IS_NATIVE_WCHAR_T
764 size_type find(
const wchar_t* w_str, size_type index, size_type length )
const;
768 size_type find(
char ch, size_type index = 0 )
const;
771 size_type find( code_point ch, size_type index = 0 )
const;
772 #if MYGUI_IS_NATIVE_WCHAR_T
775 size_type find(
wchar_t ch, size_type index = 0 )
const;
779 size_type find( unicode_char ch, size_type index = 0 )
const;
782 size_type rfind(
const UString& str, size_type index = 0 )
const;
784 size_type rfind(
const code_point* cp_str, size_type index, size_type num )
const;
786 size_type rfind(
const char* c_str, size_type index, size_type num )
const;
787 #if MYGUI_IS_NATIVE_WCHAR_T
788 size_type rfind(
const wchar_t* w_str, size_type index, size_type num )
const;
791 size_type rfind(
char ch, size_type index = 0 )
const;
794 size_type rfind( code_point ch, size_type index )
const;
795 #if MYGUI_IS_NATIVE_WCHAR_T
796 size_type rfind(
wchar_t ch, size_type index = 0 )
const;
799 size_type rfind( unicode_char ch, size_type index = 0 )
const;
807 size_type find_first_of(
const UString &str, size_type index = 0, size_type num = npos )
const;
810 size_type find_first_of( code_point ch, size_type index = 0 )
const;
812 size_type find_first_of(
char ch, size_type index = 0 )
const;
813 #if MYGUI_IS_NATIVE_WCHAR_T
814 size_type find_first_of(
wchar_t ch, size_type index = 0 )
const;
817 size_type find_first_of( unicode_char ch, size_type index = 0 )
const;
821 size_type find_first_not_of(
const UString& str, size_type index = 0, size_type num = npos )
const;
823 size_type find_first_not_of( code_point ch, size_type index = 0 )
const;
825 size_type find_first_not_of(
char ch, size_type index = 0 )
const;
826 #if MYGUI_IS_NATIVE_WCHAR_T
827 size_type find_first_not_of(
wchar_t ch, size_type index = 0 )
const;
830 size_type find_first_not_of( unicode_char ch, size_type index = 0 )
const;
834 size_type find_last_of(
const UString& str, size_type index = npos, size_type num = npos )
const;
836 size_type find_last_of( code_point ch, size_type index = npos )
const;
839 return find_last_of( static_cast<code_point>( ch ), index );
841 #if MYGUI_IS_NATIVE_WCHAR_T
842 size_type find_last_of(
wchar_t ch, size_type index = npos )
const;
845 size_type find_last_of( unicode_char ch, size_type index = npos )
const;
849 size_type find_last_not_of(
const UString& str, size_type index = npos, size_type num = npos )
const;
851 size_type find_last_not_of( code_point ch, size_type index = npos )
const;
853 size_type find_last_not_of(
char ch, size_type index = npos )
const;
854 #if MYGUI_IS_NATIVE_WCHAR_T
855 size_type find_last_not_of(
wchar_t ch, size_type index = npos )
const;
858 size_type find_last_not_of( unicode_char ch, size_type index = npos )
const;
881 UString& operator=( code_point ch );
884 #if MYGUI_IS_NATIVE_WCHAR_T
885 UString& operator=(
wchar_t ch );
888 UString& operator=( unicode_char ch );
891 code_point& operator[]( size_type index );
893 const code_point& operator[]( size_type index )
const;
900 operator std::string()
const;
903 operator std::wstring()
const;
910 static bool _utf16_independent_char( code_point cp );
913 static bool _utf16_surrogate_lead( code_point cp );
915 static bool _utf16_surrogate_follow( code_point cp );
917 static size_t _utf16_char_length( code_point cp );
919 static size_t _utf16_char_length( unicode_char uc );
925 static size_t _utf16_to_utf32(
const code_point in_cp[2], unicode_char& out_uc );
932 static size_t _utf32_to_utf16(
const unicode_char& in_uc, code_point out_cp[2] );
939 static bool _utf8_start_char(
unsigned char cp );
942 static size_t _utf8_char_length(
unsigned char cp );
944 static size_t _utf8_char_length( unicode_char uc );
947 static size_t _utf8_to_utf32(
const unsigned char in_cp[6], unicode_char& out_uc );
949 static size_t _utf32_to_utf8(
const unicode_char& in_uc,
unsigned char out_cp[6] );
952 static size_type _verifyUTF8(
const unsigned char* c_str );
954 static size_type _verifyUTF8(
const std::string& str );
975 void _cleanBuffer()
const;
978 void _getBufferStr()
const;
980 void _getBufferWStr()
const;
982 void _getBufferUTF32Str()
const;
984 void _load_buffer_UTF8()
const;
985 void _load_buffer_WStr()
const;
986 void _load_buffer_UTF32()
const;
988 mutable BufferType m_bufferType;
989 mutable size_t m_bufferSize;
1017 #if MYGUI_IS_NATIVE_WCHAR_T
1035 #if MYGUI_IS_NATIVE_WCHAR_T
1090 inline std::ostream& operator << ( std::ostream& os,
const UString& s ) {
1095 inline std::wostream& operator << ( std::wostream& os,
const UString& s ) {
1101 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
1102 # pragma warning (default : 4275)
1105 #endif // __MYGUI_U_STRING_H__