#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;
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");
}
--- /dev/null
+/* $Id$
+
+This file is part of libmspstrings
+Copyright © 2006-2007 Mikko Rasa
+Distributed under the LGPL
+*/
+
+#include "iso88591.h"
+
+using namespace std;
+
+namespace Msp {
+
+void Iso88591::Encoder::encode_char(wchar_t c_)
+{
+ // Win32 has typedef unsigned short wchar_t
+ int c=c_;
+ if(c<0 || c>0xFF)
+ error("Can't express character in Latin-1");
+ else
+ append(c);
+}
+
+void Iso88591::Decoder::decode_char(const string &str, string::const_iterator &i)
+{
+ if(i==str.end())
+ return;
+ append(static_cast<unsigned char>(*i++));
+}
+
+} // namespace Msp
--- /dev/null
+/* $Id$
+
+This file is part of libmspstrings
+Copyright © 2006-2007 Mikko Rasa
+Distributed under the LGPL
+*/
+
+#ifndef MSP_STRINGS_ISO88591_H_
+#define MSP_STRINGS_ISO88591_H_
+
+#include "codec.h"
+
+namespace Msp {
+
+class Iso88591: public StringCodec
+{
+public:
+ class Encoder: public StringCodec::Encoder
+ {
+ public:
+ Encoder(ErrorMode em=THROW_ON_ERROR): StringCodec::Encoder(em) { }
+ void encode_char(wchar_t);
+ private:
+ void append_replacement() { append(032); }
+ };
+
+ class Decoder: public StringCodec::Decoder
+ {
+ public:
+ Decoder(ErrorMode em=THROW_ON_ERROR): StringCodec::Decoder(em) { }
+ void decode_char(const std::string &, std::string::const_iterator &);
+ };
+
+ Encoder *create_encoder(ErrorMode em=THROW_ON_ERROR) const { return new Encoder(em); }
+ Decoder *create_decoder(ErrorMode em=THROW_ON_ERROR) const { return new Decoder(em); }
+};
+
+} // namespace Msp
+
+#endif
+++ /dev/null
-/* $Id$
-
-This file is part of libmspstrings
-Copyright © 2006-2007 Mikko Rasa
-Distributed under the LGPL
-*/
-
-#include "latin1.h"
-
-using namespace std;
-
-namespace Msp {
-
-void Latin1::Encoder::encode_char(wchar_t c_)
-{
- // Win32 has typedef unsigned short wchar_t
- int c=c_;
- if(c<0 || c>0xFF)
- error("Can't express character in Latin-1");
- else
- append(c);
-}
-
-void Latin1::Decoder::decode_char(const string &str, string::const_iterator &i)
-{
- if(i==str.end())
- return;
- append(static_cast<unsigned char>(*i++));
-}
-
-} // namespace Msp
+++ /dev/null
-/* $Id$
-
-This file is part of libmspstrings
-Copyright © 2006-2007 Mikko Rasa
-Distributed under the LGPL
-*/
-
-#ifndef MSP_STRINGS_LATIN1_H_
-#define MSP_STRINGS_LATIN1_H_
-
-#include "codec.h"
-
-namespace Msp {
-
-class Latin1: public StringCodec
-{
-public:
- class Encoder: public StringCodec::Encoder
- {
- public:
- Encoder(ErrorMode em=THROW_ON_ERROR): StringCodec::Encoder(em) { }
- void encode_char(wchar_t);
- private:
- void append_replacement() { append(032); }
- };
-
- class Decoder: public StringCodec::Decoder
- {
- public:
- Decoder(ErrorMode em=THROW_ON_ERROR): StringCodec::Decoder(em) { }
- void decode_char(const std::string &, std::string::const_iterator &);
- };
-
- Encoder *create_encoder(ErrorMode em=THROW_ON_ERROR) const { return new Encoder(em); }
- Decoder *create_decoder(ErrorMode em=THROW_ON_ERROR) const { return new Decoder(em); }
-};
-
-} // namespace Msp
-
-#endif
--- /dev/null
+/* $Id$
+
+This file is part of libmspstrings
+Copyright © 2006-2007 Mikko Rasa
+Distributed under the LGPL
+*/
+
+#include "windows1252.h"
+
+using namespace std;
+
+namespace {
+
+unsigned short table[32]=
+{
+ 0x20AC, 0, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
+ 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0, 0x017D, 0,
+ 0, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0, 0x017E, 0x0178
+};
+
+}
+
+namespace Msp {
+
+void Windows1252::Encoder::encode_char(wchar_t c_)
+{
+ int c=c_;
+ if((c>=0 && c<=0x7F) || (c>=0xA0 && c<=0xFF))
+ append(c);
+ else
+ {
+ unsigned i;
+ for(i=0; i<32; ++i)
+ if(table[i]==c)
+ {
+ append(c);
+ break;
+ }
+
+ if(i==32)
+ error("Can't express character in Windows-1252");
+ }
+}
+
+void Windows1252::Decoder::decode_char(const string &str, string::const_iterator &i)
+{
+ if(i==str.end())
+ return;
+ else
+ {
+ int c=static_cast<unsigned char>(*i++);
+ if(c>=0x80 && c<=0x9F)
+ {
+ c-=0x80;
+ if(table[c]==0)
+ error("Invalid Windows-1252 string (undefined character)");
+ append(table[c]);
+ }
+ else
+ append(c);
+ }
+}
+
+} // namespace Msp
--- /dev/null
+/* $Id$
+
+This file is part of libmspstrings
+Copyright © 2006-2007 Mikko Rasa
+Distributed under the LGPL
+*/
+
+#ifndef MSP_STRINGS_WINDOWS1252_H_
+#define MSP_STRINGS_WINDOWS1252_H_
+
+#include "codec.h"
+
+namespace Msp {
+
+class Windows1252: public StringCodec
+{
+public:
+ class Encoder: public StringCodec::Encoder
+ {
+ public:
+ Encoder(ErrorMode em=THROW_ON_ERROR): StringCodec::Encoder(em) { }
+ void encode_char(wchar_t);
+ private:
+ void append_replacement() { append(032); }
+ };
+
+ class Decoder: public StringCodec::Decoder
+ {
+ public:
+ Decoder(ErrorMode em=THROW_ON_ERROR): StringCodec::Decoder(em) { }
+ void decode_char(const std::string &, std::string::const_iterator &);
+ };
+
+ Encoder *create_encoder(ErrorMode em=THROW_ON_ERROR) const { return new Encoder(em); }
+ Decoder *create_decoder(ErrorMode em=THROW_ON_ERROR) const { return new Decoder(em); }
+};
+
+} // namespace Msp
+
+#endif