static void xsltEnumSupportedLocales(void) { xmlRMutexLock(xsltLocaleMutex); if (xsltLocaleListSize <= 0) { size_t len; EnumSystemLocalesA(xsltCountSupportedLocales, LCID_SUPPORTED); len = xsltLocaleListSize * sizeof(xsltRFC1766Info); xsltLocaleList = xmlMalloc(len); memset(xsltLocaleList, 0, len); EnumSystemLocalesA(xsltIterateSupportedLocales, LCID_SUPPORTED); } xmlRMutexUnlock(xsltLocaleMutex); }
const char* MSVC_LocaleLookup(const char* raw_shortname) { /* NULL is used to read locale only so we need to return it too */ if (raw_shortname == NULL) return NULL; std::string shortname(raw_shortname); if (shortname == "C") return "C"; if (shortname == "") return ""; static std::string last_raw_value = ""; static std::string last_full_name = ""; static bool first_use = true; if (last_raw_value == shortname) { return last_full_name.c_str(); } if (first_use) { EnumSystemLocalesA(UpdateLocaleCallback, LCID_SUPPORTED | LCID_ALTERNATE_SORTS); first_use = false; } last_raw_value = shortname; if (glb_supported_locales.find(utf8_to_wide(shortname)) != glb_supported_locales.end()) { last_full_name = wide_to_utf8( glb_supported_locales[utf8_to_wide(shortname)]); return last_full_name.c_str(); } /* empty string is system default */ errorstream << "MSVC_LocaleLookup: unsupported locale: \"" << shortname << "\" switching to system default!" << std::endl; return ""; }
int __GetLCID(const char* lang, const char* ctry, LCID* lcid) { __FindFlag=0; __FndLang=lang; __FndCtry=ctry; EnumSystemLocalesA(EnumLocalesProcA, LCID_INSTALLED); if(__FindFlag==0) return -1; *lcid=__FndLCID; return 0; }
/*** *void GetLcidFromCountry - get LCIDs from country string * *Purpose: * Match the best LCIDs to the country string given. After global * variables are initialized, the CountryEnumProc routine is * registered as an EnumSystemLocalesA callback to actually perform * the matching as the LCIDs are enumerated. * *Entry: * pchCountry - country string * bAbbrevCountry - country string is a three-letter abbreviation * *Exit: * lcidLanguage - lcidCountry - LCID of country with default * language * *Exceptions: * *******************************************************************************/ static void GetLcidFromCountry (void) { bAbbrevCountry = strlen(pchCountry) == 3; EnumSystemLocalesA(CountryEnumProc, LCID_INSTALLED); // locale value is invalid if the country was not defined or // no default language was found if (!(iLcidState & __LCID_FULL)) iLcidState = 0; }
/*** *void GetLcidFromLanguage - get LCIDs from language string * *Purpose: * Match the best LCIDs to the language string given. After global * variables are initialized, the LanguageEnumProc routine is * registered as an EnumSystemLocalesA callback to actually perform * the matching as the LCIDs are enumerated. * *Entry: * pchLanguage - language string * bAbbrevLanguage - language string is a three-letter abbreviation * iPrimaryLen - length of language string with primary name * *Exit: * lcidLanguage - lcidCountry - LCID of language with default * country * *Exceptions: * *******************************************************************************/ static void GetLcidFromLanguage (void) { // initialize static variables for callback use bAbbrevLanguage = strlen(pchLanguage) == 3; iPrimaryLen = bAbbrevLanguage ? 2 : GetPrimaryLen(pchLanguage); EnumSystemLocalesA(LanguageEnumProc, LCID_INSTALLED); // locale value is invalid if the language was not installed // or the language was not available for the country specified if (!(iLcidState & __LCID_FULL)) iLcidState = 0; }
/*** *void GetLcidFromLangCountry - get LCIDs from language and country strings * *Purpose: * Match the best LCIDs to the language and country string given. * After global variables are initialized, the LangCountryEnumProc * routine is registered as an EnumSystemLocalesA callback to actually * perform the matching as the LCIDs are enumerated. * *Entry: * pchLanguage - language string * bAbbrevLanguage - language string is a three-letter abbreviation * pchCountry - country string * bAbbrevCountry - country string ia a three-letter abbreviation * iPrimaryLen - length of language string with primary name * *Exit: * lcidLanguage - LCID of language string * lcidCountry - LCID of country string * *Exceptions: * *******************************************************************************/ static void GetLcidFromLangCountry (void) { // initialize static variables for callback use bAbbrevLanguage = strlen(pchLanguage) == 3; bAbbrevCountry = strlen(pchCountry) == 3; lcidLanguage = 0; iPrimaryLen = bAbbrevLanguage ? 2 : GetPrimaryLen(pchLanguage); EnumSystemLocalesA(LangCountryEnumProc, LCID_INSTALLED); // locale value is invalid if the language was not installed or the language // was not available for the country specified if (!(iLcidState & __LCID_LANGUAGE) || !(iLcidState & __LCID_EXISTS) || !(iLcidState & (__LCID_FULL | __LCID_PRIMARY | __LCID_DEFAULT))) iLcidState = 0; }
rtl_TextEncoding SAL_CALL osl_getTextEncodingFromLocale( rtl_Locale * pLocale ) { struct EnumLocalesParams params = { L"", L"", 0 }; /* initialise global TLS id */ if( (DWORD) -1 == g_dwTLSLocaleEncId ) { oslMutex globalMutex = * osl_getGlobalMutex(); /* initializing must be thread save */ osl_acquireMutex( globalMutex ); if( (DWORD) -1 == g_dwTLSLocaleEncId ) g_dwTLSLocaleEncId = TlsAlloc(); osl_releaseMutex( globalMutex ); } /* if pLocale is NULL, use process locale as default */ if( NULL == pLocale ) osl_getProcessLocale( &pLocale ); /* copy in parameters to structure */ if( pLocale && pLocale->Language && pLocale->Language->length < ELP_LANGUAGE_FIELD_LENGTH ) { wcscpy( params.Language, pLocale->Language->buffer ); if( pLocale->Country && pLocale->Country->length < ELP_COUNTRY_FIELD_LENGTH ) wcscpy( params.Country, pLocale->Country->buffer ); /* save pointer to local structure in TLS */ TlsSetValue( g_dwTLSLocaleEncId, ¶ms ); /* enum all locales known to Windows */ EnumSystemLocalesA( EnumLocalesProcA, LCID_SUPPORTED ); /* use the LCID found in iteration */ return GetTextEncodingFromLCID( params.Locale ); } return RTL_TEXTENCODING_DONTKNOW; }