1
/******************************************************************************
3
* unicodertf - SWFilter descendant to convert a double byte unicode file
10
#include <unicodertf.h>
14
UnicodeRTF::UnicodeRTF() {
18
char UnicodeRTF::processText(SWBuf &text, const SWKey *key, const SWModule *module)
20
const unsigned char *from;
24
unsigned char from2[7];
28
from = (const unsigned char *)orig.c_str();
30
// -------------------------------
31
for (text = ""; *from; from++) {
34
if ((*from & 128) != 128) {
38
//case: Invalid UTF-8 (illegal continuing byte in initial position)
39
if ((*from & 128) && ((*from & 64) != 64)) {
42
//case: 2+ byte codepoint
46
for (subsequent = 1; (from2[0] & 128) && (subsequent < 7); subsequent++) {
48
from2[subsequent] = from[subsequent];
49
from2[subsequent] &= 63;
51
ch |= from2[subsequent];
55
char significantFirstBits = 8 - (2+subsequent);
57
ch |= (((short)from2[0]) << (((6*subsequent)+significantFirstBits)-8));
60
utf16 = (signed short)ch;
63
sprintf(digit, "%d", utf16);
68
utf16 = (signed short)((ch - 0x10000) / 0x400 + 0xD800);
71
sprintf(digit, "%d", utf16);
74
utf16 = (signed short)((ch - 0x10000) % 0x400 + 0xDC00);
77
sprintf(digit, "%d", utf16);