ICU-2395 Add some documentation on setlocale and cleanup some of the code for getting the default locale.

X-SVN-Rev: 10062
This commit is contained in:
George Rhoten 2002-10-24 20:52:54 +00:00
parent 80ce3b2d6c
commit 08ca9c365b
2 changed files with 33 additions and 32 deletions

View File

@ -1127,28 +1127,25 @@ The leftmost codepage (.xxx) wins.
l = lang, C = ctry, M = charmap, V = variant
*/
if(gCorrectedPOSIXLocale != NULL) {
return gCorrectedPOSIXLocale;
if (gCorrectedPOSIXLocale != NULL) {
return gCorrectedPOSIXLocale;
}
if((p = uprv_strchr(posixID, '.')) != NULL)
{
if ((p = uprv_strchr(posixID, '.')) != NULL) {
/* assume new locale can't be larger than old one? */
correctedPOSIXLocale = uprv_malloc(uprv_strlen(posixID));
uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID);
correctedPOSIXLocale[p-posixID] = 0;
/* do not copy after the @ */
if((p = uprv_strchr(correctedPOSIXLocale, '@')) != NULL)
{
if ((p = uprv_strchr(correctedPOSIXLocale, '@')) != NULL) {
correctedPOSIXLocale[p-correctedPOSIXLocale] = 0;
}
}
/* Note that we scan the *uncorrected* ID. */
if((p = uprv_strrchr(posixID, '@')) != NULL)
{
if(correctedPOSIXLocale == NULL) {
if ((p = uprv_strrchr(posixID, '@')) != NULL) {
if (correctedPOSIXLocale == NULL) {
correctedPOSIXLocale = uprv_malloc(uprv_strlen(posixID));
uprv_strncpy(correctedPOSIXLocale, posixID, p-posixID);
correctedPOSIXLocale[p-posixID] = 0;
@ -1156,58 +1153,58 @@ The leftmost codepage (.xxx) wins.
p++;
/* Take care of any special cases here.. */
if(!uprv_strcmp(p, "nynorsk"))
{
if (!uprv_strcmp(p, "nynorsk")) {
p = "NY";
/* Should we assume no_NO_NY instead of possible no__NY?
* if(!uprv_strcmp(correctedPOSIXLocale, "no")) {
* uprv_strcpy(correctedPOSIXLocale, "no_NO");
* }
* if (!uprv_strcmp(correctedPOSIXLocale, "no")) {
* uprv_strcpy(correctedPOSIXLocale, "no_NO");
* }
*/
}
if(uprv_strchr(correctedPOSIXLocale,'_') == NULL)
{
if (uprv_strchr(correctedPOSIXLocale,'_') == NULL) {
uprv_strcat(correctedPOSIXLocale, "__"); /* aa@b -> aa__b */
}
else
{
else {
uprv_strcat(correctedPOSIXLocale, "_"); /* aa_CC@b -> aa_CC_b */
}
if((q = uprv_strchr(p, '.')) != NULL)
{
if ((q = uprv_strchr(p, '.')) != NULL) {
/* How big will the resulting string be? */
len = uprv_strlen(correctedPOSIXLocale) + (q-p);
uprv_strncat(correctedPOSIXLocale, p, q-p);
correctedPOSIXLocale[len] = 0;
}
else
{
uprv_strcat(correctedPOSIXLocale, p); /* Anything following the @ sign */
else {
/* Anything following the @ sign */
uprv_strcat(correctedPOSIXLocale, p);
}
/* Should there be a map from 'no@nynorsk' -> no_NO_NY here?
How about 'russian' -> 'ru'?
*/
* How about 'russian' -> 'ru'?
*/
}
/* Was a correction made? */
if(correctedPOSIXLocale != NULL)
{
if (correctedPOSIXLocale != NULL) {
posixID = correctedPOSIXLocale;
}
else {
/* copy it, just in case the original pointer goes away. See j2395 */
correctedPOSIXLocale = (char *)uprv_malloc(uprv_strlen(posixID) + 1);
posixID = uprv_strcpy(correctedPOSIXLocale, posixID);
}
umtx_lock(NULL);
if(gCorrectedPOSIXLocale == NULL) {
if (gCorrectedPOSIXLocale == NULL) {
gCorrectedPOSIXLocale = correctedPOSIXLocale;
correctedPOSIXLocale = NULL;
}
}
umtx_unlock(NULL);
if(correctedPOSIXLocale != NULL) { /* Was already set - clean up. */
uprv_free(correctedPOSIXLocale);
if (correctedPOSIXLocale != NULL) { /* Was already set - clean up. */
uprv_free(correctedPOSIXLocale);
}
return posixID;

View File

@ -200,7 +200,9 @@ U_CAPI const char* U_EXPORT2 u_getDataDirectory(void);
U_CAPI void U_EXPORT2 u_setDataDirectory(const char *directory);
/**
* Return the default codepage for this platform and locale
* Return the default codepage for this platform and locale.
* This function can call setlocale() on Unix platforms. Please read the
* platform documentation on setlocale() before calling this function.
* @return the default codepage for this platform
* @stable
*/
@ -209,6 +211,8 @@ U_CAPI const char* U_EXPORT2 uprv_getDefaultCodepage(void);
/**
* Return the default locale ID string by querying ths system, or
* zero if one cannot be found.
* This function can call setlocale() on Unix platforms. Please read the
* platform documentation on setlocale() before calling this function.
* @return the default locale ID string
* @stable
*/