X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=utf8.c;h=db706ac4ed6f033091cfaeb7b23c07ca7fd71675;hb=b3c32ead20bc4d3baa6cffe00dd862f069463869;hp=dc3735364f85273c2a119b994ddb405c09dc395c;hpb=35d2f73b999636c93049b2d7bed1458bcf2f9648;p=git.git diff --git a/utf8.c b/utf8.c index dc3735364..db706ac4e 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) { @@ -335,7 +354,7 @@ int is_encoding_utf8(const char *name) * with iconv. If the conversion fails, returns NULL. */ #ifndef NO_ICONV -#ifdef OLD_ICONV +#if defined(OLD_ICONV) || (defined(__sun__) && !defined(_XPG6)) typedef const char * iconv_ibp; #else typedef char * iconv_ibp;