X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcodec.cpp;h=ae15382a5882cb8b8b7962edc84f727ec6ea8a65;hp=efc981492f18a08d766eb0c39932548adecfd8c5;hb=9da6abdcabec59f4845da256a8ad75a810ed1589;hpb=58384e355b4a78730d69243f1092e47591f2f384 diff --git a/source/codec.cpp b/source/codec.cpp index efc9814..ae15382 100644 --- a/source/codec.cpp +++ b/source/codec.cpp @@ -1,3 +1,10 @@ +/* $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" @@ -25,6 +32,7 @@ bool StringCodec::detect(const string &str) const { for(string::const_iterator i=str.begin(); i!=str.end(); ) dec->decode_char(str, i); + dec->sync(); } catch(const CodecError &) { @@ -36,6 +44,26 @@ bool StringCodec::detect(const string &str) const return result; } +void StringCodec::Encoder::error(const string &msg) +{ + switch(err_mode_) + { + case IGNORE_ERRORS: break; + case REPLACE_ERRORS: append_replacement(); break; + default: throw CodecError(msg); + } +} + +void StringCodec::Decoder::error(const string &msg) +{ + switch(err_mode_) + { + case IGNORE_ERRORS: break; + case REPLACE_ERRORS: append(0xFFFD); break; + default: throw CodecError(msg); + } +} + /** Creates a codec for the given encoding. The caller is responsible for deleting the codec when it's no longer needed.