Page 1 of 1

Cast CEGUI::STRING to std::String Unicode

Posted: Sat Jun 30, 2007 12:42
by Durin
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?

Posted: Sat Jun 30, 2007 15:01
by Durin
I have just seen, that cegui doesn't know german codepage.
Can i get cegui::string with german codepage?

Posted: Mon Jul 02, 2007 06:51
by Durin
I found a solution myself "cast is your friend".
Thx for help

Posted: Mon Jul 02, 2007 07:45
by Pompei2
would be nice if you post some useful code of your solution for the other ppl that will search the same thing ;)

Posted: Mon Jul 02, 2007 15:03
by Durin
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???

Posted: Tue Jul 03, 2007 15:57
by Pompei2
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.