469,945 Members | 1,831 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,945 developers. It's quick & easy.

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

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

Jun 6 '06 #1
4 20615
ud******@gmail.com 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
Jun 6 '06 #2
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'

ud******@gmail.com 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


Jun 6 '06 #3
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'

ud******@gmail.com 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


Jun 6 '06 #4
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

Jun 6 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by ajay.sonawane | last post: by
5 posts views Thread by sarab | last post: by
4 posts views Thread by John Smith | last post: by
5 posts views Thread by tienlx | last post: by
5 posts views Thread by Neo | last post: by
reply views Thread by Bipin Mistry | last post: by
1 post views Thread by Hooyoo | last post: by
8 posts views Thread by AGRAJA | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.