25 #ifndef UTF8_TRANSFORM_INC
26 #define UTF8_TRANSFORM_INC 1
31 typedef bool ReturnType;
33 CopyUtf8ToUtf16(uint16_t *dst) : dst(dst) {}
35 inline void utf16(uint16_t c) { *dst++ = c; }
37 inline bool finish() {
return true; }
38 inline bool abort() {
return false; }
45 template<
typename Iterator,
typename Fn>
46 inline typename Fn::ReturnType
utf8::transform(Iterator it, Iterator end, Fn fn) {
47 using namespace ::utf8::impl;
49 #define UTF8_HANDLE_ERROR { \
50 if (fn.error_action() == ABORT_ON_ERROR) { \
56 unsigned byte = *it++;
61 if ((byte & 0xe0) == 0xc0) {
67 unsigned byte2 = *it++;
69 if ((byte2 & 0xc0) != 0x80)
74 fn.utf16(((byte & 0x1f) << 6) | (byte2 & 0x3f));
75 }
else if ((byte & 0xf0) == 0xe0) {
81 unsigned byte2 = *it++;
83 if ((byte2 & 0xc0) != 0x80)
86 unsigned byte3 = *it++;
88 if ((byte3 & 0xc0) != 0x80)
94 fn.utf16(((byte & 0x0f) << 12) | ((byte2 & 0x3f) << 6) | (byte3 & 0x3f));
111 #undef UTF8_HANDLE_ERROR
116 uint16_t ch1, ch2, ch3;
120 switch (((uint8_t) ch1) >> 4) {
132 return (ch1 << 6) | ch2;
141 return (ch1 << 12) | (ch2 << 6) | ch3;
145 template<
typename Utf8Iterator>
146 inline bool utf8::decode(Utf8Iterator begin, Utf8Iterator end, uint16_t *dst) {
150 #endif // UTF8_TRANSFORM_INC
uint16_t decode_char(const char *&)
Fn::ReturnType transform(Iterator begin, Iterator end, Fn)
bool decode(Utf8Iterator begin, Utf8Iterator end, uint16_t *dst)