27 #include <wx/strconv.h> 28 #include <wx/buffer.h> 46 m_s( (const char*) o.utf8_str() )
53 return wxString(
c_str(), wxConvUTF8 );
57 UTF8::operator wxString ()
const 59 return wxString( c_str(), wxConvUTF8 );
65 m_s = (
const char*) o.utf8_str();
75 unsigned ch = *aSequence;
84 const unsigned char* s = aSequence;
86 static const unsigned char utf8_len[] = {
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
104 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
105 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
106 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
109 int len = utf8_len[ *s - 0x80 ];
116 wxFAIL_MSG(
"uni_forward: invalid start byte" );
122 if( ( s[1] & 0xc0 ) != 0x80 )
125 wxFAIL_MSG(
"uni_forward: invalid continuation byte" );
130 ch = ((s[0] & 0x1f) << 6) +
131 ((s[1] & 0x3f) << 0);
137 if( (s[1] & 0xc0) != 0x80 ||
138 (s[2] & 0xc0) != 0x80 ||
139 (s[0] == 0xE0 && s[1] < 0xA0)
144 wxFAIL_MSG(
"uni_forward: invalid continuation byte" );
149 ch = ((s[0] & 0x0f) << 12) +
150 ((s[1] & 0x3f) << 6 ) +
151 ((s[2] & 0x3f) << 0 );
157 if( (s[1] & 0xc0) != 0x80 ||
158 (s[2] & 0xc0) != 0x80 ||
159 (s[3] & 0xc0) != 0x80 ||
160 (s[0] == 0xF0 && s[1] < 0x90) ||
161 (s[0] == 0xF4 && s[1] > 0x8F) )
164 wxFAIL_MSG(
"uni_forward: invalid continuation byte" );
169 ch = ((s[0] & 0x7) << 18) +
170 ((s[1] & 0x3f) << 12) +
171 ((s[2] & 0x3f) << 6 ) +
172 ((s[3] & 0x3f) << 0 );
187 int len = strlen( aString );
191 const unsigned char*
next = (
unsigned char*) aString;
192 const unsigned char* end =
next + len;
217 std::vector< char > temp( wcslen( txt ) * 4 + 1 );
218 wxConvUTF8.WC2MB( temp.data(), txt, temp.size() );
219 m_s.assign( temp.data() );
223 auto string = wxSafeConvertWX2MB( txt );
224 m_s.assign(
string );
234 m_s.operator+=( char( w_ch ) );
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
UTF8 & operator=(const wxString &o)
const char * c_str() const
bool IsUTF8(const char *aString)
Test a C string to see if it is UTF8 encoded.
UTF8 & operator+=(const UTF8 &str)
static int uni_forward(const unsigned char *aSequence, unsigned *aResult=NULL)
Advance over a single UTF8 encoded multibyte character, capturing the Unicode character as it goes,...
std::string substr(size_t pos=0, size_t len=npos) const