Cast CEGUI::STRING to std::String Unicode

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

Durin
Just popping in
Just popping in
Posts: 17
Joined: Tue May 15, 2007 10:15

Cast CEGUI::STRING to std::String Unicode

Postby Durin » Sat Jun 30, 2007 12:42

Hi there,
I have to cast a CEGUI::String to a C++ std::string. The problem is the CEGUI::String is Unicode and for Example ä, ö or ü (for german text) are not showen right in the std::string. My Code is:

Code: Select all

   std::ostringstream buffer;
   buffer << editbox->getText();
   std::string check = buffer.str();


I want to get text from an editbox and save it in std::string check.
Can you give an answer how to make it right?

Durin
Just popping in
Just popping in
Posts: 17
Joined: Tue May 15, 2007 10:15

Postby Durin » Sat Jun 30, 2007 15:01

I have just seen, that cegui doesn't know german codepage.
Can i get cegui::string with german codepage?

Durin
Just popping in
Just popping in
Posts: 17
Joined: Tue May 15, 2007 10:15

Postby Durin » Mon Jul 02, 2007 06:51

I found a solution myself "cast is your friend".
Thx for help

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

Postby Pompei2 » Mon Jul 02, 2007 07:45

would be nice if you post some useful code of your solution for the other ppl that will search the same thing ;)

Durin
Just popping in
Just popping in
Posts: 17
Joined: Tue May 15, 2007 10:15

Postby Durin » Mon Jul 02, 2007 15:03

My Code is:

Code: Select all

std::string check;
   wchar_t* line = (wchar_t*)editbox->getText().ptr();

   while(*line){
      if(*line != 10) check += *line;
      line += 2;
   }

After this the CEGUI::String from the editbox is written in std::string check.
This works fine with Windows XP, but with LINUX it creates a curious string whitch is completely different from editbox->getText().
Has someone a solution for this???

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

Postby Pompei2 » Tue Jul 03, 2007 15:57

This is probably because wchar_t is two bytes on windows (which is non-standard) and four bytes on linux (which is standard), AFAIK. I have no direct solution to this, but maybe those two threads can help you:
http://www.cegui.org.uk/phpBB2/viewtopic.php?t=2627
http://www.cegui.org.uk/phpBB2/viewtopic.php?t=2610

Also remind that the default codepage on linux is not the same as on windows.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 32 guests