tWork with characters, not bytes - vaccinewars - be a doctor and try to vaccina… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 57dbe7518a6f3246df05170bbb362cbf8263a6dc | |
parent 4de78172baa253ad9297d26834c41ff628204bc1 | |
Author: Ben Webb <[email protected]> | |
Date: Wed, 9 Dec 2020 19:22:23 -0800 | |
Work with characters, not bytes | |
When outputting fixed width strings, use the width | |
in characters, not bytes. Closes #54. | |
Diffstat: | |
M src/curses_client/curses_client.c | 24 +++++++++++++++--------- | |
1 file changed, 15 insertions(+), 9 deletions(-) | |
--- | |
diff --git a/src/curses_client/curses_client.c b/src/curses_client/curses_clien… | |
t@@ -292,22 +292,28 @@ static void mvaddcentstr(const int row, const gchar *str) | |
/* | |
* Displays a string at the given coordinates and with the given | |
- * attributes. If the string is longer than "wid", it is truncated, and | |
- * if shorter, it is padded with spaces. | |
+ * attributes. If the string is longer than "wid" characters, it is truncated, | |
+ * and if shorter, it is padded with spaces. | |
*/ | |
static void mvaddfixwidstr(const int row, const int col, const int wid, | |
const gchar *str, const int attrs) | |
{ | |
- int strwid = str ? strlen(str) : 0; | |
- int strind; | |
+ int strwidch = str ? strcharlen(str) : 0; | |
+ int i, strwidbyte; | |
- strwid = MIN(strwid, wid); | |
+ strwidch = MIN(strwidch, wid); | |
+ if (LocaleIsUTF8) { | |
+ strwidbyte = g_utf8_offset_to_pointer(str, strwidch) - str; | |
+ } else { | |
+ strwidbyte = strwidch; | |
+ } | |
- for (strind = 0; strind < strwid; ++strind) { | |
- mvaddch(row, col + strind, (guchar)str[strind] | attrs); | |
+ move(row, col); | |
+ for (i = 0; i < strwidbyte; ++i) { | |
+ addch((guchar)str[i] | attrs); | |
} | |
- for (strind = strwid; strind < wid; ++strind) { | |
- mvaddch(row, col + strind, (guchar)' ' | attrs); | |
+ for (i = strwidch; i < wid; ++i) { | |
+ addch((guchar)' ' | attrs); | |
} | |
} | |