wish support configure for utf8 string

If you found a bug in our library or on our website, please report it in this section. In this forum you can also make concrete suggestions or feature requests.

Moderators: CEGUI MVP, CEGUI Team

PeakGao
Just popping in
Just popping in
Posts: 9
Joined: Fri Apr 21, 2006 07:04

wish support configure for utf8 string

Postby PeakGao » Fri Jul 28, 2006 06:27

In our app, our other modules use std::wstring, and compile them in UNICODE mode, we wish cegui's utf8-string support configure, so cegui may use our std::wstring...

can support?

3q!

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Fri Jul 28, 2006 07:11

Hi,

(i don't completely understand your first line, but here we go):
If you are looking for a conversion of your wstring to a CEGUI string (or at least to utf8) you can look at a piece of code from the layout editor. There we do the same for converting a wxString (wxWwidgets unicode string) into a CEGUI string:

Code: Select all

/** Converts a wxWidgets string into a CEGUI string, Unicode proof.*/
    static CEGUI::String ToCEGUIString(const wxString& str)
    {
        const wxWCharBuffer buf = wxConvLibc.cWX2WC(str.c_str());
        return CEGUI::String( (const CEGUI::utf8*)(wxConvUTF8.cWC2MB(buf.data()).data() ) );
    }


As you can see, the trick is a Wide character to Multibyte character conversion (cWC2MB). On windows, you can use the WideCharToMultiByte function. I found this thread pretty usefull after a quick glance:
http://www.experts-exchange.com/Program ... 46903.html

If this is not what you meant, just reply again please :-)

HTH!

PeakGao
Just popping in
Just popping in
Posts: 9
Joined: Fri Apr 21, 2006 07:04

Postby PeakGao » Fri Jul 28, 2006 08:08

scriptkid wrote:Hi,

(i don't completely understand your first line, but here we go):
If you are looking for a conversion of your wstring to a CEGUI string (or at least to utf8) you can look at a piece of code from the layout editor. There we do the same for converting a wxString (wxWwidgets unicode string) into a CEGUI string:

Code: Select all

/** Converts a wxWidgets string into a CEGUI string, Unicode proof.*/
    static CEGUI::String ToCEGUIString(const wxString& str)
    {
        const wxWCharBuffer buf = wxConvLibc.cWX2WC(str.c_str());
        return CEGUI::String( (const CEGUI::utf8*)(wxConvUTF8.cWC2MB(buf.data()).data() ) );
    }


As you can see, the trick is a Wide character to Multibyte character conversion (cWC2MB). On windows, you can use the WideCharToMultiByte function. I found this thread pretty usefull after a quick glance:
http://www.experts-exchange.com/Program ... 46903.html

If this is not what you meant, just reply again please :-)

HTH!



hehe...,sorry,my poor english!! chinese english! :)

You understand my meant,..., but i don't wish to convert wide string to CEGUI string, i wish to CEGUI support std::wstring directly by some condition compile, i.e.
#ifndef CEGUIString
#define CEGUIString CEGUI::String
#endif

so, i can define my string calss before include "cegui.h".

#define CEGUIString std::wstring
#include "cegui.h"

or i only modefy the marco define in the cegui.h file:
#define CEGUIString std::wstring
and, compile CEGUI, thus CEGUI use std::wstring directly, keep compatible with our modules.

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Fri Jul 28, 2006 11:55

Hi,

okay i see what you really meant now :-)

My first guess is that your idea involves slightly more then an #ifdef. You can indeed put the #ifdef in the CEGUIString.h file, thereby skipping the declaration of the String class, and then say something like:

Code: Select all

typedef std::wstring CEGUI::String;

(I'd prefer typedef over a define).

However, the Cegui String has methods which might not be available in the std::wstring, or are at least named differently.

Another idea is to inherit the Cegui string from the std::wstring, and implement the methods by calling the wstring versions, thereby not breaking any client code.

But keep in mind: i am not the author of the library, but from what i have seen of cegui so far, is that the String class is used often. Besides, i think that the reason for the Cegui String is that it's 'real' unicode, where the wstring isn't. So be very carefull with hacking it ;-)

Btw. what is your problem with a conversion? Do you have serious performance requirements or something?

Good luck :-)

PeakGao
Just popping in
Just popping in
Posts: 9
Joined: Fri Apr 21, 2006 07:04

Postby PeakGao » Tue Aug 01, 2006 10:46

thank you for your reply!! :)


Return to “Bug Reports, Suggestions, Feature Requests”

Who is online

Users browsing this forum: No registered users and 7 guests