From 89a36d32b12dfa028c31e44a8818acd0eb5cc756 Mon Sep 17 00:00:00 2001 From: Koop Mast Date: Mon, 2 Nov 2015 14:54:21 +0100 Subject: [PATCH] Support 3 component locales. POSIX supports 3 component locales like sr_Cyrl_RS@UTF-8. The code only assumes 2 components, and gives a warning. See http://tools.ietf.org/html/bcp47 , Appendix-A for more examples. --- src/fclang.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/fclang.c b/src/fclang.c index b1fd1bc..ef8574e 100644 --- a/src/fclang.c +++ b/src/fclang.c @@ -183,6 +183,7 @@ FcLangNormalize (const FcChar8 *lang) { FcChar8 *result = NULL, *s, *orig; char *territory, *encoding, *modifier; + char *script; size_t llen, tlen = 0, mlen = 0; if (!lang || !*lang) @@ -241,26 +242,36 @@ FcLangNormalize (const FcChar8 *lang) modifier = encoding; } } - territory = strchr ((const char *) s, '_'); - if (!territory) - territory = strchr ((const char *) s, '-'); + territory = strrchr ((const char *) s, '_'); if (territory) { *territory = 0; territory++; tlen = strlen (territory); } + + /* There might by a script component, e.g. sr_Cyrl_RS@UTF-8. We + * can't assume that all legal locale names are in the form + * _.. If the script component is + * here, skip it to define the language properly + * (e.g. "sr" instead of "sr_Cyrl") + */ + script = strchr ((const char *) s, '_'); + if (script) + { + *script = 0; + } llen = strlen ((const char *) s); if (llen < 2 || llen > 3) { - fprintf (stderr, "Fontconfig warning: ignoring %s: not a valid language tag\n", - lang); + fprintf (stderr, "Fontconfig warning: ignoring %s: not a valid language tag (%s)\n", + s, lang); goto bail0; } if (territory && (tlen < 2 || tlen > 3)) { - fprintf (stderr, "Fontconfig warning: ignoring %s: not a valid region tag\n", - lang); + fprintf (stderr, "Fontconfig warning: ignoring %s: not a valid region tag (%s)\n", + territory, lang); goto bail0; } if (territory) -- 2.6.2