X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcodec.cpp;fp=source%2Fcodec.cpp;h=42315e52e9f7179540bcb5836021328f470cee2b;hp=521dfea2094c3eb2c8a0cffe96eca98c54fb4c70;hb=0ac97daad8d24f6762e1b870fec782c7aace695a;hpb=7735d609f5ecc2ae924d82c1395f028df9cfabd9 diff --git a/source/codec.cpp b/source/codec.cpp index 521dfea..42315e5 100644 --- a/source/codec.cpp +++ b/source/codec.cpp @@ -46,6 +46,14 @@ void Codec::Encoder::encode(const ustring &str, string &buf) encode_char(*i, buf); } +string Codec::Encoder::encode(const ustring &str) +{ + string buf; + encode(str, buf); + sync(buf); + return buf; +} + void Codec::Encoder::error(UnicodeChar ch, string &buf, const string &msg) { switch(err_mode) @@ -70,6 +78,13 @@ void Codec::Decoder::decode(const string &str, ustring &buf) } } +ustring Codec::Decoder::decode(const string &str) +{ + ustring buf; + decode(str, buf); + return buf; +} + UnicodeChar Codec::Decoder::error(const string &msg) { switch(err_mode) @@ -131,13 +146,21 @@ Codec *detect_codec(const string &str) else if((c&0xC0)==0xC0) { if(utf8_mb) + { is_utf8=false; + utf8_mb=0; + } else { for(utf8_mb=1; (c>>(6-utf8_mb))&1; ++utf8_mb) ; } } } + else if(utf8_mb) + { + is_utf8=false; + utf8_mb=0; + } } if(is_ascii)