gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Patch] unicode work with gnokii.


From: Pawel Kot
Subject: Re: [Patch] unicode work with gnokii.
Date: Mon, 27 May 2002 14:11:16 +0200

Hi,

>>> address@hidden 24 May 2002 06:32:28 >>>

> Here is the patch for gnokii, without need wchat.h. Please test it.

I don't think the patch does the correct thing. Could you please write some
comments?

> -void DecodeUnicode(unsigned char* dest, const unsigned char* src, int len)
> +int  DecodeUnicode(unsigned char* dest, const unsigned char* src, int len)
>  {
>       int i;
> -     wchar_t wc;
> +     unsigned char * d = dest;
>  
> -     for (i = 0; i < len; i++) {
> -             wc = src[(2 * i) + 1] | (src[2 * i] << 8);
> -             dest[i] = DecodeWithUnicodeAlphabet(wc);
> +     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;
> +             }

Why don't you do it in DecodeWithUnicodeAlphabet()?

> -void EncodeUnicode(unsigned char* dest, const unsigned char* src, int len)
> +int  EncodeUnicode(unsigned char* dest, const unsigned char* src, int len)
>  {
>       int i;
> -     wchar_t wc;
> +     unsigned char * d = dest;
>  
> -     for (i = 0; i < len; i++) {
> -             wc = EncodeWithUnicodeAlphabet(src[i]);
> -             dest[i*2] = (wc >> 8) & 0xff;
> -             dest[(i*2)+1] = wc & 0xff;
> -     }
> -     return;
> +     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;
> +             }
> +        }

IMHO this change break the function semantics.

pkot




reply via email to

[Prev in Thread] Current Thread [Next in Thread]