is there a easy way to convert std::wstring to CEGUI::String? do i have to write a conversion function?
thanks!
convert std::wstring to CEGUI::String?
Moderators: CEGUI MVP, CEGUI Team
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: convert std::wstring to CEGUI::String?
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.
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.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Re: convert std::wstring to CEGUI::String?
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
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
Re: convert std::wstring to CEGUI::String?
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.
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.
Re: convert std::wstring to CEGUI::String?
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.
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 4 guests