X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Futf8.cpp;h=dd01150803186dc68a4687668026a94e23b3dee4;hb=36f9e78ae75f5e14b132f37d249340ad3480b8ce;hp=2d0458f3254b96c69ff827c0f2e86f5a44ab220b;hpb=f47bc86e6ce900c5323e593db003c93110538268;p=libs%2Fcore.git diff --git a/source/utf8.cpp b/source/utf8.cpp index 2d0458f..dd01150 100644 --- a/source/utf8.cpp +++ b/source/utf8.cpp @@ -34,7 +34,7 @@ void Utf8::Encoder::encode_char(UnicodeChar ch, string &buf) utf[0]=0xFF<<(8-bytes) | ch>>(bytes*6-6); for(unsigned j=bytes-1; j>0; --j) { - utf[j]=0x80 | ch&0x3F; + utf[j]=0x80 | (ch&0x3F); ch>>=6; } @@ -71,22 +71,14 @@ UnicodeChar Utf8::Decoder::decode_char(const string &str, string::const_iterator UnicodeChar result=(*j++)&(mask-1); unsigned k; - for(k=1; (k>(bytes*6-6)) + result=error("Incomplete UTF-8 character"); + else if(!(result>>(bytes*5-4)) || !(result>>7)) result=error("Denormalized UTF-8 multibyte sequence"); - else if(result>0x10FFFF) + else if(result>0x10FFFF || (result>=0xD800 && result<=0xDFFF)) result=error("Invalid Unicode code point"); i=j;