Irrlicht i18n (Unicode, FreeType, etc.)

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki

Re: Irrlicht i18n (Unicode, FreeType, etc.)

Postby christianclavet » Thu Jul 31, 2014 12:55 pm

OK. Thanks for the reply!

So if I understand correctly, when you create a ustring it should be created in UTF16 and is stored in that format.

If I have another character encoding in the string (Irrlicht bitmap font usually use ANSI-Similar to LATIN1), it will have to be converted first. The USTRING class is only to convert between UNICODE types.

I'll use google and check how others are converting LATIN1 to UNICODE (UTF16) and the reverse then.
User avatar
christianclavet
 
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA

Re: Irrlicht i18n (Unicode, FreeType, etc.)

Postby Nalin » Thu Jul 31, 2014 7:10 pm

christianclavet wrote:OK. Thanks for the reply!

So if I understand correctly, when you create a ustring it should be created in UTF16 and is stored in that format.

If I have another character encoding in the string (Irrlicht bitmap font usually use ANSI-Similar to LATIN1), it will have to be converted first. The USTRING class is only to convert between UNICODE types.

I'll use google and check how others are converting LATIN1 to UNICODE (UTF16) and the reverse then.

Your source string has to be unicode, yes. It cannot do conversions between different character maps. Just between the different encoding types of unicode (UTF8/16/32).

Also, your source string doesn't have to be UTF16. It can be UTF8 or UTF32 if you desire. ustring just converts and stores the string internally as UTF16. If you pass in a uchar16_t string, it loads it as UTF16. If you pass in uchar32_t, it loads it as UTF32. If you pass in a const char*, it attempts to find a unicode byte-order mark. If it finds one, it loads as UTF8/16/32 (whatever the BOM says it is). If no byte-order mark is found, it treats the source string as UTF8.
Nalin
 
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA

Re: Irrlicht i18n (Unicode, FreeType, etc.)

Postby MartinVee » Tue Feb 28, 2017 9:26 pm

I found a bug in the ustring16::findLastCharNotInList() method. This causes problems too in the ustring16::trim() method.

The method reads as follow :

cpp Code: Select all
 
//! Finds last position of a character not in a given list.
//! \param c A list of characters to NOT find. For example if the method should find the first occurrence of a character not 'a' or 'b', this parameter should be "ab".
//! \param count The amount of characters in the list. Usually, this should be strlen(c).
//! \return Position where the character has been found, or -1 if not found.
s32 findLastCharNotInList(const uchar32_t* const c, u32 count=1) const
{
  if (!c || !count)
    return -1;
 
  const_iterator i(end());
  --i;
 
  s32 pos = size() - 1;
  while (!i.atStart())
  {
    uchar32_t t = *i;
    u32 j;
    for (j=0; j<count; ++j)
      if (t == c[j])
        break;
 
    if (j==count)
      return pos;
    --pos;
    --i;
  }
  return -1;
}
 


Since the iterator starts at end()-minus-one and the while checks for atStart(), the loop is never executed for single-character strings. Like I said, this causes the trim() function to return an empty string.

Example :

cpp Code: Select all
 
core::ustring test(L"5");
test.trim();
bool thisShouldNotBeTrue = (test == L"");
 


I fixed it like this :

cpp Code: Select all
 
s32 findLastCharNotInList(const uchar32_t* const c, u32 count=1) const
{
  if (!c || !count)
    return -1;
 
  const_iterator i(end());
  --i;
 
  s32 pos = size() - 1;
  while (true)
  {
    uchar32_t t = *i;
    u32 j;
    for (j=0; j<count; ++j)
      if (t == c[j])
        break;
 
    if (j==count)
      return pos;
    --pos;
 
    if(i.atStart())
      break;
 
    --i;
  }
 
  return -1;
}
 
User avatar
MartinVee
 
Posts: 102
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: Irrlicht i18n (Unicode, FreeType, etc.)

Postby Nalin » Tue Feb 28, 2017 10:05 pm

MartinVee wrote:I found a bug in the ustring16::findLastCharNotInList() method. This causes problems too in the ustring16::trim() method.


Thank you for reporting it. I've applied your changes to the version of irrUString.h that I'm hosting.
Nalin
 
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA

Re: Irrlicht i18n (Unicode, FreeType, etc.)

Postby REDDemon » Wed Mar 01, 2017 1:18 pm

This is very usefull, I recently finished working on an Arabic teaching game and I understand how valuable is having working unicode and UTF-X for irrlicht.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
User avatar
REDDemon
Developer
 
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Previous

Return to Project Announcements

Who is online

Users browsing this forum: No registered users and 1 guest

cron