Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

latin1utf8.cpp

00001 /******************************************************************************
00002  *
00003  * Latin1UTF8 - SWFilter decendant to convert a Latin-1 character to UTF-8
00004  *
00005  */
00006 
00007 
00008 #include <stdlib.h>
00009 #include <stdio.h>
00010 #include <latin1utf8.h>
00011 #include <swmodule.h>
00012 
00013 Latin1UTF8::Latin1UTF8() {
00014 }
00015 
00016 
00017 char Latin1UTF8::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
00018 {
00019     unsigned char *to, *from;
00020         int len;
00021 
00022         len = strlen(text) + 1;
00023         if (len == maxlen + 1)
00024                 maxlen = (maxlen + 1) * FILTERPAD;
00025         // shift string to right of buffer
00026         if (len < maxlen) {
00027           memmove(&text[maxlen - len], text, len);
00028           from = (unsigned char*)&text[maxlen - len];
00029         }
00030         else    
00031           from = (unsigned char*)text;                                                  // -------------------------------
00032 
00033 
00034 
00035         for (to = (unsigned char*)text; *from; from++) {
00036           if (*from < 0x80) {
00037             *to++ = *from;
00038           }
00039           else if (*from < 0xc0) {
00040                 switch(*from) {
00041                 case 0x80: // '€'
00042                         *to++ = 0xe2; // 'â'
00043                         *to++ = 0x82; // '‚'
00044                         *to++ = 0xac; // '¬'
00045                         break;
00046                 case 0x82: // '‚'
00047                         *to++ = 0xe2; // 'â'
00048                         *to++ = 0x80; // '€'
00049                         *to++ = 0x9a; // 'š'
00050                         break;
00051                 case 0x83: // 'ƒ'
00052                         *to++ = 0xc6; // 'Æ'
00053                         *to++ = 0x92; // '’'
00054                         break;
00055                 case 0x84: // '„'
00056                         *to++ = 0xe2; // 'â'
00057                         *to++ = 0x80; // '€'
00058                         *to++ = 0x9e; // 'ž'
00059                         break;
00060                 case 0x85: // '…'
00061                         *to++ = 0xe2; // 'â'
00062                         *to++ = 0x80; // '€'
00063                         *to++ = 0xa6; // '¦'
00064                         break;
00065                 case 0x86: // '†'
00066                         *to++ = 0xe2; // 'â'
00067                         *to++ = 0x80; // '€'
00068                         *to++ = 0xa0; // ' '
00069                         break;
00070                 case 0x87: // '‡'
00071                         *to++ = 0xe2; // 'â'
00072                         *to++ = 0x80; // '€'
00073                         *to++ = 0xa1; // '¡'
00074                         break;
00075                 case 0x88: // 'ˆ'
00076                         *to++ = 0xcb; // 'Ë'
00077                         *to++ = 0x86; // '†'
00078                         break;
00079                 case 0x89: // '‰'
00080                         *to++ = 0xe2; // 'â'
00081                         *to++ = 0x80; // '€'
00082                         *to++ = 0xb0; // '°'
00083                         break;
00084                 case 0x8A: // 'Š'
00085                         *to++ = 0xc5; // 'Å'
00086                         *to++ = 0xa0; // ' '
00087                         break;
00088                 case 0x8B: // '‹'
00089                         *to++ = 0xe2; // 'â'
00090                         *to++ = 0x80; // '€'
00091                         *to++ = 0xb9; // '¹'
00092                         break;
00093                 case 0x8C: // 'Œ'
00094                         *to++ = 0xc5; // 'Å'
00095                         *to++ = 0x92; // '’'
00096                         break;
00097                 case 0x8E: // 'Ž'
00098                         *to++ = 0xc5; // 'Å'
00099                         *to++ = 0xbd; // '½'
00100                         break;
00101                 case 0x91: // '‘'
00102                         *to++ = 0xe2; // 'â'
00103                         *to++ = 0x80; // '€'
00104                         *to++ = 0x98; // '˜'
00105                         break;
00106                 case 0x92: // '’'
00107                         *to++ = 0xe2; // 'â'
00108                         *to++ = 0x80; // '€'
00109                         *to++ = 0x99; // '™'
00110                         break;
00111                 case 0x93: // '“'
00112                         *to++ = 0xe2; // 'â'
00113                         *to++ = 0x80; // '€'
00114                         *to++ = 0x9c; // 'œ'
00115                         break;
00116                 case 0x94: // '”'
00117                         *to++ = 0xe2; // 'â'
00118                         *to++ = 0x80; // '€'
00119                         *to++ = 0x9d; // '�'
00120                         break;
00121                 case 0x95: // '•'
00122                         *to++ = 0xe2; // 'â'
00123                         *to++ = 0x80; // '€'
00124                         *to++ = 0xa2; // '¢'
00125                         break;
00126                 case 0x96: // '–'
00127                         *to++ = 0xe2; // 'â'
00128                         *to++ = 0x80; // '€'
00129                         *to++ = 0x93; // '“'
00130                         break;
00131                 case 0x97: // '—'
00132                         *to++ = 0xe2; // 'â'
00133                         *to++ = 0x80; // '€'
00134                         *to++ = 0x94; // '”'
00135                         break;
00136                 case 0x98: // '˜'
00137                         *to++ = 0xcb; // 'Ë'
00138                         *to++ = 0x9c; // 'œ'
00139                         break;
00140                 case 0x99: // '™'
00141                         *to++ = 0xe2; // 'â'
00142                         *to++ = 0x84; // '„'
00143                         *to++ = 0xa2; // '¢'
00144                         break;
00145                 case 0x9A: // 'š'
00146                         *to++ = 0xc5; // 'Å'
00147                         *to++ = 0xa1; // '¡'
00148                         break;
00149                 case 0x9B: // '›'
00150                         *to++ = 0xe2; // 'â'
00151                         *to++ = 0x80; // '€'
00152                         *to++ = 0xba; // 'º'
00153                         break;
00154                 case 0x9C: // 'œ'
00155                         *to++ = 0xc5; // 'Å'
00156                         *to++ = 0x93; // '“'
00157                         break;
00158                 case 0x9E: // 'ž'
00159                         *to++ = 0xc5; // 'Å'
00160                         *to++ = 0xbe; // '¾'
00161                         break;
00162                 case 0x9F: // 'Ÿ'
00163                         *to++ = 0xc5; // 'Å'
00164                         *to++ = 0xb8; // '¸'
00165                         break;
00166                 default:
00167                         *to++ = 0xC2;
00168                         *to++ = *from;
00169                 }
00170           }
00171           else {
00172             *to++ = 0xC3;
00173             *to++ = (*from - 0x40);
00174           }
00175         }
00176         *to++ = 0;
00177         *to = 0;
00178         return 0;
00179 }

Generated on Thu Jun 20 22:12:59 2002 for The Sword Project by doxygen1.2.15