convert std::wstring to CEGUI::String?

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
thelONE
Just popping in
Just popping in
Posts: 3
Joined: Mon Jan 24, 2005 19:10
Contact:

convert std::wstring to CEGUI::String?

Postby thelONE » Sat Jul 30, 2005 09:03

is there a easy way to convert std::wstring to CEGUI::String? do i have to write a conversion function?
thanks!

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: convert std::wstring to CEGUI::String?

Postby CrazyEddie » Sat Jul 30, 2005 12:30

Short answer, no.

The very fact that there is no easy conversion highlights the reason that std::wstring was not used in the first place; it's basically non-portable.

While it's all very nice when you just access wstring itself, there are major issues when you need to do anything like conversions of the wchars - since what exactly a wchar represents is not specified. So, any conversion functions will be platform (actually, compiler) specific.

User avatar
thelONE
Just popping in
Just popping in
Posts: 3
Joined: Mon Jan 24, 2005 19:10
Contact:

Re: convert std::wstring to CEGUI::String?

Postby thelONE » Sat Jul 30, 2005 13:37

I think that is why you implement your own string class rather than use std::wstring, isn't it?

i'm using msvc7.1(do not consider cross-platform issue currently), and when i display a chinese string on hud, i may do these:

std::wstring wstr = L"昨天曼联输给一个日本球队了,不可思议。";
CEGUI::String ce_str = ENCODING_CONVERSION(wstr);
window->setText(ce_str);

that ENCODING_CONVERSION function may be a easy solution, but i really could not implement this, could you help me? thnaks a lot ;)

User avatar
gcarlton
Just can't stay away
Just can't stay away
Posts: 149
Joined: Wed Jan 12, 2005 12:06

Re: convert std::wstring to CEGUI::String?

Postby gcarlton » Sun Jul 31, 2005 06:10

Here is a group of C functions which apparently convert between utf-8, utf-16, and utf-32.
http://www.unicode.org/Public/PROGRAMS/CVTUTF

As far as I understand it, utf-16 is wchar_t, and so you should be able to convert between that and utf-8 using these functions.

User avatar
Sachin
Just popping in
Just popping in
Posts: 20
Joined: Wed Jul 06, 2005 09:42

Re: convert std::wstring to CEGUI::String?

Postby Sachin » Mon Aug 01, 2005 06:11

well i used the follwing func to convert from wstring to std::string..& an std::string is directly convertable to CEGUI::string as one of the constructors of CEGUI::string takes std::string as an argument.

string W2S( wstring wstr )
{
std::string res;
int len = wstr.length();
char* c = new char[len+1];

for ( int i=0;i<len;i++)
{
c[i] = wstr[i];
}
c[i] = 0;
res = c;
res[len]=0;

delete[] c;
return res;
}

u may wonder y so much hassle like declaring a new char array etc.......but try w/o it u will know the probs.


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 6 guests