зеркало из https://github.com/microsoft/git.git
gettext: add is_utf8_locale()
This function returns true if git is running under an UTF-8 locale. pcre in the next patch will need this. is_encoding_utf8() is used instead of strcmp() to catch both "utf-8" and "utf8" suffixes. When built with no gettext support, we peek in several env variables to detect UTF-8. pcre library might support utf-8 even if libc is built without locale support.. The peeking code is a copy from compat/regex/regcomp.c Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
9d9babb84d
Коммит
e8c1672655
24
gettext.c
24
gettext.c
|
@ -18,6 +18,8 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
static const char *charset;
|
||||
|
||||
/*
|
||||
* Guess the user's preferred languages from the value in LANGUAGE environment
|
||||
* variable and LC_MESSAGES locale category if NO_GETTEXT is not defined.
|
||||
|
@ -65,7 +67,6 @@ static int test_vsnprintf(const char *fmt, ...)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static const char *charset;
|
||||
static void init_gettext_charset(const char *domain)
|
||||
{
|
||||
/*
|
||||
|
@ -172,8 +173,27 @@ int gettext_width(const char *s)
|
|||
{
|
||||
static int is_utf8 = -1;
|
||||
if (is_utf8 == -1)
|
||||
is_utf8 = !strcmp(charset, "UTF-8");
|
||||
is_utf8 = is_utf8_locale();
|
||||
|
||||
return is_utf8 ? utf8_strwidth(s) : strlen(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
int is_utf8_locale(void)
|
||||
{
|
||||
#ifdef NO_GETTEXT
|
||||
if (!charset) {
|
||||
const char *env = getenv("LC_ALL");
|
||||
if (!env || !*env)
|
||||
env = getenv("LC_CTYPE");
|
||||
if (!env || !*env)
|
||||
env = getenv("LANG");
|
||||
if (!env)
|
||||
env = "";
|
||||
if (strchr(env, '.'))
|
||||
env = strchr(env, '.') + 1;
|
||||
charset = xstrdup(env);
|
||||
}
|
||||
#endif
|
||||
return is_encoding_utf8(charset);
|
||||
}
|
||||
|
|
|
@ -90,5 +90,6 @@ const char *Q_(const char *msgid, const char *plu, unsigned long n)
|
|||
#endif
|
||||
|
||||
const char *get_preferred_languages(void);
|
||||
extern int is_utf8_locale(void);
|
||||
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче