From: Mikko Rasa Date: Sun, 18 Mar 2007 17:04:45 +0000 (+0000) Subject: Added reset function for StringCodec::Decoder X-Git-Tag: strings-1.0~23 X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=commitdiff_plain;h=51b84c0c2c3abb0cf7e815c5ae259face40ac977 Added reset function for StringCodec::Decoder --- diff --git a/source/codec.h b/source/codec.h index d5ba595..5fb29db 100644 --- a/source/codec.h +++ b/source/codec.h @@ -91,11 +91,17 @@ public: { for(std::string::const_iterator i=s.begin(); i!=s.end(); ) decode_char(s, i); } /** - Ensures that all input has been processed. An exception is thrown if - this is not the case. + Ensures that all input has been processed. If this is not the case any + buffers are cleared and an exception is thrown, */ virtual void sync() { } + /** + Resets the decoder, clearing a possibly erroneus state. Does not flush + the internal buffer. + */ + virtual void reset() { } + const std::wstring &get() const { return buffer_; } unsigned size() const { return buffer_.size(); } void flush() { buffer_.clear(); } diff --git a/source/iso2022jp.cpp b/source/iso2022jp.cpp index 806dca1..ab31456 100644 --- a/source/iso2022jp.cpp +++ b/source/iso2022jp.cpp @@ -110,6 +110,12 @@ void Iso2022Jp::Decoder::sync() dec->flush(); } +void Iso2022Jp::Decoder::reset() +{ + switch_mode(ASCII); + escape=0; +} + void Iso2022Jp::Decoder::switch_mode(Mode m) { append(dec->get()); diff --git a/source/iso2022jp.h b/source/iso2022jp.h index ea5209e..8ded0d8 100644 --- a/source/iso2022jp.h +++ b/source/iso2022jp.h @@ -33,6 +33,7 @@ public: Decoder(); void decode_char(const std::string &, std::string::const_iterator &); void sync(); + void reset(); private: Mode mode; StringCodec::Decoder *dec; diff --git a/source/jisx0208.cpp b/source/jisx0208.cpp index 477ccd0..4d46f70 100644 --- a/source/jisx0208.cpp +++ b/source/jisx0208.cpp @@ -42,6 +42,10 @@ void JisX0208::Decoder::sync() throw CodecError("Sync in middle of JIS X 0208 character"); } +void JisX0208::Decoder::reset() +{ + high=0; +} wchar_t jisx0208_to_ucs(unsigned short jis) { diff --git a/source/jisx0208.h b/source/jisx0208.h index a81f578..16f8202 100644 --- a/source/jisx0208.h +++ b/source/jisx0208.h @@ -19,6 +19,7 @@ public: public: void decode_char(const std::string &, std::string::const_iterator &); void sync(); + void reset(); private: char high; }; diff --git a/source/utf8.cpp b/source/utf8.cpp index 0217790..f95ad9c 100644 --- a/source/utf8.cpp +++ b/source/utf8.cpp @@ -89,4 +89,9 @@ void Utf8::Decoder::sync() throw CodecError("Sync in the middle of multibyte UTF-8 sequence"); } +void Utf8::Decoder::reset() +{ + bytes=0; +} + } // namespace Msp diff --git a/source/utf8.h b/source/utf8.h index 18f9ae5..0475523 100644 --- a/source/utf8.h +++ b/source/utf8.h @@ -20,6 +20,7 @@ public: Decoder(): bytes(0), code(0) { } void decode_char(const std::string &, std::string::const_iterator &); void sync(); + void reset(); private: unsigned bytes; unsigned code;