X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=utf8.c;h=1087870c51caff3dd86a852ec5e8bf5875f6d797;hb=a1d68bea891118bdaecb6dd77610e6daf2f7d53d;hp=a4ee6650ef6c4c487c083aabf0a950b8ec317b09;hpb=2173205f5c6e0e87c282cf94c13c8a41935cb1a2;p=git.git diff --git a/utf8.c b/utf8.c index a4ee6650e..1087870c5 100644 --- a/utf8.c +++ b/utf8.c @@ -429,6 +429,27 @@ int same_encoding(const char *src, const char *dst) return !strcasecmp(src, dst); } +/* + * Wrapper for fprintf and returns the total number of columns required + * for the printed string, assuming that the string is utf8. + */ +int utf8_fprintf(FILE *stream, const char *format, ...) +{ + struct strbuf buf = STRBUF_INIT; + va_list arg; + int columns; + + va_start(arg, format); + strbuf_vaddf(&buf, format, arg); + va_end(arg); + + columns = fputs(buf.buf, stream); + if (0 <= columns) /* keep the error from the I/O */ + columns = utf8_strwidth(buf.buf); + strbuf_release(&buf); + return columns; +} + /* * Given a buffer and its encoding, return it re-encoded * with iconv. If the conversion fails, returns NULL.