[SOLVED] CEGUI::String <-> wchar_t ?

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Pompei2
Home away from home
Home away from home
Posts: 489
Joined: Tue May 23, 2006 16:31

[SOLVED] CEGUI::String <-> wchar_t ?

Postby Pompei2 » Wed May 30, 2007 12:12

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.
Last edited by Pompei2 on Thu Jun 28, 2007 23:41, edited 3 times in total.

Kuehrli
Just popping in
Just popping in
Posts: 12
Joined: Tue May 22, 2007 14:03
Location: Linz, AT

Postby Kuehrli » Tue Jun 05, 2007 08:25

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... 8)

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!

Pompei2
Home away from home
Home away from home
Posts: 489
Joined: Tue May 23, 2006 16:31

Postby Pompei2 » Sat Jun 09, 2007 11:33

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

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*) ?

Kuehrli
Just popping in
Just popping in
Posts: 12
Joined: Tue May 22, 2007 14:03
Location: Linz, AT

Postby Kuehrli » Tue Jun 12, 2007 08:57

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*).

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.

Pompei2
Home away from home
Home away from home
Posts: 489
Joined: Tue May 23, 2006 16:31

Postby Pompei2 » Fri Jun 15, 2007 10:59

cool thank you very much.

I get my char * with unicode signs from CEGUI. I have to use it to implement chatting :)

Edit: Great, it works ! I love it, when "It just works" :P thank you !


Return to “Help”

Who is online

Users browsing this forum: No registered users and 38 guests