/[winpt]/trunk/Src/wptUTF8.cpp
ViewVC logotype

Contents of /trunk/Src/wptUTF8.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 36 - (show annotations)
Thu Oct 27 15:25:13 2005 UTC (19 years, 4 months ago) by werner
File size: 22021 byte(s)
First set of changes to use autotools for building.
1 /* wptUTF8.cpp - UTF8 conversation
2 * Copyright (C) 1994, 1998-2001 Free Software Foundation, Inc.
3 * Copyright (C) 2002, 2004 Timo Schulz
4 *
5 * This file is part of WinPT.
6 *
7 * WinPT is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * WinPT is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with WinPT; if not, write to the Free Software Foundation,
19 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <windows.h>
27 #include <windows.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <ctype.h>
32
33 #include "wptTypes.h"
34 #include "wptErrors.h"
35
36 static u16 koi8_unicode[128] = {
37 0x2500,0x2502,0x250c,0x2510,0x2514,0x2518,0x251c,0x2524,
38 0x252c,0x2534,0x253c,0x2580,0x2584,0x2588,0x258c,0x2590,
39 0x2591,0x2592,0x2593,0x2320,0x25a0,0x2219,0x221a,0x2248,
40 0x2264,0x2265,0x00a0,0x2321,0x00b0,0x00b2,0x00b7,0x00f7,
41 0x2550,0x2551,0x2552,0x0451,0x2553,0x2554,0x2555,0x2556,
42 0x2557,0x2558,0x2559,0x255a,0x255b,0x255c,0x255d,0x255e,
43 0x255f,0x2560,0x2561,0x0401,0x2562,0x2563,0x2564,0x2565,
44 0x2566,0x2567,0x2568,0x2569,0x256a,0x256b,0x256c,0x00a9,
45 0x044e,0x0430,0x0431,0x0446,0x0434,0x0435,0x0444,0x0433,
46 0x0445,0x0438,0x0439,0x043a,0x043b,0x043c,0x043d,0x043e,
47 0x043f,0x044f,0x0440,0x0441,0x0442,0x0443,0x0436,0x0432,
48 0x044c,0x044b,0x0437,0x0448,0x044d,0x0449,0x0447,0x044a,
49 0x042e,0x0410,0x0411,0x0426,0x0414,0x0415,0x0424,0x0413,
50 0x0425,0x0418,0x0419,0x041a,0x041b,0x041c,0x041d,0x041e,
51 0x041f,0x042f,0x0420,0x0421,0x0422,0x0423,0x0416,0x0412,
52 0x042c,0x042b,0x0417,0x0428,0x042d,0x0429,0x0427,0x042a
53 };
54
55 static u16 latin2_unicode[128] = {
56 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,
57 0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,
58 0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,
59 0x0098,0x0099,0x009A,0x009B,0x009C,0x009D,0x009E,0x009F,
60 0x00A0,0x0104,0x02D8,0x0141,0x00A4,0x013D,0x015A,0x00A7,
61 0x00A8,0x0160,0x015E,0x0164,0x0179,0x00AD,0x017D,0x017B,
62 0x00B0,0x0105,0x02DB,0x0142,0x00B4,0x013E,0x015B,0x02C7,
63 0x00B8,0x0161,0x015F,0x0165,0x017A,0x02DD,0x017E,0x017C,
64 0x0154,0x00C1,0x00C2,0x0102,0x00C4,0x0139,0x0106,0x00C7,
65 0x010C,0x00C9,0x0118,0x00CB,0x011A,0x00CD,0x00CE,0x010E,
66 0x0110,0x0143,0x0147,0x00D3,0x00D4,0x0150,0x00D6,0x00D7,
67 0x0158,0x016E,0x00DA,0x0170,0x00DC,0x00DD,0x0162,0x00DF,
68 0x0155,0x00E1,0x00E2,0x0103,0x00E4,0x013A,0x0107,0x00E7,
69 0x010D,0x00E9,0x0119,0x00EB,0x011B,0x00ED,0x00EE,0x010F,
70 0x0111,0x0144,0x0148,0x00F3,0x00F4,0x0151,0x00F6,0x00F7,
71 0x0159,0x016F,0x00FA,0x0171,0x00FC,0x00FD,0x0163,0x02D9
72 };
73
74
75 static const char *active_charset_name = "iso-8859-1";
76 static u16 *active_charset = NULL;
77 static int no_translation = 0;
78
79 static int
80 ascii_strcasecmp( const char *a, const char *b )
81 {
82 if( a == b )
83 return 0;
84
85 for (; *a && *b; a++, b++) {
86 if (*a != *b && toupper(*a) != toupper(*b))
87 break;
88 }
89
90 return *a == *b? 0 : (toupper (*a) - toupper (*b));
91 } /* ascii_strcasecmp */
92
93 int
94 set_native_charset( const char *newset )
95 {
96 if( !ascii_strcasecmp( newset, "iso-8859-1" ) ) {
97 active_charset_name = "iso-8859-1";
98 no_translation = 0;
99 active_charset = NULL;
100 }
101 else if( !ascii_strcasecmp( newset, "iso-8859-2" ) ) {
102 active_charset_name = "iso-8859-2";
103 no_translation = 0;
104 active_charset = latin2_unicode;
105 }
106 else if( !ascii_strcasecmp( newset, "koi8-r" ) ) {
107 active_charset_name = "koi8-r";
108 no_translation = 0;
109 active_charset = koi8_unicode;
110 }
111 else if( !ascii_strcasecmp (newset, "utf8" )
112 || !ascii_strcasecmp(newset, "utf-8") ) {
113 active_charset_name = "utf-8";
114 no_translation = 1;
115 active_charset = NULL;
116 }
117 else
118 return WPTERR_GENERAL;
119
120 return 0;
121 } /* set_native_charset */
122
123 const char*
124 get_native_charset( void )
125 {
126 return active_charset_name;
127 } /* get_native_charset */
128
129 /****************
130 * Convert string, which is in native encoding to UTF8 and return the
131 * new allocated UTF8 string.
132 */
133 char *
134 native_to_utf8( const char *string )
135 {
136 const byte *s;
137 char *buffer;
138 byte *p;
139 size_t length=0;
140
141 if (no_translation)
142 buffer = strdup( string );
143 else if( active_charset ) {
144 for(s=(byte*)string; *s; s++ ) {
145 length++;
146 if( *s & 0x80 )
147 length += 2; /* we may need 3 bytes */
148 }
149 buffer = (char *)malloc( length + 1 );
150 for(p=(byte *)buffer, s=(byte *)string; *s; s++ ) {
151 if( *s & 0x80 ) {
152 u16 val = active_charset[ *s & 0x7f ];
153 if( val < 0x0800 ) {
154 *p++ = 0xc0 | ( (val >> 6) & 0x1f );
155 *p++ = 0x80 | ( val & 0x3f );
156 }
157 else {
158 *p++ = 0xe0 | ( (val >> 12) & 0x0f );
159 *p++ = 0x80 | ( (val >> 6) & 0x3f );
160 *p++ = 0x80 | ( val & 0x3f );
161 }
162 }
163 else
164 *p++ = *s;
165 }
166 *p = 0;
167 }
168 else {
169 for(s=(byte*)string; *s; s++ ) {
170 length++;
171 if( *s & 0x80 )
172 length++;
173 }
174 buffer = (char*)malloc( length + 1 );
175 for(p=(byte*)buffer, s=(byte*)string; *s; s++ ) {
176 if( *s & 0x80 ) {
177 *p++ = 0xc0 | ((*s >> 6) & 3);
178 *p++ = 0x80 | ( *s & 0x3f );
179 }
180 else
181 *p++ = *s;
182 }
183 *p = 0;
184 }
185
186 return buffer;
187 } /* native_to_utf8 */
188
189 /****************
190 * Convert string, which is in UTF8 to native encoding. illegal
191 * encodings by some "\xnn" and quote all control characters. A
192 * character with value DELIM will always be quoted, it must be a
193 * vanilla ASCII character.
194 */
195 char *
196 utf8_to_native( const char *string, size_t length, int delim )
197 {
198 int nleft;
199 int i;
200 byte encbuf[8];
201 int encidx;
202 const byte *s;
203 size_t n;
204 byte *buffer = NULL, *p = NULL;
205 unsigned long val = 0;
206 size_t slen;
207 int resync = 0;
208
209 /* 1. pass (p==NULL): count the extended utf-8 characters */
210 /* 2. pass (p!=NULL): create string */
211 for( ;; ) {
212 for( slen=length, nleft=encidx=0, n=0, s=(byte*)string; slen; s++, slen-- ) {
213 if( resync ) {
214 if( !(*s < 128 || (*s >= 0xc0 && *s <= 0xfd)) ) {
215 /* still invalid */
216 if( p ) {
217 sprintf((char*)p, "\\x%02x", *s );
218 p += 4;
219 }
220 n += 4;
221 continue;
222 }
223 resync = 0;
224 }
225 if( !nleft ) {
226 if( !(*s & 0x80) ) { /* plain ascii */
227 if( *s < 0x20 || *s == 0x7f || *s == delim) {
228 n++;
229 if( p )
230 *p++ = '\\';
231 switch( *s ) {
232 case '\n': n++; if( p ) *p++ = 'n'; break;
233 case '\r': n++; if( p ) *p++ = 'r'; break;
234 case '\f': n++; if( p ) *p++ = 'f'; break;
235 case '\v': n++; if( p ) *p++ = 'v'; break;
236 case '\b': n++; if( p ) *p++ = 'b'; break;
237 case 0 : n++; if( p ) *p++ = '0'; break;
238 default:
239 n += 3;
240 if ( p ) {
241 sprintf( (char*)p, "x%02x", *s );
242 p += 3;
243 }
244 break;
245 }
246 }
247 else {
248 if( p ) *p++ = *s;
249 n++;
250 }
251 }
252 else if( (*s & 0xe0) == 0xc0 ) { /* 110x xxxx */
253 val = *s & 0x1f;
254 nleft = 1;
255 encidx = 0;
256 encbuf[encidx++] = *s;
257 }
258 else if( (*s & 0xf0) == 0xe0 ) { /* 1110 xxxx */
259 val = *s & 0x0f;
260 nleft = 2;
261 encidx = 0;
262 encbuf[encidx++] = *s;
263 }
264 else if( (*s & 0xf8) == 0xf0 ) { /* 1111 0xxx */
265 val = *s & 0x07;
266 nleft = 3;
267 encidx = 0;
268 encbuf[encidx++] = *s;
269 }
270 else if( (*s & 0xfc) == 0xf8 ) { /* 1111 10xx */
271 val = *s & 0x03;
272 nleft = 4;
273 encidx = 0;
274 encbuf[encidx++] = *s;
275 }
276 else if( (*s & 0xfe) == 0xfc ) { /* 1111 110x */
277 val = *s & 0x01;
278 nleft = 5;
279 encidx = 0;
280 encbuf[encidx++] = *s;
281 }
282 else { /* invalid encoding: print as \xnn */
283 if( p ) {
284 sprintf((char*)p, "\\x%02x", *s );
285 p += 4;
286 }
287 n += 4;
288 resync = 1;
289 }
290 }
291 else if( *s < 0x80 || *s >= 0xc0 ) { /* invalid */
292 if( p ) {
293 for(i=0; i < encidx; i++ ) {
294 sprintf((char*)p, "\\x%02x", encbuf[i] );
295 p += 4;
296 }
297 sprintf((char*)p, "\\x%02x", *s );
298 p += 4;
299 }
300 n += 4 + 4*encidx;
301 nleft = 0;
302 encidx = 0;
303 resync = 1;
304 }
305 else {
306 encbuf[encidx++] = *s;
307 val <<= 6;
308 val |= *s & 0x3f;
309 if( !--nleft ) { /* ready */
310 if (no_translation) {
311 if( p ) {
312 for(i=0; i < encidx; i++ )
313 *p++ = encbuf[i];
314 }
315 n += encidx;
316 encidx = 0;
317 }
318 else if( active_charset ) { /* table lookup */
319 for(i=0; i < 128; i++ ) {
320 if( active_charset[i] == val )
321 break;
322 }
323 if( i < 128 ) { /* we can print this one */
324 if( p ) *p++ = i+128;
325 n++;
326 }
327 else { /* we do not have a translation: print utf8 */
328 if( p ) {
329 for(i=0; i < encidx; i++ ) {
330 sprintf((char*)p, "\\x%02x", encbuf[i] );
331 p += 4;
332 }
333 }
334 n += encidx*4;
335 encidx = 0;
336 }
337 }
338 else { /* native set */
339 if( val >= 0x80 && val < 256 ) {
340 n++; /* we can simply print this character */
341 if( p ) *p++ = val;
342 }
343 else { /* we do not have a translation: print utf8 */
344 if( p ) {
345 for(i=0; i < encidx; i++ ) {
346 sprintf((char*)p, "\\x%02x", encbuf[i] );
347 p += 4;
348 }
349 }
350 n += encidx*4;
351 encidx = 0;
352 }
353 }
354 }
355
356 }
357 }
358 if( !buffer ) { /* allocate the buffer after the first pass */
359 buffer = p = (byte *)malloc( n + 1 );
360 }
361 else {
362 *p = 0; /* make a string */
363 return (char*)buffer;
364 }
365 }
366 }
367
368
369 static void
370 conv_charset (byte *string, size_t size, int what)
371 {
372 int i;
373
374 if( what == 0 ) {
375 for( i = 0; i < size; i++, string++ ) {
376 switch( *string ) {
377 case 0xa0: *string = 0xff; break; /* nobreakspace */
378 case 0xa1: *string = 0xad; break; /* exclamdown */
379 case 0xa2: *string = 0xbd; break; /* cent */
380 case 0xa3: *string = 0x9c; break; /* sterling */
381 case 0xa4: *string = 0xcf; break; /* currency */
382 case 0xa5: *string = 0xbe; break; /* yen */
383 case 0xa6: *string = 0xdd; break; /* brokenbar */
384 case 0xa7: *string = 0xf5; break; /* section */
385 case 0xa8: *string = 0xf9; break; /* diaeresis */
386 case 0xa9: *string = 0xb8; break; /* copyright */
387 case 0xaa: *string = 0xa6; break; /* ordfeminine */
388 case 0xab: *string = 0xae; break; /* guillemotleft */
389 case 0xac: *string = 0xaa; break; /* notsign */
390 case 0xad: *string = 0xf0; break; /* hyphen */
391 case 0xae: *string = 0xa9; break; /* registered */
392 case 0xaf: *string = 0xee; break; /* macron */
393 case 0xb0: *string = 0xf8; break; /* degree */
394 case 0xb1: *string = 0xf1; break; /* plusminus */
395 case 0xb2: *string = 0xfd; break; /* twosuperior */
396 case 0xb3: *string = 0xfc; break; /* threesuperior */
397 case 0xb4: *string = 0xef; break; /* acute */
398 case 0xb5: *string = 0xe6; break; /* mu */
399 case 0xb6: *string = 0xf4; break; /* paragraph */
400 case 0xb7: *string = 0xfa; break; /* periodcentered */
401 case 0xb8: *string = 0xf7; break; /* cedilla */
402 case 0xb9: *string = 0xfb; break; /* onesuperior */
403 case 0xba: *string = 0xa7; break; /* masculine */
404 case 0xbb: *string = 0xaf; break; /* guillemotright */
405 case 0xbc: *string = 0xac; break; /* onequarter */
406 case 0xbd: *string = 0xab; break; /* onehalf */
407 case 0xbe: *string = 0xf3; break; /* threequarters */
408 case 0xbf: *string = 0xa8; break; /* questiondown */
409 case 0xc0: *string = 0xb7; break; /* Agrave */
410 case 0xc1: *string = 0xb5; break; /* Aacute */
411 case 0xc2: *string = 0xb6; break; /* Acircumflex */
412 case 0xc3: *string = 0xc7; break; /* Atilde */
413 case 0xc4: *string = 0x8e; break; /* Adiaeresis */
414 case 0xc5: *string = 0x8f; break; /* Aring */
415 case 0xc6: *string = 0x92; break; /* AE */
416 case 0xc7: *string = 0x80; break; /* Ccedilla */
417 case 0xc8: *string = 0xd4; break; /* Egrave */
418 case 0xc9: *string = 0x90; break; /* Eacute */
419 case 0xca: *string = 0xd2; break; /* Ecircumflex */
420 case 0xcb: *string = 0xd3; break; /* Ediaeresis */
421 case 0xcc: *string = 0xde; break; /* Igrave */
422 case 0xcd: *string = 0xd6; break; /* Iacute */
423 case 0xce: *string = 0xd7; break; /* Icircumflex */
424 case 0xcf: *string = 0xd8; break; /* Idiaeresis */
425 case 0xd0: *string = 0xd1; break; /* Eth */
426 case 0xd1: *string = 0xa5; break; /* Ntilde */
427 case 0xd2: *string = 0xe3; break; /* Ograve */
428 case 0xd3: *string = 0xe0; break; /* Oacute */
429 case 0xd4: *string = 0xe2; break; /* Ocircumflex */
430 case 0xd5: *string = 0xe5; break; /* Otilde */
431 case 0xd6: *string = 0x99; break; /* Odiaeresis */
432 case 0xd7: *string = 0x9e; break; /* multiply */
433 case 0xd8: *string = 0x9d; break; /* Ooblique */
434 case 0xd9: *string = 0xeb; break; /* Ugrave */
435 case 0xda: *string = 0xe9; break; /* Uacute */
436 case 0xdb: *string = 0xea; break; /* Ucircumflex */
437 case 0xdc: *string = 0x9a; break; /* Udiaeresis */
438 case 0xdd: *string = 0xed; break; /* Yacute */
439 case 0xde: *string = 0xe8; break; /* Thorn */
440 case 0xdf: *string = 0xe1; break; /* ssharp */
441 case 0xe0: *string = 0x85; break; /* agrave */
442 case 0xe1: *string = 0xa0; break; /* aacute */
443 case 0xe2: *string = 0x83; break; /* acircumflex */
444 case 0xe3: *string = 0xc6; break; /* atilde */
445 case 0xe4: *string = 0x84; break; /* adiaeresis */
446 case 0xe5: *string = 0x86; break; /* aring */
447 case 0xe6: *string = 0x91; break; /* ae */
448 case 0xe7: *string = 0x87; break; /* ccedilla */
449 case 0xe8: *string = 0x8a; break; /* egrave */
450 case 0xe9: *string = 0x82; break; /* eacute */
451 case 0xea: *string = 0x88; break; /* ecircumflex */
452 case 0xeb: *string = 0x89; break; /* ediaeresis */
453 case 0xec: *string = 0x8d; break; /* igrave */
454 case 0xed: *string = 0xa1; break; /* iacute */
455 case 0xee: *string = 0x8c; break; /* icircumflex */
456 case 0xef: *string = 0x8b; break; /* idiaeresis */
457 case 0xf0: *string = 0xd0; break; /* eth */
458 case 0xf1: *string = 0xa4; break; /* ntilde */
459 case 0xf2: *string = 0x95; break; /* ograve */
460 case 0xf3: *string = 0xa2; break; /* oacute */
461 case 0xf4: *string = 0x93; break; /* ocircumflex */
462 case 0xf5: *string = 0xe4; break; /* otilde */
463 case 0xf6: *string = 0x94; break; /* odiaeresis */
464 case 0xf7: *string = 0xf6; break; /* division */
465 case 0xf8: *string = 0x9b; break; /* oslash */
466 case 0xf9: *string = 0x97; break; /* ugrave */
467 case 0xfa: *string = 0xa3; break; /* uacute */
468 case 0xfb: *string = 0x96; break; /* ucircumflex */
469 case 0xfc: *string = 0x81; break; /* udiaeresis */
470 case 0xfd: *string = 0xec; break; /* yacute */
471 case 0xfe: *string = 0xe7; break; /* thorn */
472 case 0xff: *string = 0x98; break; /* ydiaeresis */
473 default : break;
474 }
475 }
476 }
477 else {
478 for( i = 0; i < size; i++, string++ ) {
479 switch( *string ) {
480 case 0xff: *string = 0xa0; break;
481 case 0xad: *string = 0xa1; break;
482 case 0xbd: *string = 0xa2; break;
483 case 0x9c: *string = 0xa3; break;
484 case 0xcf: *string = 0xa4; break;
485 case 0xbe: *string = 0xa5; break;
486 case 0xdd: *string = 0xa6; break;
487 case 0xf5: *string = 0xa7; break;
488 case 0xf9: *string = 0xa8; break;
489 case 0xb8: *string = 0xa9; break;
490 case 0xa6: *string = 0xaa; break;
491 case 0xae: *string = 0xab; break;
492 case 0xaa: *string = 0xac; break;
493 case 0xf0: *string = 0xad; break;
494 case 0xa9: *string = 0xae; break;
495 case 0xee: *string = 0xaf; break;
496 case 0xf8: *string = 0xb0; break;
497 case 0xf1: *string = 0xb1; break;
498 case 0xfd: *string = 0xb2; break;
499 case 0xfc: *string = 0xb3; break;
500 case 0xef: *string = 0xb4; break;
501 case 0xe6: *string = 0xb5; break;
502 case 0xf4: *string = 0xb6; break;
503 case 0xfa: *string = 0xb7; break;
504 case 0xf7: *string = 0xb8; break;
505 case 0xfb: *string = 0xb9; break;
506 case 0xa7: *string = 0xba; break;
507 case 0xaf: *string = 0xbb; break;
508 case 0xac: *string = 0xbc; break;
509 case 0xab: *string = 0xbd; break;
510 case 0xf3: *string = 0xbe; break;
511 case 0xa8: *string = 0xbf; break;
512 case 0xb7: *string = 0xc0; break;
513 case 0xb5: *string = 0xc1; break;
514 case 0xb6: *string = 0xc2; break;
515 case 0xc7: *string = 0xc3; break;
516 case 0x8e: *string = 0xc4; break;
517 case 0x8f: *string = 0xc5; break;
518 case 0x92: *string = 0xc6; break;
519 case 0x80: *string = 0xc7; break;
520 case 0xd4: *string = 0xc8; break;
521 case 0x90: *string = 0xc9; break;
522 case 0xd2: *string = 0xca; break;
523 case 0xd3: *string = 0xcb; break;
524 case 0xde: *string = 0xcc; break;
525 case 0xd6: *string = 0xcd; break;
526 case 0xd7: *string = 0xce; break;
527 case 0xd8: *string = 0xcf; break;
528 case 0xd1: *string = 0xd0; break;
529 case 0xa5: *string = 0xd1; break;
530 case 0xe3: *string = 0xd2; break;
531 case 0xe0: *string = 0xd3; break;
532 case 0xe2: *string = 0xd4; break;
533 case 0xe5: *string = 0xd5; break;
534 case 0x99: *string = 0xd6; break;
535 case 0x9e: *string = 0xd7; break;
536 case 0x9d: *string = 0xd8; break;
537 case 0xeb: *string = 0xd9; break;
538 case 0xe9: *string = 0xda; break;
539 case 0xea: *string = 0xdb; break;
540 case 0x9a: *string = 0xdc; break;
541 case 0xed: *string = 0xdd; break;
542 case 0xe8: *string = 0xde; break;
543 case 0xe1: *string = 0xdf; break;
544 case 0x85: *string = 0xe0; break;
545 case 0xa0: *string = 0xe1; break;
546 case 0x83: *string = 0xe2; break;
547 case 0xc6: *string = 0xe3; break;
548 case 0x84: *string = 0xe4; break;
549 case 0x86: *string = 0xe5; break;
550 case 0x91: *string = 0xe6; break;
551 case 0x87: *string = 0xe7; break;
552 case 0x8a: *string = 0xe8; break;
553 case 0x82: *string = 0xe9; break;
554 case 0x88: *string = 0xea; break;
555 case 0x89: *string = 0xeb; break;
556 case 0x8d: *string = 0xec; break;
557 case 0xa1: *string = 0xed; break;
558 case 0x8c: *string = 0xee; break;
559 case 0x8b: *string = 0xef; break;
560 case 0xd0: *string = 0xf0; break;
561 case 0xa4: *string = 0xf1; break;
562 case 0x95: *string = 0xf2; break;
563 case 0xa2: *string = 0xf3; break;
564 case 0x93: *string = 0xf4; break;
565 case 0xe4: *string = 0xf5; break;
566 case 0x94: *string = 0xf6; break;
567 case 0xf6: *string = 0xf7; break;
568 case 0x9b: *string = 0xf8; break;
569 case 0x97: *string = 0xf9; break;
570 case 0xa3: *string = 0xfa; break;
571 case 0x96: *string = 0xfb; break;
572 case 0x81: *string = 0xfc; break;
573 case 0xec: *string = 0xfd; break;
574 case 0xe7: *string = 0xfe; break;
575 case 0x98: *string = 0xff; break;
576 default : break;
577 }
578 }
579 }
580 } /* conv_charset */
581
582
583 char *
584 utf8_to_wincp (const char * s, size_t len)
585 {
586 char * decs;
587 decs = utf8_to_native (s, len, 0);
588 conv_charset ((byte *)decs, strlen (decs), 1);
589 return decs;
590 }
591
592
593 char *
594 wincp_to_utf8 (const char * s, size_t len)
595 {
596 char * encs;
597 conv_charset ((byte *)s, len, 0);
598 encs = native_to_utf8 (s);
599 return encs;
600 }
601
602
603 int
604 is_8bit_string (const char * str)
605 {
606 size_t i;
607
608 for (i = 0; i < strlen (str); i++) {
609 if (str[i] & 0x80)
610 return -1;
611 }
612 return 0;
613 } /* is_8bit_string */

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26