3 This file is part of libmspstrings
4 Copyright © 2006-2007 Mikko Rasa
5 Distributed under the LGPL
10 #include "iso2022jp.h"
16 #include "windows1252.h"
23 bool Codec::detect(const string &str) const
25 Decoder *dec=create_decoder();
29 for(string::const_iterator i=str.begin(); i!=str.end(); )
30 dec->decode_char(str, i);
32 catch(const CodecError &)
42 void Codec::Encoder::encode(const ustring &str, string &buf)
44 for(ustring::const_iterator i=str.begin(); i!=str.end(); ++i)
48 void Codec::Encoder::error(UnicodeChar ch, string &buf, const string &msg)
53 transliterate(ch, buf);
57 throw CodecError(msg);
62 void Codec::Decoder::decode(const string &str, ustring &buf)
64 for(string::const_iterator i=str.begin(); i!=str.end();)
66 UnicodeChar c=decode_char(str, i);
72 UnicodeChar Codec::Decoder::error(const string &msg)
81 throw CodecError(msg);
85 Codec *create_codec(const string &n)
88 for(string::const_iterator i=n.begin(); i!=n.end(); ++i)
92 else if(islower(*i) || isdigit(*i))
96 if(name=="ascii") return new Ascii;
97 if(name=="iso2022jp") return new Iso2022Jp;
98 if(name=="iso646fi") return new Iso646Fi;
99 if(name=="iso88591" || name=="latin1") return new Iso88591;
100 if(name=="jisx0201") return new JisX0201;
101 if(name=="jisx0208") return new JisX0208;
102 if(name=="utf8") return new Utf8;
103 if(name=="windows1252") return new Windows1252;
104 throw InvalidParameterValue("Unknown string codec");
107 } // namespace Codecs