summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bfstd.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/bfstd.c b/src/bfstd.c
index 43513b8..12af438 100644
--- a/src/bfstd.c
+++ b/src/bfstd.c
@@ -728,8 +728,17 @@ size_t xstrwidth(const char *str) {
size_t len = strlen(str);
size_t ret = 0;
+ size_t asclen = asciinlen(str, len);
+ size_t i;
+ for (i = 0; i < asclen; ++i) {
+ // Assume all ASCII printables have width 1
+ if (xisprint(str[i])) {
+ ++ret;
+ }
+ }
+
mbstate_t mb = {0};
- for (size_t i = 0; i < len;) {
+ while (i < len) {
wint_t wc = xmbrtowc(str, &i, len, &mb);
if (wc == WEOF) {
// Assume a single-width '?'