3 This file is part of libmspstrings
4 Copyright © 2006-2007 Mikko Rasa
5 Distributed under the LGPL
14 void Utf8::Encoder::encode_char(wchar_t c)
19 error("Can't express character in UTF-8");
37 buf[0]=0xFF<<(8-bytes) | code>>(bytes*6-6);
38 for(unsigned j=bytes-1; j>0; --j)
40 buf[j]=0x80 | code&0x3F;
49 void Utf8::Decoder::decode_char(const string &str, string::const_iterator &i)
57 error("Invalid UTF-8 string (tail byte when expecting head)");
64 for(; *i&mask; mask>>=1)
69 error("Invalid UTF-8 string (overlong multibyte sequence)");
78 error("Invalid UTF-8 string (denormalized multibyte sequence)");
93 error("Invalid UTF-8 string (head byte when expecting tail)");
98 code=code<<6 | (*i++)&0x3F;
104 error("Invalid UTF-8 string (character out of range)");
113 void Utf8::Decoder::sync()
117 error("Sync in the middle of multibyte UTF-8 sequence");
122 void Utf8::Decoder::reset()