Added reset function for StringCodec::Decoder
authorMikko Rasa <tdb@tdb.fi>
Sun, 18 Mar 2007 17:04:45 +0000 (17:04 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sun, 18 Mar 2007 17:04:45 +0000 (17:04 +0000)
source/codec.h
source/iso2022jp.cpp
source/iso2022jp.h
source/jisx0208.cpp
source/jisx0208.h
source/utf8.cpp
source/utf8.h

index d5ba595b3b3ee765caa574479c766c92f27281c8..5fb29db29b305577582e6ed56c58f3bda61d823c 100644 (file)
@@ -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(); }
index 806dca1d2e672958b1ebfdf62091a009c7ceaa54..ab31456245b449c861a4c69b98dab62af77d4f40 100644 (file)
@@ -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());
index ea5209e56c19d7e4157a5632685226343507aa56..8ded0d845d2c87200577351acb57ded2466c9f2d 100644 (file)
@@ -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;
index 477ccd082c4d1516fa45dde8ccdbac6d474ab85e..4d46f709f89df5f739aa7c11a6a298505f41ed45 100644 (file)
@@ -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)
 {
index a81f578108c9f933f3fdbf3ac91b16cd7e6b6baf..16f82027247c4517d32097d74bca300af1d897ca 100644 (file)
@@ -19,6 +19,7 @@ public:
        public:
                void decode_char(const std::string &, std::string::const_iterator &);
                void sync();
+               void reset();
        private:
                char high;
        };
index 0217790277a2a1b14112668552cc1675125028d6..f95ad9c27a9ea1b76b86d273432f3c74b21b7fea 100644 (file)
@@ -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
index 18f9ae58f93fa42421887422986e038c276e3abe..0475523cf52578216e9a63c4a4942ad1c18936e9 100644 (file)
@@ -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;