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

Contents of /trunk/Src/wptUTF8.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File size: 22426 byte(s)
WinPT initial checkin.


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26