Distributed under the LGPL
*/
+#include "codecutils.h"
#include "iso646fi.h"
using namespace std;
+namespace {
+
+const unsigned map_size = 9;
+
+const int mapping[map_size*2]=
+{
+ 0xC4, 0x5B,
+ 0xC5, 0x5D,
+ 0xD6, 0x5C,
+ 0xDC, 0x5E,
+ 0xE4, 0x7B,
+ 0xE5, 0x7D,
+ 0xE9, 0x60,
+ 0xF6, 0x7C,
+ 0xFC, 0x7E
+};
+
+}
+
+
namespace Msp {
+namespace Codecs {
-void Iso646Fi::Encoder::encode_char(wchar_t c_)
+void Iso646Fi::Encoder::encode_char(UnicodeChar ch, string &buf)
{
- // Win32 has typedef unsigned short wchar_t
- int c=c_;
-
- if((c>=0 && c<=0x5A) || c==0x5F || (c>=0x61 && c<=0x7A))
- append(c);
- else if(c==0xC4)
- append(0x5B);
- else if(c==0xC5)
- append(0x5D);
- else if(c==0xD6)
- append(0x5C);
- else if(c==0xDC)
- append(0x5E);
- else if(c==0xE4)
- append(0x7B);
- else if(c==0xE5)
- append(0x7D);
- else if(c==0xE9)
- append(0x60);
- else if(c==0xF6)
- append(0x7C);
- else if(c==0xFC)
- append(0x7E);
+ int tch = transform_mapping_or_direct(mapping, map_size, ch, false);
+ if(tch<0 || tch>0x7F)
+ error(ch, buf, "Can't express character in ISO-646-FI");
else
- error("Can't express character in ISO-646-FI");
+ buf += tch;
}
-void Iso646Fi::Decoder::decode_char(const string &str, string::const_iterator &i)
+void Iso646Fi::Encoder::transliterate(UnicodeChar, string &buf)
+{
+ buf += '?';
+}
+
+
+UnicodeChar Iso646Fi::Decoder::decode_char(const string &str, string::const_iterator &i)
{
if(i==str.end())
- return;
-
- unsigned char c=*i++;
- if(c==0x5B)
- append(0xC4);
- else if(c==0x5C)
- append(0xD6);
- else if(c==0x5D)
- append(0xC5);
- else if(c==0x5E)
- append(0xDC);
- else if(c==0x60)
- append(0xE9);
- else if(c==0x7B)
- append(0xE4);
- else if(c==0x7C)
- append(0xF6);
- else if(c==0x7D)
- append(0xE5);
- else if(c==0x7E)
- append(0xFC);
- else if(c<=0x7F)
- append(c);
+ return error("No input");
+
+ unsigned char ch = *i;
+ int tch = (ch<=0x7F ? transform_mapping_or_direct(mapping, map_size, ch, true) : -1);
+
+ UnicodeChar result;
+ if(tch==-1)
+ result = error("Undefined ISO-646-FI character");
else
- error("Invalid ISO-646-FI string (undefined character)");
-}
+ result = tch;
+ ++i;
+ return result;
}
+
+} // namespace Codecs
+} // namespace Msp