26#include <wx/strconv.h>
40 m_s( (const char*) o.utf8_str() )
47 return wxString(
c_str(), wxConvUTF8 );
51UTF8::operator wxString ()
const
53 return wxString( c_str(), wxConvUTF8 );
59 m_s = (
const char*) o.utf8_str();
69 unsigned ch = *aSequence;
78 const unsigned char* s = aSequence;
80 static const unsigned char utf8_len[] = {
93 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
95 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
98 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
99 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
100 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
103 int len = utf8_len[ *s - 0x80 ];
110 wxFAIL_MSG( wxS(
"uni_forward: invalid start byte" ) );
116 if( ( s[1] & 0xc0 ) != 0x80 )
119 wxFAIL_MSG( wxS(
"uni_forward: invalid continuation byte" ) );
124 ch = ((s[0] & 0x1f) << 6) +
125 ((s[1] & 0x3f) << 0);
131 if( (s[1] & 0xc0) != 0x80 ||
132 (s[2] & 0xc0) != 0x80 ||
133 (s[0] == 0xE0 && s[1] < 0xA0)
138 wxFAIL_MSG( wxS(
"uni_forward: invalid continuation byte" ) );
143 ch = ((s[0] & 0x0f) << 12) +
144 ((s[1] & 0x3f) << 6 ) +
145 ((s[2] & 0x3f) << 0 );
151 if( (s[1] & 0xc0) != 0x80 ||
152 (s[2] & 0xc0) != 0x80 ||
153 (s[3] & 0xc0) != 0x80 ||
154 (s[0] == 0xF0 && s[1] < 0x90) ||
155 (s[0] == 0xF4 && s[1] > 0x8F) )
158 wxFAIL_MSG( wxS(
"uni_forward: invalid continuation byte" ) );
163 ch = ((s[0] & 0x7) << 18) +
164 ((s[1] & 0x3f) << 12) +
165 ((s[2] & 0x3f) << 6 ) +
166 ((s[3] & 0x3f) << 0 );
181 int len = strlen( aString );
185 const unsigned char*
next = (
unsigned char*) aString;
186 const unsigned char* end =
next + len;
211 std::vector< char > temp( wcslen( txt ) * 4 + 1 );
212 wxConvUTF8.WC2MB( temp.data(), txt, temp.size() );
213 m_s.assign( temp.data() );
217 auto string = wxSafeConvertWX2MB( txt );
218 m_s.assign(
string );
229 m_s.operator+=( char( w_ch ) );
246 aStream << static_cast<const std::string&>( aRhs );
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
UTF8 & operator+=(const UTF8 &str)
std::string substr(size_t pos=0, size_t len=npos) const
static int uni_forward(const unsigned char *aSequence, unsigned *aResult=nullptr)
Advance over a single UTF8 encoded multibyte character, capturing the Unicode character as it goes,...
const char * c_str() const
UTF8 & operator=(const wxString &o)
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
bool IsUTF8(const char *aString)
Test a C string to see if it is UTF8 encoded.