summaryrefslogtreecommitdiff
path: root/src/modules/filters/latin1utf16.cpp
blob: ef272455ac9e302e957ac1dd580856ebfe2730ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/******************************************************************************
 *
 *  latin1utf16.cpp -	SWFilter descendant Latin1UTF16 to convert a Latin-1
 *			character to UTF-16
 *
 * $Id: latin1utf16.cpp 2833 2013-06-29 06:40:28Z chrislit $
 *
 * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
 *	CrossWire Bible Society
 *	P. O. Box 2528
 *	Tempe, AZ  85280-2528
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation version 2.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <latin1utf16.h>
#include <swbuf.h>

SWORD_NAMESPACE_START

Latin1UTF16::Latin1UTF16() {
}


char Latin1UTF16::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++) {
		text.setSize(text.size()+2);
	   switch (*from) {
	case 0x80: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x20AC;
		break;
	case 0x82: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x201A;
		break;
	case 0x83: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x0192;
		break;
	case 0x84: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x201E;
		break;
	case 0x85: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2026;
		break;
	case 0x86: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2020;
		break;
	case 0x87: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2021;
		break;
	case 0x88: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x02C6;
		break;
	case 0x89: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2030;
		break;
	case 0x8A: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x0160;
		break;
	case 0x8B: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2039;
		break;
	case 0x8C: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x0152;
		break;
	case 0x8E: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x017D;
		break;
	case 0x91: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2018;
		break;
	case 0x92: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2019;
		break;
	case 0x93: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x201C;
		break;
	case 0x94: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x201D;
		break;
	case 0x95: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2022;
		break;
	case 0x96: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2013;
		break;
	case 0x97: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2014;
		break;
	case 0x98: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x02DC;
		break;
	case 0x99: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2122;
		break;
	case 0x9A: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x0161;
		break;
	case 0x9B: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x203A;
		break;
	case 0x9C: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x0153;
		break;
	case 0x9E: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x017E;
		break;
	case 0x9F: // '�'
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x0178;
		break;
	   default:
		*((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) *from;
	   }
    }
    return 0;
}

SWORD_NAMESPACE_END