summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-10-18 02:40:49 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-10-18 02:40:49 (GMT)
commit3def8ae9a4b18f1cb475e0ac3bc6034aaa29741d (patch)
treefbd87915fa21a35b9f3fea1bad47a486a17fc485
parentd0258d09448bff3da88b9b43636de1d8310ec436 (diff)
parenta81e42d23588188c49f9b6e519f99a734a5aacb9 (diff)
downloadgit-3def8ae9a4b18f1cb475e0ac3bc6034aaa29741d.zip
git-3def8ae9a4b18f1cb475e0ac3bc6034aaa29741d.tar.gz
git-3def8ae9a4b18f1cb475e0ac3bc6034aaa29741d.tar.bz2
Merge branch 'rs/column-use-utf8-strnwidth'
Code cleanup. * rs/column-use-utf8-strnwidth: column: use utf8_strnwidth() to strip out ANSI color escapes
-rw-r--r--column.c13
1 files changed, 1 insertions, 12 deletions
diff --git a/column.c b/column.c
index 7a17c14..4a38eed 100644
--- a/column.c
+++ b/column.c
@@ -23,18 +23,7 @@ struct column_data {
/* return length of 's' in letters, ANSI escapes stripped */
static int item_length(const char *s)
{
- int len, i = 0;
- struct strbuf str = STRBUF_INIT;
-
- strbuf_addstr(&str, s);
- while ((s = strstr(str.buf + i, "\033[")) != NULL) {
- int len = strspn(s + 2, "0123456789;");
- i = s - str.buf;
- strbuf_remove(&str, i, len + 3); /* \033[<len><func char> */
- }
- len = utf8_strwidth(str.buf);
- strbuf_release(&str);
- return len;
+ return utf8_strnwidth(s, -1, 1);
}
/*