X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcodec.cpp;h=38ef4ab932d3a3760038f0c6f0ec4bc3bf1626f8;hp=efc981492f18a08d766eb0c39932548adecfd8c5;hb=d2118ac101602cfe2d62fb7deb6ef3fcb0fe137b;hpb=dbda1bb7f44f289c9f1c5ba9741970ac264d8e5d diff --git a/source/codec.cpp b/source/codec.cpp index efc9814..38ef4ab 100644 --- a/source/codec.cpp +++ b/source/codec.cpp @@ -25,6 +25,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 +37,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.