7 void Utf8::Encoder::encode_char(wchar_t c)
11 throw CodecError("Can't express character in UTF-8");
27 buf[0]=0xFF<<(8-bytes) | code>>(bytes*6-6);
28 for(unsigned j=bytes-1; j>0; --j)
30 buf[j]=0x80 | code&0x3F;
39 void Utf8::Decoder::decode_char(const string &str, string::const_iterator &i)
46 throw CodecError("Invalid UTF-8 string (tail byte when expecting head)");
51 for(; *i&mask; mask>>=1)
55 throw CodecError("Invalid UTF-8 string (overlong multibyte sequence)");
59 throw CodecError("Invalid UTF-8 string (denormalized multibyte sequence)");
70 throw CodecError("Invalid UTF-8 string (head byte when expecting tail)");
72 code=code<<6 | (*i++)&0x3F;
78 throw CodecError("Invalid UTF-8 string (character out of range)");
86 void Utf8::Decoder::sync()
89 throw CodecError("Sync in the middle of multibyte UTF-8 sequence");