<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
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

Reply via email to