<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40045 >

Good daytime!

At least in utility/shared.c:wordwrap_string() strlen() is used to
determine number of characters in the string. This gives wrong result
on multibytes encoding.

There are several code bases for this situation.

>From (patched) Midnight Commander code:
=====
size_t mbstrlen (const char *str)
{
  if (SLsmg_Is_Unicode) {
    size_t width = 0;

    for (; *str; str++) {
      wchar_t c;
      size_t len;

      len = mbrtowc (&c, str, MB_CUR_MAX, NULL);

      if (len == (size_t)(-1) || len == (size_t)(-2)) break;

      if (len > 0) {
        int wcsize = wcwidth(c);
        width += wcsize > 0 ? wcsize : 0;
        str += len-1;
      }
    }

    return width;
  } else
    return strlen (str);
}
=====

Also there is code available at
  http://www.koders.com/c/fid4F30C99A88AEA6396B65ADED79AB7664C69E3500.aspx
and neighbours.

Q: Do we want to do something with current behavior? I consider it as
a bug, but maybe someone has another opinion.

-- 
Thanks, evyscr



_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to