summaryrefslogtreecommitdiff
path: root/src/modules/filters/latin1utf8.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/filters/latin1utf8.cpp')
-rw-r--r--src/modules/filters/latin1utf8.cpp173
1 files changed, 173 insertions, 0 deletions
diff --git a/src/modules/filters/latin1utf8.cpp b/src/modules/filters/latin1utf8.cpp
new file mode 100644
index 0000000..6c0d7f1
--- /dev/null
+++ b/src/modules/filters/latin1utf8.cpp
@@ -0,0 +1,173 @@
+/******************************************************************************
+ *
+ * Latin1UTF8 - SWFilter descendant to convert a Latin-1 character to UTF-8
+ *
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <latin1utf8.h>
+#include <swmodule.h>
+
+SWORD_NAMESPACE_START
+
+Latin1UTF8::Latin1UTF8() {
+}
+
+
+char Latin1UTF8::processText(SWBuf &text, const SWKey *key, const SWModule *module)
+{
+ const unsigned char *from;
+
+ if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering
+ return (char)-1;
+
+ SWBuf orig = text;
+ from = (const unsigned char *)orig.c_str();
+
+ for (text = ""; *from; from++) {
+ if (*from < 0x80) {
+ text += *from;
+ }
+ else if (*from < 0xc0) {
+ switch(*from) {
+ case 0x80: // ''
+ text += 0xe2; // ''
+ text += 0x82; // ''
+ text += 0xac; // ''
+ break;
+ case 0x82: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0x9a; // ''
+ break;
+ case 0x83: // ''
+ text += 0xc6; // ''
+ text += 0x92; // ''
+ break;
+ case 0x84: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0x9e; // ''
+ break;
+ case 0x85: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0xa6; // ''
+ break;
+ case 0x86: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0xa0; // ''
+ break;
+ case 0x87: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0xa1; // ''
+ break;
+ case 0x88: // ''
+ text += 0xcb; // ''
+ text += 0x86; // ''
+ break;
+ case 0x89: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0xb0; // ''
+ break;
+ case 0x8A: // ''
+ text += 0xc5; // ''
+ text += 0xa0; // ''
+ break;
+ case 0x8B: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0xb9; // ''
+ break;
+ case 0x8C: // ''
+ text += 0xc5; // ''
+ text += 0x92; // ''
+ break;
+ case 0x8E: // ''
+ text += 0xc5; // ''
+ text += 0xbd; // ''
+ break;
+ case 0x91: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0x98; // ''
+ break;
+ case 0x92: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0x99; // ''
+ break;
+ case 0x93: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0x9c; // ''
+ break;
+ case 0x94: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0x9d; // ''
+ break;
+ case 0x95: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0xa2; // ''
+ break;
+ case 0x96: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0x93; // ''
+ break;
+ case 0x97: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0x94; // ''
+ break;
+ case 0x98: // ''
+ text += 0xcb; // ''
+ text += 0x9c; // ''
+ break;
+ case 0x99: // ''
+ text += 0xe2; // ''
+ text += 0x84; // ''
+ text += 0xa2; // ''
+ break;
+ case 0x9A: // ''
+ text += 0xc5; // ''
+ text += 0xa1; // ''
+ break;
+ case 0x9B: // ''
+ text += 0xe2; // ''
+ text += 0x80; // ''
+ text += 0xba; // ''
+ break;
+ case 0x9C: // ''
+ text += 0xc5; // ''
+ text += 0x93; // ''
+ break;
+ case 0x9E: // ''
+ text += 0xc5; // ''
+ text += 0xbe; // ''
+ break;
+ case 0x9F: // ''
+ text += 0xc5; // ''
+ text += 0xb8; // ''
+ break;
+ default:
+ text += 0xC2;
+ text += *from;
+ }
+ }
+ else {
+ text += 0xC3;
+ text += (*from - 0x40);
+ }
+ }
+ return 0;
+}
+
+SWORD_NAMESPACE_END