We need(or not) strlen in utf-8?

Hello.
I need your help with issue #2575.

I made path than fix this issue.
Here is path:

[code]diff --git a/050c0d1 b/09f3336
index 050c0d1…09f3336 100644
— a/050c0d1
+++ b/09f3336
@@ -4559,15 +4559,10 @@ int game::mon_info(WINDOW *w)
for (int i = 0; i < 8; i++) {
widths[i] = strlen(dir_labels[i]);
}

  • const int row1spaces = width - (widths[7] + widths[0] + widths[1]);
  • const int row3spaces = width - (widths[5] + widths[4] + widths[3]);
    int xcoords[8];
    const int ycoords[] = { 0, 0, 1, 2, 2, 2, 1, 0 };
  • xcoords[0] = widths[7] + row1spaces / 3;
  • xcoords[1] = widths[7] - (row1spaces / 3) + row1spaces + widths[0];
  • xcoords[4] = widths[5] + row3spaces / 3;
  • xcoords[3] = widths[5] - (row3spaces / 3) + row3spaces + widths[4];
  • xcoords[2] = (xcoords[1] + xcoords[3]) / 2;
  • xcoords[0] = xcoords[4] = width / 3;
  • xcoords[1] = xcoords[3] = xcoords[2] = (width / 3) * 2;
    xcoords[5] = xcoords[6] = xcoords[7] = 0;
    for (int i = 0; i < 8; i++) {
    nc_color c = unique_types[i].empty() ? c_dkgray
    @@ -4575,13 +4570,13 @@ int game::mon_info(WINDOW *w)
    mvwprintz(w, ycoords[i] + startrow, xcoords[i], c, dir_labels[i]);
    }
  • // The list of symbols needs a space on each end.
  • const int symroom = row1spaces / 3 - 2;
  • // Print the symbols of all monsters in all directions.
    for (int i = 0; i < 8; i++) {
  •    int symroom;
       point pr(xcoords[i] + strlen(dir_labels[i]) + 1, ycoords[i] + startrow);
    
  •    // The list of symbols needs a space on each end.
    
  •    symroom = (width / 3) - widths[i] - 2;
       const int typeshere = unique_types[i].size();
       for (int j = 0; j < typeshere && j < symroom; j++) {
           buff = unique_types[i][j];[/code]
    

It’s simple patch, witch makes all column’s direction will be divided info 3 equal parts. Every row will be aligned.
Yes, it works with non-English languages, which uses Latin symbols. Before patch columns were unaligned in these languages.
For not Latin languages, my patch can’t resolve issue. Game has to know length of all direction’s strings and it’s length is made with strlen(). So, gettext() return string in utf-8, but strlen() can’t work with utf-8 strings. strlen() returns number of ‘char’ type. For Latin symbols is’t ok, but for utf-8 string ‘char’ != character.
I have googled and have found primitive strlen() for utf-8. I have made a fast patch which replace strlen() to strlen_utf8() and before patch worked for Russian language(for others too, but I hadn’t checked).
At once game will have to work with unicode(utf-8 or other). That’s point of i18n. All calculation based on length of translatable strings and its will must use unicode_len().
I can add strlen_utf-8() in pull request(I hadn’t created yet) which resolves issue #2575, but I don’t know in what file I should place my code. Furthermore, if gettext support will be disabled on compile time, how can it will be used strlen() instead of strlen_utf8()?

#ifdef TRANSLATION FLAG
... definition of strlen_utf8()
#define strlen(string) strlen_utf8(string)
#endif

If this is acceptable, i will write needed patches.

You are correct, and a fix for this would be appreciated, but there is already a utf-8 aware string length function, utf8_width() defined in catacharset.cpp, so no need to import another one.

While gettext is optional to make building on windows easier, I don’t think there’s an easy way to make unicode support optional, so any utf8 handling code will not be conditional. Also we will be adding utf-8 glyphs for better looking maps and such, so we will want to handle them even in the english version.

Thanks for addressing this.