Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > A simple question - how to convert from UTF8 to wide char (wchar_t) on linux

Reply
Thread Tools

A simple question - how to convert from UTF8 to wide char (wchar_t) on linux

 
 
uday.sen@gmail.com
Guest
Posts: n/a
 
      06-06-2006
Hi,

I need to convert a string from UTF8 to wide character (wchar_t *). I
perform the same in windows using:

MultiByteToWideChar(CP_UTF8, 0, pInput, -1, pOutput, nLen);

However, in linux this API is not available. However, there exists
mbstowcs() API, which converts multibyte string to wide character. But
will this API convert UTF8 encoded string to wide character? Or this
API will convert *only ASCII* characters to wide characters?

There exists also iconv() API which converts characterset using a
characterset conversion descriptor returned by iconv_open(). But for
iconv_open(char *toCode, char* fromCode), what would be "toCode" and
"fromCode" value? I think "toCode" will be UTF8, but what would be
"fromCode"?


Thanks and regards,
- Uday

 
Reply With Quote
 
 
 
 
Robert Harris
Guest
Posts: n/a
 
      06-06-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> I need to convert a string from UTF8 to wide character (wchar_t *). I
> perform the same in windows using:
>
> MultiByteToWideChar(CP_UTF8, 0, pInput, -1, pOutput, nLen);
>
> However, in linux this API is not available. However, there exists
> mbstowcs() API, which converts multibyte string to wide character. But
> will this API convert UTF8 encoded string to wide character? Or this
> API will convert *only ASCII* characters to wide characters?
>
> There exists also iconv() API which converts characterset using a
> characterset conversion descriptor returned by iconv_open(). But for
> iconv_open(char *toCode, char* fromCode), what would be "toCode" and
> "fromCode" value? I think "toCode" will be UTF8, but what would be
> "fromCode"?
>
>
> Thanks and regards,
> - Uday
>

Your fromCode is UTF8 and your toCode is WCHAR_T.

Robert
 
Reply With Quote
 
 
 
 
ithink
Guest
Posts: n/a
 
      06-06-2006
You need to set tocode to "UTF-8" and fromcode to "WCHAR_T"
To get a complete list for to and from do 'iconv --list'

(E-Mail Removed) wrote:
> Hi,
>
> I need to convert a string from UTF8 to wide character (wchar_t *). I
> perform the same in windows using:
>
> MultiByteToWideChar(CP_UTF8, 0, pInput, -1, pOutput, nLen);
>
> However, in linux this API is not available. However, there exists
> mbstowcs() API, which converts multibyte string to wide character. But
> will this API convert UTF8 encoded string to wide character? Or this
> API will convert *only ASCII* characters to wide characters?
>
> There exists also iconv() API which converts characterset using a
> characterset conversion descriptor returned by iconv_open(). But for
> iconv_open(char *toCode, char* fromCode), what would be "toCode" and
> "fromCode" value? I think "toCode" will be UTF8, but what would be
> "fromCode"?
>
>
> Thanks and regards,
> - Uday


 
Reply With Quote
 
ithink
Guest
Posts: n/a
 
      06-06-2006
Oops .. sorry for my foolish swap in my previous post ..

Set fromcode to "UTF-8" and tocode to "WCHAR_T"

ithink wrote:
> You need to set tocode to "UTF-8" and fromcode to "WCHAR_T"
> To get a complete list for to and from do 'iconv --list'
>
> (E-Mail Removed) wrote:
> > Hi,
> >
> > I need to convert a string from UTF8 to wide character (wchar_t *). I
> > perform the same in windows using:
> >
> > MultiByteToWideChar(CP_UTF8, 0, pInput, -1, pOutput, nLen);
> >
> > However, in linux this API is not available. However, there exists
> > mbstowcs() API, which converts multibyte string to wide character. But
> > will this API convert UTF8 encoded string to wide character? Or this
> > API will convert *only ASCII* characters to wide characters?
> >
> > There exists also iconv() API which converts characterset using a
> > characterset conversion descriptor returned by iconv_open(). But for
> > iconv_open(char *toCode, char* fromCode), what would be "toCode" and
> > "fromCode" value? I think "toCode" will be UTF8, but what would be
> > "fromCode"?
> >
> >
> > Thanks and regards,
> > - Uday


 
Reply With Quote
 
uday.sen@gmail.com
Guest
Posts: n/a
 
      06-06-2006
Thanks a lot for your prompt help. I have following 2 questions:

1. Will "WCHAR_T" be platform independent? Going forward I plan to
deploy the piece of code on Solaris 10.
2. When converting using iconv(), how can I determine the size required
for output string? "iconv(3)" man page does not tell about anything
about it.
size_t retval = iconv(cd, pInput, wcslen(pInput), pOutput,
???);
Do I have to calculate it by myself? Or there is any platform API that
I can use for my purpose.

Thanks again,
- Uday

 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
given char* utf8, how to read unicode line by line, and output utf8 gry C++ 2 03-13-2012 04:32 AM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
char 8bit wide or 7bit wide in c++? Web Developer C++ 2 07-31-2003 08:09 AM



Advertisments