String woes

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
spannerman
Home away from home
Home away from home
Posts: 330
Joined: Wed Jan 12, 2005 12:06

String woes

Postby spannerman » Tue Jul 20, 2004 16:38

I constantly come across situations where I need to mix String types, usually with me ending up with string-related type cast errors.

I get things like 'const CEGUI::String' to 'CEGUI::utf8 *' errors, but mainly OGRE to CEGUI string errors like 'OGRE::String' to 'CEGUI::String' or 'CEGUI::utf8 *'

Whats the proper way to convert between all the different String types?

Also, whats the deal with all this casting constant String values to utf8? In many occasions I seem to be able to simply not do it, like when I feed a CEGUI method a OGRE::String parameter.

Cheers

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

String woes

Postby CrazyEddie » Tue Jul 20, 2004 17:30

:lol:

Well it all started of with people wanting Unicode support, discussions about how this should and should not be done, what should be input into the system, and so on... You can read this discussion on the Ogre forums.

The decision was made that string literals as such should be in the form of utf8 encoded data. Now with utf8, the ASCII characters are exactly the same, so the String constructor can take a string literal so long as it is cast to utf8*.

In unicode 'unpacked' utf32 format, the first 255 codepoints (characters) are the same as ISO-8859-1 - so these can be input via a std::string if desired.

The best way to convert between Ogre and CEGUI strings is probably to go via std::string - since both systems can use these. If you have a char* it is usually safe to cast to utf8*. To go from CEGUI::String to something else your best bet is to use String::c_str() which returns a const char*.

I know this can sometimes be a bit strange, but eventually I want the system to have full Unicode support, so needed a way from the outset to make that easier without having to break everyones code at a later date.

HTH.

User avatar
spannerman
Home away from home
Home away from home
Posts: 330
Joined: Wed Jan 12, 2005 12:06

String woes

Postby spannerman » Tue Jul 20, 2004 18:31

Yes, that does help, thanks for the explanation. c_str() seems to be what I was missing most of the time. Im back on track :)


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 5 guests