10 #include "windows1252.h"
15 namespace StringCodec {
17 bool Codec::detect(const string &str) const
19 Decoder *dec = create_decoder(IGNORE_ERRORS);
22 for(string::const_iterator i=str.begin(); (result && i!=str.end()); )
23 result = (dec->decode_char(str, i)!=-1);
30 void Codec::Encoder::encode(const ustring &str, string &buf)
32 for(ustring::const_iterator i=str.begin(); i!=str.end(); ++i)
36 string Codec::Encoder::encode(const ustring &str)
46 void Codec::Decoder::decode(const string &str, ustring &buf)
48 for(string::const_iterator i=str.begin(); i!=str.end();)
50 unichar c = decode_char(str, i);
56 ustring Codec::Decoder::decode(const string &str)
63 Codec *create_codec(const string &n)
66 for(string::const_iterator i=n.begin(); i!=n.end(); ++i)
70 else if(islower(*i) || isdigit(*i))
74 if(name=="ascii") return new Ascii;
75 if(name=="iso2022jp") return new Iso2022Jp;
76 if(name=="iso646fi") return new Iso646Fi;
77 if(name=="iso88591" || name=="latin1") return new Iso88591;
78 if(name=="iso885915" || name=="latin9") return new Iso885915;
79 if(name=="jisx0201") return new JisX0201;
80 if(name=="jisx0208") return new JisX0208;
81 if(name=="utf8") return new Utf8;
82 if(name=="windows1252" || name=="cp1252") return new Windows1252;
83 throw invalid_argument("unknown string codec");
86 Codec *detect_codec(const string &str)
90 bool is_latin1 = true;
93 for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
108 else if((c&0xC0)==0xC0)
117 for(utf8_mb=1; (c>>(6-utf8_mb))&1; ++utf8_mb) ;
135 return new Windows1252;
138 } // namespace StringCodec