3 This file is part of libmspstrings
4 Copyright © 2006-2007 Mikko Rasa
5 Distributed under the LGPL
10 #include "iso2022jp.h"
13 #include "iso885915.h"
17 #include "windows1252.h"
24 bool Codec::detect(const string &str) const
26 Decoder *dec=create_decoder();
30 for(string::const_iterator i=str.begin(); i!=str.end(); )
31 dec->decode_char(str, i);
33 catch(const CodecError &)
43 void Codec::Encoder::encode(const ustring &str, string &buf)
45 for(ustring::const_iterator i=str.begin(); i!=str.end(); ++i)
49 void Codec::Encoder::error(UnicodeChar ch, string &buf, const string &msg)
54 transliterate(ch, buf);
58 throw CodecError(msg);
63 void Codec::Decoder::decode(const string &str, ustring &buf)
65 for(string::const_iterator i=str.begin(); i!=str.end();)
67 UnicodeChar c=decode_char(str, i);
73 UnicodeChar Codec::Decoder::error(const string &msg)
82 throw CodecError(msg);
86 Codec *create_codec(const string &n)
89 for(string::const_iterator i=n.begin(); i!=n.end(); ++i)
93 else if(islower(*i) || isdigit(*i))
97 if(name=="ascii") return new Ascii;
98 if(name=="iso2022jp") return new Iso2022Jp;
99 if(name=="iso646fi") return new Iso646Fi;
100 if(name=="iso88591" || name=="latin1") return new Iso88591;
101 if(name=="iso885915" || name=="latin9") return new Iso885915;
102 if(name=="jisx0201") return new JisX0201;
103 if(name=="jisx0208") return new JisX0208;
104 if(name=="utf8") return new Utf8;
105 if(name=="windows1252") return new Windows1252;
106 throw InvalidParameterValue("Unknown string codec");
109 } // namespace Codecs