wcstombs & mbstowcs problem

0 views
Skip to first unread message

Simon Fell

unread,
Mar 31, 2003, 2:11:52 AM3/31/03
to
The following code takes a wchar_t string, converts it to a mbcs and
then back to a wchar_t string. The resulting wchar_t string is
different, specifcally the original \xA9 character becomes \xFFA9.

wchar_t * wSrc = L"\xa9" L"12345" ;
char dest[10] ;
wchar_t wdest[10] ;
wcstombs(dest, wSrc, 10 ) ;
mbstowcs(wdest, dest, 10 ) ;
// r should be 0 but isn't
int r = wcscmp(wSrc, wdest) ;

This is using the C++ carbon toolbox stationary with CW8.3 on
OSX10.2.4

How can i round trip between mbcs and wchar_t ?

Thanks
Simon

MW Ron

unread,
Apr 1, 2003, 5:10:24 PM4/1/03
to
In article <1f6b4043.03033...@posting.google.com>,
s...@zaks.demon.co.uk (Simon Fell) wrote:

Engineering thinks if found a bug,
change mbstring.c line 217, which should be

*pwc = *s & 0x00ff; /*- mm 030401 -*/

However I tested it and it didn't work for me. If you want to give it a
shot let me know. (don't forget to rebuild the library). If it doesn't
work let us know more about what you are using, Carbon, or Mach-O etc.

Ron

--
Migrate your PowerPlant Applications to Windows
http://www.metrowerks.com/MW/Services/OEM/default.htm

Ron Liechty - MW...@metrowerks.com - http://www.metrowerks.com

Simon Fell

unread,
Apr 2, 2003, 1:25:14 PM4/2/03
to
MW Ron <mw...@metrowerks.com> wrote in message news:<mwron-0DE8DD....@enews.newsguy.com>...
>>[snip]

> Engineering thinks if found a bug,
> change mbstring.c line 217, which should be
>
> *pwc = *s & 0x00ff; /*- mm 030401 -*/
>
> However I tested it and it didn't work for me. If you want to give it a
> shot let me know. (don't forget to rebuild the library). If it doesn't
> work let us know more about what you are using, Carbon, or Mach-O etc.
>
> Ron

I doubt that would work, i ended up doing this
*pwc = *((unsigned char *)s) ;

I also found that the r versions ( wcsrtombs & mbsrtowcs ) have issues
that prevent round tripping, in that wcsrtombs generates a UTF-8
stream, but mbstrtowcs will not correctly handle an input stream
containing UTF-8.

Cheers
Simon

MW Ron

unread,
Apr 2, 2003, 5:04:58 PM4/2/03
to
In article <1f6b4043.03040...@posting.google.com>,
s...@zaks.demon.co.uk (Simon Fell) wrote:

>MW Ron <mw...@metrowerks.com> wrote in message
>news:<mwron-0DE8DD....@enews.newsguy.com>...
>>>[snip]
>> Engineering thinks if found a bug,
>> change mbstring.c line 217, which should be
>>
>> *pwc = *s & 0x00ff; /*- mm 030401 -*/
>>
>> However I tested it and it didn't work for me. If you want to give it a
>> shot let me know. (don't forget to rebuild the library). If it doesn't
>> work let us know more about what you are using, Carbon, or Mach-O etc.
>>
>> Ron
>
>I doubt that would work, i ended up doing this
>*pwc = *((unsigned char *)s) ;

It worked for me but there may be some other changes I didn't notice.
When I looked at this again today I found that the mbstring.c had
changed quite a bit more than I thought in the next release.

>I also found that the r versions ( wcsrtombs & mbsrtowcs ) have issues
>that prevent round tripping, in that wcsrtombs generates a UTF-8
>stream, but mbstrtowcs will not correctly handle an input stream
>containing UTF-8.

I'll pass this on to our engineer

Thanks,

Reply all
Reply to author
Forward
0 new messages