FIXED: accented characters are stripped

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

FIXED: accented characters are stripped

Post by christianclavet »

Hi,

I have this string (core::stringw)

Code: Select all

core::stringw allo = L"français";
Then want to send it to a GUI like this:

Code: Select all

gui->setText(allo);
This will give a compiler error. Because the types are not the same (wchar_t* versus core::stringw)

It can be quickly fixed by changing the line to this:

Code: Select all

gui->setText(allo.c_str());
This work fine, but the resulting string will appear like this:
fran ais
If I define directly as wchar_t and sent it as the proper type, it display correctly.
So I deducted that the using of .c_str(); will string every accented characters from the string.

Is there a way to do a conversion from core::stringw to wchar_t* but by preserving the accented characters?

EDIT: Found a way to have this working but really not sure about the code. The extended character are preserved using this:

Code: Select all

// Temp fix to get the extended characters not being removed inside.
 
        text::stringw = "Français"
 
    core::stringc source = text.c_str(); // Irrlicht widestrings
    char *mtext = (char *)source.c_str(); // char buffer
    wchar_t buffer[65536];  //widestring buffer (64k limit)
    mbstowcs(buffer, mtext, strlen(mtext))
    setText(buffer);
With this "Français" is displayed correctly with the accented character. I think that stringw store strings in a UTF format, and that could explain why the extended characters are stripped. As most of the GUI are using fonts based on ANSI (Latin1) theses extended characters will not display. If someone has a cleaner way to convert, would be appreciated.
Last edited by christianclavet on Mon Aug 04, 2014 2:36 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: accented characters are stripped

Post by CuteAlien »

The interpretation of such characters depends on the compiler and compiler-settings. This page seems to have move information: http://stackoverflow.com/questions/3316 ... in-unicode

I would recommend loading text-strings yourself and not keeping them in code at all. If you want to do that in a really clean way you will use stringtables for all strings which are printed out.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: FIXED: accented characters are stripped

Post by christianclavet »

Thanks CuteAlien, but the source strings come directly from IrrXML.

As you said, if I create the string like this:

Code: Select all

wchar_t* string = L"français";
The extended character is preserved.

But my source character is coming from core::stringw since it's read be irrXML;
At least the trick I've made works (tested only on windows now) even if it's ugly like hell.
Post Reply