- case 0: // ISO6397
- return iso6397[d-0xA0];
- case 1: // 8859-1 <-> unicode mapping
- return d;
- case 2: // 8859-2 -> unicode mapping
- return c88592[d-0xA0];
- case 3: // 8859-3 -> unicode mapping
- return c88593[d-0xA0];
- case 4: // 8859-2 -> unicode mapping
- return c88594[d-0xA0];
- case 5: // 8859-5 -> unicode mapping
- return c88595[d-0xA0];
- case 6: // 8859-6 -> unicode mapping
- return c88596[d-0xA0];
- case 7: // 8859-7 -> unicode mapping
- return c88597[d-0xA0];
- case 8: // 8859-8 -> unicode mapping
- return c88598[d-0xA0];
- case 9: // 8859-9 -> unicode mapping
- return c88599[d-0xA0];
- case 10:// 8859-10 -> unicode mapping
- return c885910[d-0xA0];
- case 11:// 8859-11 -> unicode mapping
- return c885911[d-0xA0];
-/* case 12:// 8859-12 -> unicode mapping // reserved for indian use..
- return c885912[d-0xA0];*/
- case 13:// 8859-13 -> unicode mapping
- return c885913[d-0xA0];
- case 14:// 8859-14 -> unicode mapping
- return c885914[d-0xA0];
- case 15:// 8859-15 -> unicode mapping
- return c885915[d-0xA0];
- case 16:// 8859-16 -> unicode mapping
- return c885916[d-0xA0];
- default:
- return d;
+ case 0: return iso6937[d-0xA0]; // ISO6937
+ case 1: return d; // 8859-1 -> unicode mapping
+ case 2: return c88592[d-0xA0]; // 8859-2 -> unicode mapping
+ case 3: return c88593[d-0xA0]; // 8859-3 -> unicode mapping
+ case 4: return c88594[d-0xA0]; // 8859-2 -> unicode mapping
+ case 5: return c88595[d-0xA0]; // 8859-5 -> unicode mapping
+ case 6: return c88596[d-0xA0]; // 8859-6 -> unicode mapping
+ case 7: return c88597[d-0xA0]; // 8859-7 -> unicode mapping
+ case 8: return c88598[d-0xA0]; // 8859-8 -> unicode mapping
+ case 9: return c88599[d-0xA0]; // 8859-9 -> unicode mapping
+ case 10: return c885910[d-0xA0]; // 8859-10 -> unicode mapping
+ case 11: return c885911[d-0xA0]; // 8859-11 -> unicode mapping
+// case 12: return c885912[d-0xA0]; // 8859-12 -> unicode mapping // reserved for indian use..
+ case 13: return c885913[d-0xA0]; // 8859-13 -> unicode mapping
+ case 14: return c885914[d-0xA0]; // 8859-14 -> unicode mapping
+ case 15: return c885915[d-0xA0]; // 8859-15 -> unicode mapping
+ case 16: return c885916[d-0xA0]; // 8859-16 -> unicode mapping
+ default: return d;
+ }
+}
+
+std::string UnicodeToUTF8(long c)
+{
+ if ( c < 0x80 ) {
+ char utf[2] = {static_cast<char>(c), 0};
+ return std::string(utf, 1);
+ }
+ else if ( c < 0x800) {
+ char utf[3] = { static_cast<char>(0xc0 | (c >> 6)), static_cast<char>(0x80 | (c & 0x3f)), 0};
+ return std::string(utf, 2);
+ }
+ else if ( c < 0x10000) {
+ char utf[4] = { static_cast<char>(0xe0 | (c >> 12)), static_cast<char>(0x80 | ((c >> 6) & 0x3f)),
+ static_cast<char>(0x80 | (c & 0x3f)), 0};
+ return std::string(utf, 3);
+ }
+ else if ( c < 0x200000) {
+ char utf[5] = { static_cast<char>(0xf0 | (c >> 18)), static_cast<char>(0x80 | ((c >> 12) & 0x3f)),
+ static_cast<char>(0x80 | ((c >> 6) & 0x3f)), static_cast<char>(0x80 | (c & 0x3f)), 0};
+ return std::string(utf, 4);