Um.. Kind of.

First off, when using UTF-8 locales, the wchar_t's are indeed UTF-32/UCS-4.
 (Note that the byte order in this case is native endian!  You can't use
wchar_t's over the wire, they aren't portable; they are intended for
internal use only.  (Whereas UTF-8 is always safe on the wire.)

Where it gets sticky is if you use a different locale.  For example, in
iso-8859-1 locales, the equivalent wchar_t is really just the 8-bit latin1
character, with the high order 3 bytes zero.  (On illumos wchar_t is
32-bits wide -- on Windows its only 16.)

In a GB18030 locale (or other Asian locale), the code points are all
different.  You can't just convert those to wchar_t's.

The *correct* way to convert UTF-8 data to wchar_t's is with mbtowc (and
friends).  If you're *not* in a UTF-8 locale, then its quite likely that
there is *no* valid conversion of the UTF-8 data to a wchar_t.

Programmatically, you can only convert a multibyte encoding to a wchar_t
(or vice versa) if the multibyte encoding matches the encoding scheme used
by the current locale.  That is, you can convert GB18030 multibyte strings
to wchar_t's only if you are in a locale like zh_CN.GB18030, and you can
only convert between UTF-8 and wchar_t's if your current locale is
something ending in .UTF-8.

Hopefully that helps?



On Fri, Aug 15, 2014 at 12:46 AM, Alexander Pyhalov via illumos-discuss <
[email protected]> wrote:

> Hello. On OpenIndiana (and it seems Solaris, at least it's true for my old
> SXCE server) iconv doesn't know how to make translation from WCHAR_T to
> UTF-8 ( https://www.illumos.org/issues/5089 ).
>
> When I looked at GNU libiconv, it seems that it threats WCHAR_T on Solaris
> as UCS-4. Is it correct? I mean, can I replace WCHAR_T <=> UTF-8
> conversions with UCS-4 <=> UTF-8 conversions?
> --
> Best regards,
> Alexander Pyhalov,
> system administrator of Computer Center of Southern Federal University
>
>
> -------------------------------------------
> illumos-discuss
> Archives: https://www.listbox.com/member/archive/182180/=now
> RSS Feed: https://www.listbox.com/member/archive/rss/182180/
> 22003744-9012f59c
> Modify Your Subscription: https://www.listbox.com/
> member/?&
> Powered by Listbox: http://www.listbox.com
>



-------------------------------------------
illumos-discuss
Archives: https://www.listbox.com/member/archive/182180/=now
RSS Feed: https://www.listbox.com/member/archive/rss/182180/21175430-2e6923be
Modify Your Subscription: 
https://www.listbox.com/member/?member_id=21175430&id_secret=21175430-6a77cda4
Powered by Listbox: http://www.listbox.com

Reply via email to