#include "c.h"
Go to the source code of this file.
Data Structures | |
struct | locale_map |
Functions | |
char * | pgwin32_setlocale (int category, const char *locale) |
Variables | |
static struct locale_map | locale_map_list [] |
char* pgwin32_setlocale | ( | int | category, | |
const char * | locale | |||
) |
Definition at line 66 of file win32setlocale.c.
References free, i, lengthof, locale_map::locale_name_part, malloc, NULL, and locale_map::replacement.
{ char *result; char *alias; int i; if (locale == NULL) return setlocale(category, locale); /* Check if the locale name matches any of the problematic ones. */ alias = NULL; for (i = 0; i < lengthof(locale_map_list); i++) { const char *needle = locale_map_list[i].locale_name_part; const char *replacement = locale_map_list[i].replacement; char *match; match = strstr(locale, needle); if (match != NULL) { /* Found a match. Replace the matched string. */ int matchpos = match - locale; int replacementlen = strlen(replacement); char *rest = match + strlen(needle); int restlen = strlen(rest); alias = malloc(matchpos + replacementlen + restlen + 1); if (!alias) return NULL; memcpy(&alias[0], &locale[0], matchpos); memcpy(&alias[matchpos], replacement, replacementlen); memcpy(&alias[matchpos + replacementlen], rest, restlen + 1); /* includes null * terminator */ break; } } /* Call the real setlocale() function */ if (alias) { result = setlocale(category, alias); free(alias); } else result = setlocale(category, locale); return result; }
struct locale_map locale_map_list[] [static] |
{ {"Hong Kong S.A.R.", "HKG"}, {"U.A.E.", "ARE"}, {"Chinese (Traditional)_Macau S.A.R..950", "ZHM"}, {"Chinese_Macau S.A.R..950", "ZHM"}, {"Chinese (Traditional)_Macao S.A.R..950", "ZHM"}, {"Chinese_Macao S.A.R..950", "ZHM"} }
Definition at line 34 of file win32setlocale.c.