Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: UTF-8 and wchar_t

Reply
Thread Tools

Re: UTF-8 and wchar_t

 
 
Ersek, Laszlo
Guest
Posts: n/a
 
      03-02-2010
In article <(E-Mail Removed)86.com>, Michal Nazarewicz <(E-Mail Removed)> writes:

> Also, what happens when I say to wprintf() a string which contains wide
> character which has no representation in current locale (ie. some funky
> unicode character where locale is set to ISO-8859-1 encoding)?


wprintf() will return a negative value [and errno will be set to EILSEQ].


> Can I somehow instruct the standard library function to print, say,
> a question mark in such situations or do I have to handle such cases by
> myself?


On a second thought, you might be better off if you converted the output
with iconv() too, from WCHAR_T to the codeset used by the current
locale.

http://www.opengroup.org/onlinepubs/...xsh/iconv.html
----v----
If iconv() encounters a character in the input buffer that is valid, but
for which an identical character does not exist in the target codeset,
iconv() performs an implementation-dependent conversion on this
character.
----^----

(You would have to test this.)

You should be able to get the codeset used by the current locale by
calling

nl_langinfo(CODESET)

http://www.opengroup.org/onlinepubs/..._langinfo.html

(Sorry for being glibc/SUSv2-specific.)

Cheers,
lacos
 
Reply With Quote
 
 
 
 
Mikko Rauhala
Guest
Posts: n/a
 
      03-03-2010
On Tue, 02 Mar 2010 21:42:07 +0100, Michal Nazarewicz <(E-Mail Removed)> wrote:
> Thanks for all the links and information. I have been considering
> iconv() but didn't notice that it can do conversion to/from wchar_t as
> well and that was my biggest concern. I'll be sure to look more into
> it.


To clarify further, it's not necessarily able to do so. The GNU
implementation does support it, but more generally, available
iconv sources/targets are implementation-defined.

> however depending on glibc may hurt me a bit as my code won't
> quite work on, say, BSD then.


Indeed I'm not sure if WCHAR_T is available for iconv there.
You can probably use GNU libiconv (under LGPL) there too if you like,
though.

(Yeah, getting Unixy, sorry about that; if one continues further,
probably better to move to comp.unix.programming)

--
Mikko Rauhala <(E-Mail Removed)> - http://www.iki.fi/mjr/blog/
The Finnish Pirate Party - http://piraattipuolue.fi/
World Transhumanist Association - http://transhumanism.org/
Singularity Institute - http://singinst.org/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting from windows wchar_t to linux wchar_t yakir22@gmail.com C++ 3 08-15-2008 09:04 AM
Portable integer type which can hold int, wchar_t, and void * JesusWaffle@gmail.com C Programming 3 05-15-2006 03:30 PM
wchar_t and wide characters jjf@bcs.org.uk C Programming 1 03-13-2006 01:16 PM
std::wstring, TCHAR, wchar_t and LPTSTR sorty C++ 4 11-25-2003 11:05 AM
string class that can convert between wchar_t and char Bren C++ 4 10-07-2003 03:24 PM



Advertisments