Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2005:
[Freeciv-Dev] (PR#14731) Demographics report and localization
Home

[Freeciv-Dev] (PR#14731) Demographics report and localization

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: himasaram@xxxxxxxx
Subject: [Freeciv-Dev] (PR#14731) Demographics report and localization
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 2 Dec 2005 18:25:26 -0800
Reply-to: bugs@xxxxxxxxxxx

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

I committed the fix to the dev branch...

Final question: can you see this same bug in 2.0?  And, does the
attached patch fix it?

-jason

Index: utility/fciconv.c
===================================================================
--- utility/fciconv.c   (revision 11290)
+++ utility/fciconv.c   (working copy)
@@ -348,3 +348,27 @@
   fputs(output, stream);
   fflush(stream);
 }
+
+/****************************************************************************
+  Return the length, in *characters*, of the string.  This can be used in
+  place of strlen in some places because it returns the number of characters
+  not the number of bytes (with multi-byte characters in UTF-8, the two
+  may not be the same).
+
+  Use of this function outside of GUI layout code is probably a hack.  For
+  instance the demographics code uses it, but this should instead pass the
+  data directly to the GUI library for formatting.
+****************************************************************************/
+size_t get_internal_string_length(const char *text)
+{
+  int text2[(strlen(text) + 1)]; /* UCS-4 text */
+  int i = 0;
+
+  convert_string(text, internal_encoding, "UCS-4",
+                (char *)text2, sizeof(text2));
+  for (i = 0; ; i++) {
+    if (text2[i] == 0) {
+      return i;
+    }
+  }
+}
Index: utility/fciconv.h
===================================================================
--- utility/fciconv.h   (revision 11290)
+++ utility/fciconv.h   (working copy)
@@ -38,4 +38,6 @@
 void fc_fprintf(FILE *stream, const char *format, ...)
       fc__attribute((format (printf, 2, 3)));
 
+size_t get_internal_string_length(const char *text);
+
 #endif /* FC__FCICONV_H */
Index: server/report.c
===================================================================
--- server/report.c     (revision 11290)
+++ server/report.c     (working copy)
@@ -20,6 +20,7 @@
 #include <string.h>
 
 #include "events.h"
+#include "fciconv.h"
 #include "fcintl.h"
 #include "game.h"
 #include "government.h"
@@ -602,8 +603,11 @@
                          int selcols)
 {
   if (TEST_BIT(selcols, DEM_COL_QUANTITY)) {
-      cat_snprintf(outptr, out_size, " %-18s",
-                  prow->to_text(prow->get_value(pplayer)));
+    const char *text = prow->to_text(prow->get_value(pplayer));
+
+    cat_snprintf(outptr, out_size, " %s", text);
+    cat_snprintf(outptr, out_size, "%*s",
+                18 - get_internal_string_length(text), "");
   }
 
   if (TEST_BIT(selcols, DEM_COL_RANK)) {
@@ -738,7 +742,11 @@
   buffer[0] = '\0';
   for (i = 0; i < ARRAY_SIZE(rowtable); i++) {
     if (strchr(game.demography, rowtable[i].key)) {
-      cat_snprintf(buffer, sizeof(buffer), "%-18s", _(rowtable[i].name));
+      const char *name = _(rowtable[i].name);
+
+      cat_snprintf(buffer, sizeof(buffer), "%s", name);
+      cat_snprintf(buffer, sizeof(buffer), "%*s",
+                  18 - get_internal_string_length(name), "");
       dem_line_item(buffer, sizeof(buffer), pplayer, &rowtable[i], selcols);
       sz_strlcat(buffer, "\n");
     }

[Prev in Thread] Current Thread [Next in Thread]