Hi,
I'm converting my game to use only wchar_t instead of char. Is there a way to create a CEGUI::String based on a wchar_t * ? and vice-versa is there a way to create a wchar_t * based on a CEGUI::String ? please be explicit, as i know nearly nothing about unicode, i'm just reading documents about it right now.
[SOLVED] CEGUI::String <-> wchar_t ?
Moderators: CEGUI MVP, CEGUI Team
[SOLVED] CEGUI::String <-> wchar_t ?
Last edited by Pompei2 on Thu Jun 28, 2007 23:41, edited 3 times in total.
I had the same problem when trying to display a wchar_t[]. I found a solution which is kind of a hack but it works...
to get a wchar_t[] out of a CEGUI::String :
to get the wchar_t[] back into a new CEGUI::String :
What needs to be changed here of course is the constant size of the string of 20. I am sure that there is a better way to cast between utf8, utf32 and wchar_t but I could't find one until now!

to get a wchar_t[] out of a CEGUI::String :
Code: Select all
CEGUI::String str((const utf8*)"blablablablablabla!");
wchar_t* line = (wchar_t*)str.ptr();
wchar_t linearr[20];
for(int i=0; i<20; i++)
linearr[i] = *(line + 2*i);
to get the wchar_t[] back into a new CEGUI::String :
Code: Select all
CEGUI::String str2(20, (utf32)linearr[0]);
for(int i=0; i<20; i++)
{
str2.replace(i, 1, 1, (utf32)linearr[i]);
}
What needs to be changed here of course is the constant size of the string of 20. I am sure that there is a better way to cast between utf8, utf32 and wchar_t but I could't find one until now!
cool thank you very much, this is all that I needed !!
Edit: oh and ehm ....
If you got a text in an editbox, that contains unicode charachters, like
if you call getText( ).c_str( ) on it, you get some strange chars. From my experience, I see that it are the two chars öù encoded in unicode (Utf8 ?)
but then, how do you create a CEGUI::String from such a char * ??
In my example, I would like to create the string öù back again from the char *. How can I achieve this ? Is it enough to just cast the char * using (const utf8*) ?
Edit: oh and ehm ....
If you got a text in an editbox, that contains unicode charachters, like
Code: Select all
öù
if you call getText( ).c_str( ) on it, you get some strange chars. From my experience, I see that it are the two chars öù encoded in unicode (Utf8 ?)
but then, how do you create a CEGUI::String from such a char * ??
In my example, I would like to create the string öù back again from the char *. How can I achieve this ? Is it enough to just cast the char * using (const utf8*) ?
If you have unicode characters as input for a char* the characters get split up into some strange chars as you mentioned it - for example "öù" becomes "öù". But CEGUI seems to handle this well if you cast it to (const utf8*).
works well if you save your file with unicode-codepage (in VS2003 under File - Advanced Save Options) - but this shouldn't be necessary if you just handle the text with getText().c_str() and don't write the string in your code.
Code: Select all
char* test = "öù";
CEGUI::String str((const utf8*)test);
works well if you save your file with unicode-codepage (in VS2003 under File - Advanced Save Options) - but this shouldn't be necessary if you just handle the text with getText().c_str() and don't write the string in your code.
Who is online
Users browsing this forum: No registered users and 23 guests