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 #elif MYGUI_PLATFORM == MYGUI_PLATFORM_SYMBIAN
136 # define MYGUI_IS_NATIVE_WCHAR_T 0
137 #else // MYGUI_COMPILER != MYGUI_COMPILER_MSVC
140 # define MYGUI_IS_NATIVE_WCHAR_T 1
142 #endif // MYGUI_COMPILER == MYGUI_COMPILER_MSVC
172 static const unsigned char _lead1 = 0xC0;
173 static const unsigned char _lead1_mask = 0x1F;
174 static const unsigned char _lead2 = 0xE0;
175 static const unsigned char _lead2_mask = 0x0F;
176 static const unsigned char _lead3 = 0xF0;
177 static const unsigned char _lead3_mask = 0x07;
178 static const unsigned char _lead4 = 0xF8;
179 static const unsigned char _lead4_mask = 0x03;
180 static const unsigned char _lead5 = 0xFC;
181 static const unsigned char _lead5_mask = 0x01;
182 static const unsigned char _cont = 0x80;
183 static const unsigned char _cont_mask = 0x3F;
200 typedef std::basic_string<code_point>
dstring;
209 explicit invalid_data(
const std::string& _Message ): std::runtime_error( _Message ) {
224 bool _test_begin()
const;
225 bool _test_end()
const;
275 value_type& operator[]( difference_type n )
const;
321 const value_type& operator[]( difference_type n )
const;
382 value_type& operator[]( difference_type n )
const;
415 const value_type& operator[]( difference_type n )
const;
454 #if MYGUI_IS_NATIVE_WCHAR_T
456 UString(
const wchar_t* w_str );
461 UString(
const std::wstring& wstr );
467 UString(
const std::string& str );
507 #if MYGUI_IS_NATIVE_WCHAR_T
509 void push_back(
wchar_t val );
517 void push_back(
char val );
527 const std::string& asUTF8()
const;
529 const char* asUTF8_c_str()
const;
535 const std::wstring& asWStr()
const;
537 const wchar_t* asWStr_c_str()
const;
605 UString& assign(
const std::wstring& wstr );
606 #if MYGUI_IS_NATIVE_WCHAR_T
608 UString& assign(
const wchar_t* w_str );
613 UString& assign(
const std::string& str );
615 UString& assign(
const char* c_str );
636 #if MYGUI_IS_NATIVE_WCHAR_T
660 mData.
insert( index, str );
664 UString& insert( size_type index1,
const UString& str, size_type index2, size_type num );
666 void insert( iterator i, iterator start, iterator end );
668 UString& insert( size_type index,
const code_point* str, size_type num );
669 #if MYGUI_IS_NATIVE_WCHAR_T
671 UString& insert( size_type index,
const wchar_t* w_str, size_type num );
674 UString& insert( size_type index,
const char* c_str, size_type num );
676 UString& insert( size_type index, size_type num, code_point ch );
677 #if MYGUI_IS_NATIVE_WCHAR_T
679 UString& insert( size_type index, size_type num,
wchar_t ch );
682 UString& insert( size_type index, size_type num,
char ch );
684 UString& insert( size_type index, size_type num, unicode_char ch );
686 void insert( iterator i, size_type num,
const code_point& ch );
687 #if MYGUI_IS_NATIVE_WCHAR_T
689 void insert( iterator i, size_type num,
const wchar_t& ch );
692 void insert( iterator i, size_type num,
const char& ch );
694 void insert( iterator i, size_type num,
const unicode_char& ch );
702 iterator erase( iterator loc );
704 iterator erase( iterator start, iterator end );
706 UString& erase( size_type index = 0, size_type num = npos );
714 UString& replace( size_type index1, size_type num1,
const UString& str );
716 UString& replace( size_type index1, size_type num1,
const UString& str, size_type num2 );
718 UString& replace( size_type index1, size_type num1,
const UString& str, size_type index2, size_type num2 );
720 UString& replace( iterator start, iterator end,
const UString& str, size_type num = npos );
722 UString& replace( size_type index, size_type num1, size_type num2, code_point ch );
724 UString& replace( iterator start, iterator end, size_type num, code_point ch );
732 int compare(
const UString& str )
const;
734 int compare(
const code_point* str )
const;
736 int compare( size_type index, size_type length,
const UString& str )
const;
738 int compare( size_type index, size_type length,
const UString& str, size_type index2, size_type length2 )
const;
740 int compare( size_type index, size_type length,
const code_point* str, size_type length2 )
const;
741 #if MYGUI_IS_NATIVE_WCHAR_T
743 int compare( size_type index, size_type length,
const wchar_t* w_str, size_type length2 )
const;
746 int compare( size_type index, size_type length,
const char* c_str, size_type length2 )
const;
755 size_type find(
const UString& str, size_type index = 0 )
const;
758 size_type find(
const code_point* cp_str, size_type index, size_type length )
const;
761 size_type find(
const char* c_str, size_type index, size_type length )
const;
762 #if MYGUI_IS_NATIVE_WCHAR_T
765 size_type find(
const wchar_t* w_str, size_type index, size_type length )
const;
769 size_type find(
char ch, size_type index = 0 )
const;
772 size_type find( code_point ch, size_type index = 0 )
const;
773 #if MYGUI_IS_NATIVE_WCHAR_T
776 size_type find(
wchar_t ch, size_type index = 0 )
const;
780 size_type find( unicode_char ch, size_type index = 0 )
const;
783 size_type rfind(
const UString& str, size_type index = 0 )
const;
785 size_type rfind(
const code_point* cp_str, size_type index, size_type num )
const;
787 size_type rfind(
const char* c_str, size_type index, size_type num )
const;
788 #if MYGUI_IS_NATIVE_WCHAR_T
790 size_type rfind(
const wchar_t* w_str, size_type index, size_type num )
const;
793 size_type rfind(
char ch, size_type index = 0 )
const;
795 size_type rfind( code_point ch, size_type index )
const;
796 #if MYGUI_IS_NATIVE_WCHAR_T
798 size_type rfind(
wchar_t ch, size_type index = 0 )
const;
801 size_type rfind( unicode_char ch, size_type index = 0 )
const;
809 size_type find_first_of(
const UString &str, size_type index = 0, size_type num = npos )
const;
811 size_type find_first_of( code_point ch, size_type index = 0 )
const;
813 size_type find_first_of(
char ch, size_type index = 0 )
const;
814 #if MYGUI_IS_NATIVE_WCHAR_T
816 size_type find_first_of(
wchar_t ch, size_type index = 0 )
const;
819 size_type find_first_of( unicode_char ch, size_type index = 0 )
const;
822 size_type find_first_not_of(
const UString& str, size_type index = 0, size_type num = npos )
const;
824 size_type find_first_not_of( code_point ch, size_type index = 0 )
const;
826 size_type find_first_not_of(
char ch, size_type index = 0 )
const;
827 #if MYGUI_IS_NATIVE_WCHAR_T
829 size_type find_first_not_of(
wchar_t ch, size_type index = 0 )
const;
832 size_type find_first_not_of( unicode_char ch, size_type index = 0 )
const;
835 size_type find_last_of(
const UString& str, size_type index = npos, size_type num = npos )
const;
837 size_type find_last_of( code_point ch, size_type index = npos )
const;
840 return find_last_of( static_cast<code_point>( ch ), index );
842 #if MYGUI_IS_NATIVE_WCHAR_T
844 size_type find_last_of(
wchar_t ch, size_type index = npos )
const;
847 size_type find_last_of( unicode_char ch, size_type index = npos )
const;
850 size_type find_last_not_of(
const UString& str, size_type index = npos, size_type num = npos )
const;
852 size_type find_last_not_of( code_point ch, size_type index = npos )
const;
854 size_type find_last_not_of(
char ch, size_type index = npos )
const;
855 #if MYGUI_IS_NATIVE_WCHAR_T
857 size_type find_last_not_of(
wchar_t ch, size_type index = npos )
const;
860 size_type find_last_not_of( unicode_char ch, size_type index = npos )
const;
882 UString& operator=( code_point ch );
885 #if MYGUI_IS_NATIVE_WCHAR_T
887 UString& operator=(
wchar_t ch );
890 UString& operator=( unicode_char ch );
892 code_point& operator[]( size_type index );
894 const code_point& operator[]( size_type index )
const;
902 operator std::string()
const;
904 operator std::wstring()
const;
912 static bool _utf16_independent_char( code_point cp );
914 static bool _utf16_surrogate_lead( code_point cp );
916 static bool _utf16_surrogate_follow( code_point cp );
918 static size_t _utf16_char_length( code_point cp );
920 static size_t _utf16_char_length( unicode_char uc );
926 static size_t _utf16_to_utf32(
const code_point in_cp[2], unicode_char& out_uc );
933 static size_t _utf32_to_utf16(
const unicode_char& in_uc, code_point out_cp[2] );
941 static bool _utf8_start_char(
unsigned char cp );
943 static size_t _utf8_char_length(
unsigned char cp );
945 static size_t _utf8_char_length( unicode_char uc );
948 static size_t _utf8_to_utf32(
const unsigned char in_cp[6], unicode_char& out_uc );
950 static size_t _utf32_to_utf8(
const unicode_char& in_uc,
unsigned char out_cp[6] );
953 static size_type _verifyUTF8(
const unsigned char* c_str );
955 static size_type _verifyUTF8(
const std::string& str );
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;
1018 #if MYGUI_IS_NATIVE_WCHAR_T
1036 #if MYGUI_IS_NATIVE_WCHAR_T
1091 inline std::ostream& operator << ( std::ostream& os,
const UString& s ) {
1096 inline std::wostream& operator << ( std::wostream& os,
const UString& s ) {
1102 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
1103 # pragma warning (pop)
1106 #endif // __MYGUI_U_STRING_H__