? vcal.c Index: gsm-encoding.c =================================================================== RCS file: /cvsroot/gnokii/gnokii/common/gsm-encoding.c,v retrieving revision 1.27 diff -u -r1.27 gsm-encoding.c --- gsm-encoding.c 17 Sep 2002 18:29:38 -0000 1.27 +++ gsm-encoding.c 26 Sep 2002 09:01:34 -0000 @@ -359,27 +359,48 @@ void char_decode_unicode(unsigned char* dest, const unsigned char* src, int len) { - int i; - wchar_t wc; + int i; + unsigned char * d = dest; - for (i = 0; i < len; i++) { - wc = src[(2 * i) + 1] | (src[2 * i] << 8); - dest[i] = char_decode_uni_alphabet(wc); - } - dest[len] = 0; + for (i = 0; i < len; ) { + switch (wctomb (d + i, (src[i]) << 8 | src[i+1]) ) { + case 2: /* mulit char */ + i += 2; + break; + default: /* pass the old char */ + *(d + i) = *(src + i + 1); + d--; + i += 2; + break; + } + } + *d = 0; /* end the string */ return; } void char_encode_unicode(unsigned char* dest, const unsigned char* src, int len) { - int i; - wchar_t wc; + int i; + unsigned char * d = dest; - for (i = 0; i < len; i++) { - wc = char_decode_uni_alphabet(src[i]); - dest[i*2] = (wc >> 8) & 0xff; - dest[(i*2)+1] = wc & 0xff; - } + for (i = 0; i < len; ) { + wchar_t wc; + + switch (mbtowc (&wc, src + i, 2)){ + case 2: /* mulit char */ + *(d + i) = wc >> 8 & 0xFF; + *(d + i + 1) = wc & 0xFF; + i += 2; + break; + case 1: /* ASCII char */ + *(d + i) = 0; + d ++; + default: /* pass old char */ + d[i] = *(src + i); + i += 1; + } + } + *d = 0; /* end string */ return; }