utf8 helpers

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

utf8 helpers

Post by hendu »

http://sourceforge.net/p/irrlicht/patches/293/

Data tends to be in utf-8, platforms act natively in wchar. This is a much smaller implementation than Nalin's irrUString, yet it should be useful to many platforms.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: utf8 helpers

Post by christianclavet »

This look really interesting. Will extended characters will be stripped or converted (accented characters, etc)?

Also Irrlicht using mostly LATIN1 type fonts for display, displaying one of wchar will display correctly?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: utf8 helpers

Post by hendu »

I personally use it this way:

Data is in utf8 on disk. The TTF class takes stringw in its draw method. So on loading I convert from utf8 to wchar.

If you use bitmap fonts you need to have one with your symbols. All valid extended chars are converted.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: utf8 helpers

Post by christianclavet »

This is really nice!
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: utf8 helpers

Post by Nadro »

Patch applied into trunk.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: utf8 helpers

Post by christianclavet »

Wow Thanks! That's a great news. I'll use this version for my project now! :)
EDIT: Strange, it compile but I get a linker error.

Code: Select all

>XML_Manager.obj : error LNK2001: symbole externe non résolu "void __cdecl irr::core::utf8ToWchar(char const *,wchar_t *,unsigned __int64)" (?utf8ToWchar@core@irr@@YAXPBDPA_W_K@Z)
I'm still using MSVC Express 2008. Something is missing in the IRR project? The library compiled, but using this function with the compiled library give this error.
irrString.h should contain some link to the new function?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: utf8 helpers

Post by Nadro »

I have to add export defines to the new functions in irrString.h. I'll fix it today.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: utf8 helpers

Post by hendu »

christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: utf8 helpers

Post by christianclavet »

Thanks Hendu, I added manually the new commands and recompiled the DLL then used it again with my project and it seem to work. Compile, link. Have to check how to use the command properly now. :)

I have a crash every time I use it:

I define this:

Code: Select all

 
//xml is from irrXML
core::stringc input=xml->getAttributeValue("str");
core::stringw output=L""
core::utf8ToWchar(input.c_str(),output,input.size());
I am assuming that I would get the converted string in the output variable. But got some kind of memory allocation error that create a crash. Each time the debugger point me to the core::utf8ToWchar() command.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: utf8 helpers

Post by hendu »

You're passing a stringw where wchar_t* is expected, and you're claiming the output buffer is input.size() bytes long, when it is 2/4 bytes long. So of course it crashes trying to write N bytes to a 2/4-sized buffer ;)

Code: Select all

wchar_t out[200];
utf8ToWchar("test", out, 200);
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: utf8 helpers

Post by christianclavet »

Thanks Hendu. Now it work just fine! Got my accents back! :)
That is a great addition to Irrlicht since we can read/write strings encoded in UTF8 now!
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: utf8 helpers

Post by Nadro »

Problem with missing exports is fixed in trunk.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Post Reply