Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Pfister committed May 3, 2022
1 parent 5f034bc commit 5f367d5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
27 changes: 20 additions & 7 deletions src/native/libs/System.Globalization.Native/pal_locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ int32_t FixupLocaleName(UChar* value, int32_t valueLength)
return i;
}

// We use whatever ICU give us as the default locale except if it is en_US_POSIX. We'll map
// this POSIX locale to Invariant instead. The reason is POSIX locale collation behavior
// is not desirable at all because it doesn't support case insensitive string comparisons.
// We use whatever ICU give us as the default locale except if it is en_US_POSIX.
//
// On Apple related platforms (OSX, iOS, tvOS, MacCatalyst), we'll take what the system locale is.
// On all other platforms we'll map this POSIX locale to Invariant instead.
// The reason is POSIX locale collation behavior is not desirable at all because it doesn't support case insensitive string comparisons.
const char* DetectDefaultLocaleName()
{
const char* icuLocale;
Expand All @@ -140,11 +142,7 @@ const char* DetectDefaultLocaleName()

if (strcmp(icuLocale, "en_US_POSIX") == 0)
{
#ifdef TARGET_OS_MAC
icuLocale = DetectDefaultAppleLocaleName();
#else
return "";
#endif
}

return icuLocale;
Expand Down Expand Up @@ -223,6 +221,16 @@ int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLeng

const char* defaultLocale = DetectDefaultLocaleName();

#ifdef __APPLE__
char* appleLocale = NULL;

if (strcmp(defaultLocale, "") == 0)
{
appleLocale = DetectDefaultAppleLocaleName();
defaultLocale = appleLocale;
}
#endif

uloc_getBaseName(defaultLocale, localeNameBuffer, ULOC_FULLNAME_CAPACITY, &status);
u_charsToUChars_safe(localeNameBuffer, value, valueLength, &status);

Expand All @@ -243,6 +251,11 @@ int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLeng
}
}

#ifdef __APPLE__
if (appleLocale)
free(appleLocale);
#endif

return UErrorCodeToBool(status);
}

Expand Down
2 changes: 1 addition & 1 deletion src/native/libs/System.Globalization.Native/pal_locale.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#import <Foundation/Foundation.h>

const char* DetectDefaultAppleLocaleName()
char* DetectDefaultAppleLocaleName()
{
NSLocale *currentLocale = [NSLocale currentLocale];
NSString *localeName = @"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ DetectDefaultSystemLocaleName
Detects the default locale string for Apple platforms
*/
const char* DetectDefaultAppleLocaleName(void);
char* DetectDefaultAppleLocaleName(void);
#endif

0 comments on commit 5f367d5

Please sign in to comment.