summaryrefslogtreecommitdiff
path: root/src/fcdefault.c
diff options
context:
space:
mode:
authorAkira TAGOH <akira@tagoh.org>2012-03-29 20:25:20 +0900
committerAkira TAGOH <akira@tagoh.org>2012-06-08 15:18:30 +0900
commitbbc8fb5ba705e5257693f3b266fce12d2f81b50c (patch)
tree61c83a8c610dbc403804667dfec835d91d428426 /src/fcdefault.c
parent1b692d8ab91a096e7d433c51ab187382de91147b (diff)
downloadfontconfig-bbc8fb5ba705e5257693f3b266fce12d2f81b50c.tar.gz
Bug 32853 - Export API to get the default language
Add a new API FcGetDefaultLangs() to export the string sets of the default languages.
Diffstat (limited to 'src/fcdefault.c')
-rw-r--r--src/fcdefault.c102
1 files changed, 33 insertions, 69 deletions
diff --git a/src/fcdefault.c b/src/fcdefault.c
index 170a8a4..674374c 100644
--- a/src/fcdefault.c
+++ b/src/fcdefault.c
@@ -23,7 +23,7 @@
*/
#include "fcint.h"
-#include <locale.h>
+#include <string.h>
static const struct {
FcObject field;
@@ -39,81 +39,45 @@ static const struct {
#define NUM_FC_BOOL_DEFAULTS (int) (sizeof FcBoolDefaults / sizeof FcBoolDefaults[0])
-FcChar8 *
-FcGetDefaultLang (void)
+FcStrSet *
+FcGetDefaultLangs (void)
{
- static char lang_local [128] = {0};
- char *ctype;
- char *territory;
- char *after;
- int lang_len, territory_len;
-
- if (lang_local [0])
- return (FcChar8 *) lang_local;
-
- ctype = setlocale (LC_CTYPE, NULL);
-
- /*
- * Check if setlocale (LC_ALL, "") has been called
- */
- if (!ctype || !strcmp (ctype, "C"))
+ FcStrSet *result = FcStrSetCreate ();
+ char *langs;
+
+ langs = getenv ("FC_LANG");
+ if (!langs)
+ langs = getenv ("LC_ALL");
+ if (!langs)
+ langs = getenv ("LC_CTYPE");
+ if (!langs)
+ langs = getenv ("LANG");
+ if (langs)
{
- ctype = getenv ("LC_ALL");
- if (!ctype)
- {
- ctype = getenv ("LC_CTYPE");
- if (!ctype)
- ctype = getenv ("LANG");
- }
+ if (!FcStrSetAddLangs (result, langs))
+ FcStrSetAdd (result, (const FcChar8 *) "en");
}
+ else
+ FcStrSetAdd (result, (const FcChar8 *) "en");
+
+ return result;
+}
- /* ignore missing or empty ctype */
- if (ctype && *ctype != '\0')
+FcChar8 *
+FcGetDefaultLang (void)
+{
+ static FcChar8 lang_local[128] = {0};
+ FcStrSet *langs;
+
+ if (!lang_local[0])
{
- territory = strchr (ctype, '_');
- if (territory)
- {
- lang_len = territory - ctype;
- territory = territory + 1;
- after = strchr (territory, '.');
- if (!after)
- {
- after = strchr (territory, '@');
- if (!after)
- after = territory + strlen (territory);
- }
- territory_len = after - territory;
- if (lang_len + 1 + territory_len + 1 <= (int) sizeof (lang_local))
- {
- strncpy (lang_local, ctype, lang_len);
- lang_local[lang_len] = '-';
- strncpy (lang_local + lang_len + 1, territory, territory_len);
- lang_local[lang_len + 1 + territory_len] = '\0';
- }
- }
- else
- {
- after = strchr (ctype, '.');
- if (!after)
- {
- after = strchr (ctype, '@');
- if (!after)
- after = ctype + strlen (ctype);
- }
- lang_len = after - ctype;
- if (lang_len + 1 <= (int) sizeof (lang_local))
- {
- strncpy (lang_local, ctype, lang_len);
- lang_local[lang_len] = '\0';
- }
- }
+ langs = FcGetDefaultLangs ();
+ strncpy ((char *)lang_local, (const char *)langs->strs[0], 127);
+ lang_local[127] = 0;
+ FcStrSetDestroy (langs);
}
- /* set default lang to en */
- if (!lang_local [0])
- strcpy (lang_local, "en");
-
- return (FcChar8 *) lang_local;
+ return lang_local;
}
void