472,328 Members | 1,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

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 21318
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ajay.sonawane | last post by:
How can I find the wheather the occurance substring is main string in wide char provided that the compasion should be case insensitive.
5
by: sarab | last post by:
Hi, I have a managed C++ app in which i need to convert String * to char *. How can i achive this?. regards -sarab
4
by: John Smith | last post by:
Hello, Suppose I have the following C# code which I want to convert to VB: for (int i = 0; i < nFieldLength; i++) Console.Write((char)...
5
by: tienlx | last post by:
Hi all, I'm have a problem that i don't know how to convert object to char in C# . Does anybody know ? Thanks.
5
by: Neo | last post by:
how convert CString to char *? regards, Mohammad Omer Nasir
0
by: Bipin Mistry | last post by:
Hello all, I an new to XML read-write, and I am using "LibXml2" to work around with XML data. I am having 2 task to do (development in c++...
1
by: Hooyoo | last post by:
I read the content from a file encoded with UTF8 like this: byte data = binaryReader.ReadBytes(file.Length); And next step, I want to transform...
1
by: vcxpert | last post by:
Hi, I want to use ExtTextOutW function without using UNICODE preprocesser defined as rest piece of my code doesn't deal with wide char... So...
8
by: AGRAJA | last post by:
how to convert unsigned to char? Ref: http://www.thescripts.com/forum/thread477545.html how do I print without the leading ffffff (yet the...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.