15 #ifndef SERIALIZATION_UCS4_CONVERT_IMPL_HPP_INCLUDED
16 #define SERIALIZATION_UCS4_CONVERT_IMPL_HPP_INCLUDED
26 static const char*
get_name() {
return "utf8"; }
31 else if(ch < (1u << 11))
33 else if(ch < (1u << 16))
35 else if(ch < (1u << 21))
37 else if(ch < (1u << 26))
39 else if(ch < (1u << 31))
54 if (count == 1 || count > 6) {
69 template<
typename writer>
73 assert(out.can_push(count));
75 out.push(static_cast<utf8::char_t>(ch));
77 for(
int j = static_cast<int>(count) - 1; j >= 0; --j) {
78 unsigned char c = (ch >> (6 * j)) & 0x3f;
80 if(j == static_cast<int>(count) - 1) {
81 c |= 0xff << (8 -
count);
95 template<
typename iitor_t>
101 ucs4::char_t current_char =
static_cast<unsigned char>(*input);
105 current_char &= 0xFF >> (size + 1);
116 if ((*input & 0xC0) != 0x80)
119 current_char = (current_char << 6) | (static_cast<unsigned char>(*input) & 0x3F);
134 template<
typename writer>
141 assert(out.can_push(1));
142 out.push(static_cast<utf16::char_t>(ch));
146 assert(out.can_push(2));
148 assert(char20 < (1 << 20));
151 assert(lead < bit17);
152 assert(trail < bit17);
153 out.push(static_cast<utf16::char_t>(lead));
154 out.push(static_cast<utf16::char_t>(trail));
158 template<
typename iitor_t>
166 assert(input != end);
170 if(type == type_trail)
175 else if(type == type_lead)
182 if((*input & type_filter) != type_trail)
186 current_char &= last10;
188 current_char += (*input & last10);
189 current_char += 0x10000;
199 template<
typename writer>
202 assert(out.can_push(1));
206 template<
typename iitor_t>
209 assert(input != end);
216 template<
typename T_CHAR>
static const char * get_name()
static const char * get_name()
static ucs4::char_t read(iitor_t &input, const iitor_t &end)
static size_t byte_size_from_ucs4_codepoint(ucs4::char_t ch)
unsigned int count_leading_ones(N n)
Returns the quantity of leading 1 bits in n — i.e., the quantity of bits in n, minus the 1-based bit...
static void write(writer out, ucs4::char_t ch)
GLuint GLuint GLsizei GLenum type
GLenum GLenum GLenum input
static ucs4::char_t read(iitor_t &input, const iitor_t &end)
static void write(writer out, ucs4::char_t ch)
Templates and utility-routines for strings and numbers.
GLuint GLuint GLsizei count
static const char * get_name()
static int byte_size_from_utf8_first(utf8::char_t ch)
Functions for converting Unicode wide-char strings to UTF-8 encoded strings, back and forth...
Thrown by operations encountering invalid UTF-8 data.
static ucs4::char_t read(iitor_t &input, const iitor_t &end)
Reads a UCS-4 character from a UTF-8 stream.
static int writer(lua_State *L, const void *b, size_t size, void *B)
static void write(writer out, ucs4::char_t ch)
Writes a UCS-4 character to a UTF-8 stream.