From 981b4149803ae3f4ec3b6fb018f1e5e86dfe25b0 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg <bensberg@justemail.net> Date: Sun, 24 Apr 2016 22:02:48 +0200 Subject: [PATCH] utils: distinguish between width (columns) and length (bytes) --- src/utils.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/utils.c b/src/utils.c index 0814aa9f..7f1d8c9b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -484,38 +484,37 @@ size_t actual_x(const char *s, size_t column) return i; } -/* A strnlen() with tabs and multicolumn characters factored in, similar - * to xplustabs(). How many columns wide are the first maxlen characters - * of s? */ -size_t strnlenpt(const char *s, size_t maxlen) +/* A strnlen() with tabs and multicolumn characters factored in: + * how many columns wide are the first maxlen bytes of text? */ +size_t strnlenpt(const char *text, size_t maxlen) { - size_t len = 0; - /* The screen display width to s[i]. */ + size_t width = 0; + /* The screen display width to text[maxlen]. */ if (maxlen == 0) return 0; - assert(s != NULL); + assert(text != NULL); - while (*s != '\0') { - int s_len = parse_mbchar(s, NULL, &len); + while (*text != '\0') { + int charlen = parse_mbchar(text, NULL, &width); - s += s_len; + text += charlen; - if (maxlen <= s_len) + if (maxlen <= charlen) break; - maxlen -= s_len; + maxlen -= charlen; } - return len; + return width; } -/* A strlen() with tabs and multicolumn characters factored in, similar - * to xplustabs(). How many columns wide is s? */ -size_t strlenpt(const char *s) +/* A strlen() with tabs and multicolumn characters factored in: + * how many columns wide is text? */ +size_t strlenpt(const char *text) { - return strnlenpt(s, (size_t)-1); + return strnlenpt(text, (size_t)-1); } /* Append a new magicline to filebot. */ -- GitLab