diff options
-rw-r--r-- | src/bfstd.c | 8 | ||||
-rw-r--r-- | tests/bfstd.c | 3 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/bfstd.c b/src/bfstd.c index c6c2e7f..5b64452 100644 --- a/src/bfstd.c +++ b/src/bfstd.c @@ -695,8 +695,12 @@ size_t xstrwidth(const char *str) { if (wc == WEOF) { // Assume a single-width '?' ++ret; - } else { - ret += xwcwidth(wc); + continue; + } + + int width = xwcwidth(wc); + if (width > 0) { + ret += width; } } diff --git a/tests/bfstd.c b/tests/bfstd.c index 26abdb6..1351e11 100644 --- a/tests/bfstd.c +++ b/tests/bfstd.c @@ -69,5 +69,8 @@ bool check_bfstd(void) { ret &= check_wordesc("\xF0\x9F\x98\x80", "\xF0\x9F\x98\x80", WESC_SHELL | WESC_TTY); } + ret &= bfs_check(xstrwidth("Hello world") == 11); + ret &= bfs_check(xstrwidth("Hello\1world") == 10); + return ret; } |