using namespace std;
namespace Msp {
-namespace Codecs {
+namespace StringCodec {
bool Codec::detect(const string &str) const
{
- Decoder *dec = create_decoder();
+ Decoder *dec = create_decoder(IGNORE_ERRORS);
+
bool result = true;
- try
- {
- for(string::const_iterator i=str.begin(); i!=str.end(); )
- dec->decode_char(str, i);
- }
- catch(const CodecError &)
- {
- result = false;
- }
+ for(string::const_iterator i=str.begin(); (result && i!=str.end()); )
+ result = (dec->decode_char(str, i)!=-1);
delete dec;
return buf;
}
-void Codec::Encoder::error(UnicodeChar ch, string &buf, const string &msg)
+void Codec::Encoder::error(unichar ch, string &buf, const string &msg)
{
switch(err_mode)
{
{
for(string::const_iterator i=str.begin(); i!=str.end();)
{
- UnicodeChar c = decode_char(str, i);
+ unichar c = decode_char(str, i);
if(c!=-1)
buf += c;
}
return buf;
}
-UnicodeChar Codec::Decoder::error(const string &msg)
+unichar Codec::Decoder::error(const string &msg)
{
switch(err_mode)
{
case TRANSLITERATE:
- return 0xFFFE;
+ return 0xFFFD;
case IGNORE_ERRORS:
return -1;
default:
return new Windows1252;
}
-} // namespace Codecs
+} // namespace StringCodec
} // namespace Msp