X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Futf8.cpp;h=030406d3abcfc84dc32fd3d73a8812746d36d41d;hb=d2118ac101602cfe2d62fb7deb6ef3fcb0fe137b;hp=0217790277a2a1b14112668552cc1675125028d6;hpb=58384e355b4a78730d69243f1092e47591f2f384;p=libs%2Fcore.git diff --git a/source/utf8.cpp b/source/utf8.cpp index 0217790..030406d 100644 --- a/source/utf8.cpp +++ b/source/utf8.cpp @@ -8,7 +8,10 @@ void Utf8::Encoder::encode_char(wchar_t c) { unsigned code=c; if(code>0x10FFFF) - throw CodecError("Can't express character in UTF-8"); + { + error("Can't express character in UTF-8"); + return; + } unsigned bytes=1; if(code>0xFFFF) @@ -43,8 +46,11 @@ void Utf8::Decoder::decode_char(const string &str, string::const_iterator &i) if(bytes==0) { if((*i&0xC0)==0x80) - throw CodecError("Invalid UTF-8 string (tail byte when expecting head)"); - + { + error("Invalid UTF-8 string (tail byte when expecting head)"); + ++i; + break; + } else if(*i&0x80) { unsigned mask=0x40; @@ -52,11 +58,20 @@ void Utf8::Decoder::decode_char(const string &str, string::const_iterator &i) ++bytes; if(bytes>3) - throw CodecError("Invalid UTF-8 string (overlong multibyte sequence)"); - - code=(*i++)&(mask-1); - if(!code) - throw CodecError("Invalid UTF-8 string (denormalized multibyte sequence)"); + { + error("Invalid UTF-8 string (overlong multibyte sequence)"); + ++i; + break; + } + else + { + code=(*i++)&(mask-1); + if(!code) + { + error("Invalid UTF-8 string (denormalized multibyte sequence)"); + break; + } + } } else { @@ -67,7 +82,11 @@ void Utf8::Decoder::decode_char(const string &str, string::const_iterator &i) else { if((*i&0xC0)!=0x80) - throw CodecError("Invalid UTF-8 string (head byte when expecting tail)"); + { + error("Invalid UTF-8 string (head byte when expecting tail)"); + ++i; + break; + } code=code<<6 | (*i++)&0x3F; --bytes; @@ -75,8 +94,9 @@ void Utf8::Decoder::decode_char(const string &str, string::const_iterator &i) if(!bytes) { if(code>0x10FFFF) - throw CodecError("Invalid UTF-8 string (character out of range)"); - append(code); + error("Invalid UTF-8 string (character out of range)"); + else + append(code); break; } } @@ -86,7 +106,15 @@ void Utf8::Decoder::decode_char(const string &str, string::const_iterator &i) void Utf8::Decoder::sync() { if(bytes) - throw CodecError("Sync in the middle of multibyte UTF-8 sequence"); + { + error("Sync in the middle of multibyte UTF-8 sequence"); + bytes=0; + } +} + +void Utf8::Decoder::reset() +{ + bytes=0; } } // namespace Msp