X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fstringcodec%2Fcodec.cpp;h=3dc4f9a9d452efe7aef2478878d36ad3977af170;hb=93bb92bad766d269a6bac87e00020a6158531739;hp=0014847a67cebd30a12585980f466cdf7e5ea98c;hpb=b42ed73a1b241c0e93ee03c43c4584b41c549bac;p=libs%2Fcore.git diff --git a/source/stringcodec/codec.cpp b/source/stringcodec/codec.cpp index 0014847..3dc4f9a 100644 --- a/source/stringcodec/codec.cpp +++ b/source/stringcodec/codec.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspstrings -Copyright © 2006-2007 Mikko Rasa -Distributed under the LGPL -*/ - #include "ascii.h" #include "codec.h" #include "iso2022jp.h" @@ -19,21 +12,15 @@ Distributed under the LGPL using namespace std; namespace Msp { -namespace Codecs { +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; @@ -54,7 +41,7 @@ string Codec::Encoder::encode(const ustring &str) return buf; } -void Codec::Encoder::error(UnicodeChar ch, string &buf, const string &msg) +void Codec::Encoder::error(unichar ch, string &buf, const string &msg) { switch(err_mode) { @@ -72,7 +59,7 @@ 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; } @@ -85,12 +72,12 @@ ustring Codec::Decoder::decode(const string &str) return buf; } -UnicodeChar Codec::Decoder::error(const string &msg) +unichar Codec::Decoder::error(const string &msg) { switch(err_mode) { case TRANSLITERATE: - return 0xFFFE; + return 0xFFFD; case IGNORE_ERRORS: return -1; default: @@ -173,5 +160,5 @@ Codec *detect_codec(const string &str) return new Windows1252; } -} // namespace Codecs +} // namespace StringCodec } // namespace Msp