nsresult nsPosixLocale::GetXPLocale(const char* posixLocale, nsAString& locale) { char country_code[MAX_COUNTRY_CODE_LEN+1]; char lang_code[MAX_LANGUAGE_CODE_LEN+1]; char extra[MAX_EXTRA_LEN+1]; char posix_locale[MAX_LOCALE_LEN+1]; if (posixLocale!=nullptr) { if (strcmp(posixLocale,"C")==0 || strcmp(posixLocale,"POSIX")==0) { locale.AssignLiteral("en-US"); return NS_OK; } if (strcmp(posixLocale,"C.UTF-8")==0) { locale.AssignLiteral("en-US.UTF-8"); return NS_OK; } if (!ParseLocaleString(posixLocale,lang_code,country_code,extra,'_')) { // * locale = "x-user-defined"; // use posix if parse failed CopyASCIItoUTF16(nsDependentCString(posixLocale), locale); return NS_OK; } // Special case: substitute "nb" (Norwegian Bokmal) for macrolanguage // code "no" (Norwegian) if (nsDependentCString(lang_code).LowerCaseEqualsLiteral("no")) { lang_code[1] = 'b'; } if (*country_code) { snprintf_literal(posix_locale,"%s-%s",lang_code,country_code); } else { snprintf_literal(posix_locale,"%s",lang_code); } CopyASCIItoUTF16(nsDependentCString(posix_locale), locale); return NS_OK; } return NS_ERROR_FAILURE; }
NS_IMETHODIMP nsOS2Locale::GetXPLocale(const char* os2Locale, nsAString& locale) { char country_code[MAX_COUNTRY_CODE_LEN]; char lang_code[MAX_LANGUAGE_CODE_LEN]; char extra[MAX_EXTRA_LEN]; char os2_locale[MAX_LOCALE_LEN]; if (os2Locale!=nsnull) { if (strcmp(os2Locale,"C")==0 || strcmp(os2Locale,"OS2")==0) { locale.AssignLiteral("en-US"); return NS_OK; } if (!ParseLocaleString(os2Locale,lang_code,country_code,extra,'_')) { // * locale = "x-user-defined"; // use os2 if parse failed CopyASCIItoUTF16(nsDependentCString(os2Locale), locale); return NS_OK; } if (*country_code) { if (*extra) { PR_snprintf(os2_locale,MAX_LOCALE_LEN,"%s-%s.%s",lang_code,country_code,extra); } else { PR_snprintf(os2_locale,MAX_LOCALE_LEN,"%s-%s",lang_code,country_code); } } else { if (*extra) { PR_snprintf(os2_locale,MAX_LOCALE_LEN,"%s.%s",lang_code,extra); } else { PR_snprintf(os2_locale,MAX_LOCALE_LEN,"%s",lang_code); } } CopyASCIItoUTF16(nsDependentCString(os2_locale), locale); return NS_OK; } return NS_ERROR_FAILURE; }
NS_IMETHODIMP nsMacLocale::GetPlatformLocale(const nsAString& locale, short* scriptCode, short* langCode, short* regionCode) { char country_code[3]; char lang_code[3]; char region_code[3]; bool validCountryFound; int i; if (!ParseLocaleString(NS_LossyConvertUTF16toASCII(locale).get(), lang_code, country_code, region_code, '-')) { *scriptCode = smRoman; *langCode = langEnglish; *regionCode = verUS; return NS_ERROR_FAILURE; } if (country_code[0]!=0) { validCountryFound=false; for(i=0;country_list[i].iso_code;i++) { if (strcmp(country_list[i].iso_code,country_code)==0) { *regionCode = country_list[i].mac_region_code; validCountryFound=true; break; } } if (!validCountryFound) { *scriptCode = smRoman; *langCode = langEnglish; *regionCode = verUS; return NS_ERROR_FAILURE; } } for(i=0;lang_list[i].iso_code;i++) { if (strcmp(lang_list[i].iso_code, lang_code)==0) { *scriptCode = lang_list[i].mac_script_code; *langCode = lang_list[i].mac_lang_code; return NS_OK; } } return NS_ERROR_FAILURE; }
nsresult nsPosixLocale::GetPlatformLocale(const nsAString& locale, nsACString& posixLocale) { char country_code[MAX_COUNTRY_CODE_LEN+1]; char lang_code[MAX_LANGUAGE_CODE_LEN+1]; char extra[MAX_EXTRA_LEN+1]; char posix_locale[MAX_LOCALE_LEN+1]; NS_LossyConvertUTF16toASCII xp_locale(locale); if (!xp_locale.IsEmpty()) { if (!ParseLocaleString(xp_locale.get(),lang_code,country_code,extra,'-')) { // strncpy(posixLocale,"C",length); posixLocale = xp_locale; // use xp locale if parse failed return NS_OK; } if (*country_code) { if (*extra) { snprintf_literal(posix_locale,"%s_%s.%s",lang_code,country_code,extra); } else { snprintf_literal(posix_locale,"%s_%s",lang_code,country_code); } } else { if (*extra) { snprintf_literal(posix_locale,"%s.%s",lang_code,extra); } else { snprintf_literal(posix_locale,"%s",lang_code); } } posixLocale = posix_locale; return NS_OK; } return NS_ERROR_FAILURE; }