From 754395d3052fc0d46948b2ff7006b3c6701785c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Tue, 4 Sep 2012 17:39:35 +0700 Subject: fetch: align per-ref summary report in UTF-8 locales MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fetch does printf("%-*s", width, "foo") where "foo" can be a utf-8 string, but width is in bytes, not columns. For ASCII it's fine as one byte takes one column. For utf-8, this may result in misaligned ref summary table. Introduce gettext_width() function that returns the string length in columns (currently only supports utf-8 locales). Make the code use TRANSPORT_SUMMARY(x) where the length is compensated properly in non-English locales. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- gettext.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'gettext.c') diff --git a/gettext.c b/gettext.c index f75bca7f5..71e954563 100644 --- a/gettext.c +++ b/gettext.c @@ -4,6 +4,8 @@ #include "git-compat-util.h" #include "gettext.h" +#include "strbuf.h" +#include "utf8.h" #ifndef NO_GETTEXT # include @@ -27,10 +29,9 @@ int use_gettext_poison(void) #endif #ifndef NO_GETTEXT +static const char *charset; static void init_gettext_charset(const char *domain) { - const char *charset; - /* This trick arranges for messages to be emitted in the user's requested encoding, but avoids setting LC_CTYPE from the @@ -128,4 +129,14 @@ void git_setup_gettext(void) init_gettext_charset("git"); textdomain("git"); } + +/* return the number of columns of string 's' in current locale */ +int gettext_width(const char *s) +{ + static int is_utf8 = -1; + if (is_utf8 == -1) + is_utf8 = !strcmp(charset, "UTF-8"); + + return is_utf8 ? utf8_strwidth(s) : strlen(s); +} #endif -- cgit v1.2.1