The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
latin1utf16.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * latin1utf16.cpp - SWFilter descendant Latin1UTF16 to convert a Latin-1
4  * character to UTF-16
5  *
6  * $Id: latin1utf16.cpp 2833 2013-06-29 06:40:28Z chrislit $
7  *
8  * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
9  * CrossWire Bible Society
10  * P. O. Box 2528
11  * Tempe, AZ 85280-2528
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU General Public License as published by the
15  * Free Software Foundation version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  */
23 
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <latin1utf16.h>
27 #include <swbuf.h>
28 
30 
32 }
33 
34 
35 char Latin1UTF16::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
36  const unsigned char *from;
37  if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering
38  return (char)-1;
39 
40 
41  SWBuf orig = text;
42  from = (const unsigned char *)orig.c_str();
43 
44  for (text = ""; *from; from++) {
45  text.setSize(text.size()+2);
46  switch (*from) {
47  case 0x80: // '€'
48  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x20AC;
49  break;
50  case 0x82: // '‚'
51  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x201A;
52  break;
53  case 0x83: // 'ƒ'
54  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x0192;
55  break;
56  case 0x84: // '„'
57  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x201E;
58  break;
59  case 0x85: // '…'
60  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2026;
61  break;
62  case 0x86: // '†'
63  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2020;
64  break;
65  case 0x87: // '‡'
66  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2021;
67  break;
68  case 0x88: // 'ˆ'
69  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x02C6;
70  break;
71  case 0x89: // '‰'
72  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2030;
73  break;
74  case 0x8A: // 'Š'
75  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x0160;
76  break;
77  case 0x8B: // '‹'
78  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2039;
79  break;
80  case 0x8C: // 'Œ'
81  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x0152;
82  break;
83  case 0x8E: // 'Ž'
84  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x017D;
85  break;
86  case 0x91: // '‘'
87  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2018;
88  break;
89  case 0x92: // '’'
90  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2019;
91  break;
92  case 0x93: // '“'
93  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x201C;
94  break;
95  case 0x94: // '”'
96  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x201D;
97  break;
98  case 0x95: // '•'
99  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2022;
100  break;
101  case 0x96: // '–'
102  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2013;
103  break;
104  case 0x97: // '—'
105  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2014;
106  break;
107  case 0x98: // '˜'
108  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x02DC;
109  break;
110  case 0x99: // '™'
111  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x2122;
112  break;
113  case 0x9A: // 'š'
114  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x0161;
115  break;
116  case 0x9B: // '›'
117  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x203A;
118  break;
119  case 0x9C: // 'œ'
120  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x0153;
121  break;
122  case 0x9E: // 'ž'
123  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x017E;
124  break;
125  case 0x9F: // 'Ÿ'
126  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) 0x0178;
127  break;
128  default:
129  *((unsigned short *)(text.getRawData()+(text.size()-2))) = (unsigned short) *from;
130  }
131  }
132  return 0;
133 }
134 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
Definition: latin1utf16.cpp:35
SWText * module
Definition: osis2mod.cpp:105
char * getRawData()
Definition: swbuf.h:379
const char * c_str() const
Definition: swbuf.h:158
unsigned long size() const
Definition: swbuf.h:185
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
void setSize(unsigned long len)
Definition: swbuf.h:255