aboutsummaryrefslogtreecommitdiff
path: root/utf8.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-02-05 19:40:35 -0800
committerJunio C Hamano <gitster@pobox.com>2009-02-05 19:40:35 -0800
commit9242431ca0e2e9ab95008b29b4d88e7bd72d6257 (patch)
tree644171561184533f9a59d9e575c79401e45ed3c4 /utf8.c
parent74b11bc3beca489502d0840e4c558a5fcc44e145 (diff)
parentffaf9cc0ff0692a0b60cdf1b62e8375706b7865d (diff)
downloadgit-9242431ca0e2e9ab95008b29b4d88e7bd72d6257.tar.gz
git-9242431ca0e2e9ab95008b29b4d88e7bd72d6257.tar.xz
Merge branch 'gt/utf8-width'
* gt/utf8-width: builtin-blame.c: Use utf8_strwidth for author's names utf8: add utf8_strwidth()
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/utf8.c b/utf8.c
index dc3735364..ddfdc5e2b 100644
--- a/utf8.c
+++ b/utf8.c
@@ -246,6 +246,25 @@ int utf8_width(const char **start, size_t *remainder_p)
return git_wcwidth(ch);
}
+/*
+ * Returns the total number of columns required by a null-terminated
+ * string, assuming that the string is utf8. Returns strlen() instead
+ * if the string does not look like a valid utf8 string.
+ */
+int utf8_strwidth(const char *string)
+{
+ int width = 0;
+ const char *orig = string;
+
+ while (1) {
+ if (!string)
+ return strlen(orig);
+ if (!*string)
+ return width;
+ width += utf8_width(&string, NULL);
+ }
+}
+
int is_utf8(const char *text)
{
while (*text) {