Page 1 of 1

wish support configure for utf8 string

Posted: Fri Jul 28, 2006 06:27
by PeakGao
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!

Posted: Fri Jul 28, 2006 07:11
by scriptkid
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!

Posted: Fri Jul 28, 2006 08:08
by PeakGao
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.

Posted: Fri Jul 28, 2006 11:55
by scriptkid
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 :-)

Posted: Tue Aug 01, 2006 10:46
by PeakGao
thank you for your reply!! :)