X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fstringcodec%2Fiso885915.cpp;fp=source%2Fstringcodec%2Fiso885915.cpp;h=3eccbcf91e436105d9b0e17e4367b13df3a659fe;hp=0000000000000000000000000000000000000000;hb=b42ed73a1b241c0e93ee03c43c4584b41c549bac;hpb=5b1368cb791cab043f0435628cacbaff36e39b7b;ds=sidebyside diff --git a/source/stringcodec/iso885915.cpp b/source/stringcodec/iso885915.cpp new file mode 100644 index 0000000..3eccbcf --- /dev/null +++ b/source/stringcodec/iso885915.cpp @@ -0,0 +1,70 @@ +/* $Id$ + +This file is part of libmspstrings +Copyright © 2006-2007 Mikko Rasa +Distributed under the LGPL +*/ + +#include "codecutils.h" +#include "iso885915.h" + +using namespace std; + +namespace { + +const unsigned map_size = 8; + +const int mapping[map_size*2]= +{ + 0x0152, 0xBC, + 0x0153, 0xBD, + 0x0160, 0xA6, + 0x0161, 0xA8, + 0x0178, 0xBE, + 0x017D, 0xB4, + 0x017E, 0xB8, + 0x20AC, 0xA4 +}; + +} + + +namespace Msp { +namespace Codecs { + +void Iso885915::Encoder::encode_char(UnicodeChar ch, string &buf) +{ + int tch = transform_mapping_or_direct(mapping, map_size, ch, false); + if(tch<0 || tch>0xFF) + error(ch, buf, "Can't express character in ISO-8859-15"); + else + buf += tch; + +} + +void Iso885915::Encoder::transliterate(UnicodeChar, string &buf) +{ + buf += '?'; +} + + +UnicodeChar Iso885915::Decoder::decode_char(const string &str, string::const_iterator &i) +{ + if(i==str.end()) + return error("No input"); + + unsigned char ch = *i; + int tch = transform_mapping_or_direct(mapping, map_size, ch, true); + + UnicodeChar result; + if(tch==-1) + result = error("Undefined ISO-8859-15 character"); + else + result = tch; + + ++i; + return result; +} + +} // namespace Codecs +} // namespace Msp