X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fstringcodec%2Fcodec.cpp;h=b1c05c50292295e573f307497a175ac78797a08a;hb=94ee3a1040f67d9de2e92fc34049642b08d65b3e;hp=ed54ac938b33e6fbf12e763dccd615706696468a;hpb=056dc68dfc606a2c14126a70321045d6d9f12e0e;p=libs%2Fcore.git diff --git a/source/stringcodec/codec.cpp b/source/stringcodec/codec.cpp index ed54ac9..b1c05c5 100644 --- a/source/stringcodec/codec.cpp +++ b/source/stringcodec/codec.cpp @@ -16,17 +16,11 @@ namespace StringCodec { bool Codec::detect(const string &str) const { - Decoder *dec = create_decoder(); + Decoder *dec = create_decoder(IGNORE_ERRORS); + bool result = true; - try - { - for(string::const_iterator i=str.begin(); i!=str.end(); ) - dec->decode_char(str, i); - } - catch(const CodecError &) - { - result = false; - } + for(string::const_iterator i=str.begin(); (result && i!=str.end()); ) + result = (dec->decode_char(str, i)!=-1); delete dec; @@ -47,25 +41,13 @@ string Codec::Encoder::encode(const ustring &str) return buf; } -void Codec::Encoder::error(UnicodeChar ch, string &buf, const string &msg) -{ - switch(err_mode) - { - case TRANSLITERATE: - transliterate(ch, buf); - case IGNORE_ERRORS: - break; - default: - throw CodecError(msg); - } -} void Codec::Decoder::decode(const string &str, ustring &buf) { for(string::const_iterator i=str.begin(); i!=str.end();) { - UnicodeChar c = decode_char(str, i); + unichar c = decode_char(str, i); if(c!=-1) buf += c; } @@ -78,19 +60,6 @@ ustring Codec::Decoder::decode(const string &str) return buf; } -UnicodeChar Codec::Decoder::error(const string &msg) -{ - switch(err_mode) - { - case TRANSLITERATE: - return 0xFFFE; - case IGNORE_ERRORS: - return -1; - default: - throw CodecError(msg); - } -} - Codec *create_codec(const string &n) { string name; @@ -111,7 +80,7 @@ Codec *create_codec(const string &n) if(name=="jisx0208") return new JisX0208; if(name=="utf8") return new Utf8; if(name=="windows1252" || name=="cp1252") return new Windows1252; - throw InvalidParameterValue("Unknown string codec"); + throw invalid_argument("unknown string codec"); } Codec *detect_codec(const string &str)