]> git.tdb.fi Git - libs/core.git/blobdiff - source/codec.cpp
Rename Latin1 as Iso88591
[libs/core.git] / source / codec.cpp
index efc981492f18a08d766eb0c39932548adecfd8c5..96d18c7c922ac51aaa14bbec8138b0b8090a98bd 100644 (file)
@@ -1,11 +1,19 @@
+/* $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"
 #include "iso646fi.h"
+#include "iso88591.h"
 #include "jisx0201.h"
 #include "jisx0208.h"
-#include "latin1.h"
 #include "utf8.h"
+#include "windows1252.h"
 
 using namespace std;
 
@@ -25,6 +33,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 +45,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.
@@ -54,10 +83,11 @@ StringCodec *create_codec(const string &n)
        if(name=="ascii") return new Ascii;
        if(name=="iso2022jp") return new Iso2022Jp;
        if(name=="iso646fi") return new Iso646Fi;
+       if(name=="iso88591" || name=="latin1") return new Iso88591;
        if(name=="jisx0201") return new JisX0201;
        if(name=="jisx0208") return new JisX0208;
-       if(name=="latin1") return new Latin1;
        if(name=="utf8") return new Utf8;
+       if(name=="windows1252") return new Windows1252;
        throw InvalidParameterValue("Unknown string codec");
 }