Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] HybridGlobalization Implement missing cases for GlobalizationNative_GetLocaleInfoString #89296

Merged
merged 17 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static IEnumerable<object[]> EnglishName_TestData()
{
yield return new object[] { CultureInfo.CurrentCulture.Name, CultureInfo.CurrentCulture.EnglishName };

if (SupportFullGlobalizationData)
if (SupportFullGlobalizationData || PlatformDetection.IsHybridGlobalizationOnOSX)
{
yield return new object[] { "en-US", "English (United States)" };
yield return new object[] { "fr-FR", "French (France)" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ public static IEnumerable<object[]> NativeName_TestData()
yield return new object[] { CultureInfo.CurrentCulture.Name, CultureInfo.CurrentCulture.NativeName };

// Android has its own ICU, which doesn't 100% map to UsingLimitedCultures
if (PlatformDetection.IsNotUsingLimitedCultures || PlatformDetection.IsAndroid)
if (PlatformDetection.IsNotUsingLimitedCultures || PlatformDetection.IsAndroid || PlatformDetection.IsHybridGlobalizationOnOSX)
{
yield return new object[] { "en-US", "English (United States)" };
yield return new object[] { "en-CA", "English (Canada)" };
yield return new object[] { "en-GB", "English (United Kingdom)" };
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;
using System.Collections.Generic;

namespace System.Globalization.Tests
{
public class CultureInfoThreeLetterISOInfo
{
public static IEnumerable<object[]> RegionInfo_TestData()
{
yield return new object[] { 0x409, 244, "en-US", "USA", "eng" };
yield return new object[] { 0x411, 122, "ja-JP", "JPN", "jpn" };
yield return new object[] { 0x804, 45, "zh-CN", "CHN", "zho" };
yield return new object[] { 0x401, 205, "ar-SA", "SAU", "ara" };
yield return new object[] { 0x412, 134, "ko-KR", "KOR", "kor" };
yield return new object[] { 0x40d, 117, "he-IL", "ISR", "heb" };
}

[Theory]
[MemberData(nameof(RegionInfo_TestData))]
public void MiscTest(int lcid, int geoId, string name, string threeLetterISORegionName, string threeLetterISOLanguageName)
{
RegionInfo ri = new RegionInfo(lcid); // create it with lcid
Assert.Equal(geoId, ri.GeoId);
Assert.Equal(threeLetterISORegionName, ri.ThreeLetterISORegionName);
Assert.Equal(threeLetterISOLanguageName, new CultureInfo(name).ThreeLetterISOLanguageName);
}
}
}
48 changes: 0 additions & 48 deletions src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,44 @@
<HybridGlobalization>true</HybridGlobalization>
</PropertyGroup>
<ItemGroup>
<Compile Include="HybridMode.cs" />
<Compile Include="..\CultureInfo\CultureInfoEnglishName.cs" />
<Compile Include="..\CultureInfo\CultureInfoNumberFormat.cs" />
<Compile Include="..\CultureInfo\CultureInfoNames.cs" />
<Compile Include="..\CultureInfo\CultureInfoNativeName.cs" />
<Compile Include="..\CultureInfo\CultureInfoParent.cs" />
<Compile Include="..\CultureInfo\CultureInfoThreeLetterISOInfo.cs" />
<Compile Include="..\CultureInfo\CultureInfoTwoLetterISOLanguageName.cs" />
<Compile Include="..\CompareInfo\CompareInfoTestsBase.cs" />
<Compile Include="..\CompareInfo\CompareInfoTests.Compare.cs" />
<Compile Include="..\CompareInfo\CompareInfoTests.IndexOf.cs" />
<Compile Include="..\CompareInfo\CompareInfoTests.IsPrefix.cs" />
<Compile Include="..\CompareInfo\CompareInfoTests.IsSuffix.cs" />
<Compile Include="..\CompareInfo\CompareInfoTests.LastIndexOf.cs" />
<Compile Include="..\DateTimeFormatInfo\DateTimeFormatInfoCalendarWeekRule.cs" />
<Compile Include="..\DateTimeFormatInfo\DateTimeFormatInfoData.cs" />
<Compile Include="..\DateTimeFormatInfo\DateTimeFormatInfoFirstDayOfWeek.cs" />
<Compile Include="..\DateTimeFormatInfo\DateTimeFormatInfoCalendarWeekRule.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoValidateParseStyle.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoData.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoCurrencySymbol.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoData.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoNaNSymbol.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPercentGroupSeparator.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPercentDecimalSeparator.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPercentDecimalDigits.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPerMilleSymbol.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPercentSymbol.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPositiveSign.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPositiveInfinitySymbol.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoNegativeSign.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoNegativeInfinitySymbol.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoNumberGroupSeparator.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoNumberDecimalSeparator.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoNegativeSign.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoNumberDecimalDigits.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoNumberDecimalSeparator.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoNumberGroupSeparator.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoNumberGroupSizes.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoNumberNegativePattern.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPercentNegativePattern.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPercentDecimalDigits.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPercentDecimalSeparator.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPercentGroupSeparator.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPercentGroupSizes.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPercentNegativePattern.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPercentPositivePattern.cs" />
<Compile Include="..\CompareInfo\CompareInfoTestsBase.cs" />
<Compile Include="..\CompareInfo\CompareInfoTests.Compare.cs" />
<Compile Include="..\CompareInfo\CompareInfoTests.IndexOf.cs" />
<Compile Include="..\CompareInfo\CompareInfoTests.LastIndexOf.cs" />
<Compile Include="..\CompareInfo\CompareInfoTests.IsPrefix.cs" />
<Compile Include="..\CompareInfo\CompareInfoTests.IsSuffix.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPercentSymbol.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPerMilleSymbol.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPositiveInfinitySymbol.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoPositiveSign.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoTests.cs" />
<Compile Include="..\NumberFormatInfo\NumberFormatInfoValidateParseStyle.cs" />
<Compile Include="..\System\Globalization\TextInfoTests.cs" />
</ItemGroup>
</Project>
93 changes: 83 additions & 10 deletions src/native/libs/System.Globalization.Native/pal_locale.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

#include <stdlib.h>
#include <string.h>
#include "pal_locale_internal.h"
#include "pal_localeStringData.h"
#include "pal_localeNumberData.h"
Expand Down Expand Up @@ -41,6 +42,50 @@
return strdup(value);
}

/**
* Useful constant for the maximum size of the whole locale ID
* (including the terminating NULL and all keywords).
*/
#define FULLNAME_CAPACITY 157

static void GetParent(const char* localeID, char* parent, int32_t parentCapacity)
{
const char *lastUnderscore;
int32_t i;

if (localeID == NULL)
localeID = [NSLocale systemLocale].localeIdentifier.UTF8String;

lastUnderscore = strrchr(localeID, '-');
if (lastUnderscore != NULL)
{
i = (int32_t)(lastUnderscore - localeID);
}
else
{
i = 0;
}

if (i > 0)
{
// primary lang subtag und (undefined).
if (strncasecmp(localeID, "und-", 4) == 0)
{
localeID += 3;
i -= 3;
memmove(parent, localeID, MIN(i, parentCapacity));
}
else if (parent != localeID)
{
memcpy(parent, localeID, MIN(i, parentCapacity));
}
}

// terminate chars
if (i >= 0 && i < parentCapacity)
parent[i] = 0;
}

const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData)
{
const char* value;
Expand Down Expand Up @@ -89,6 +134,16 @@
value = [currentLocale.decimalSeparator UTF8String];
// or value = [[currentLocale objectForKey:NSLocaleDecimalSeparator] UTF8String];
break;
case LocaleString_Digits:
{
NSString *digitsString = @"0123456789";
NSNumberFormatter *nf1 = [[NSNumberFormatter alloc] init];
[nf1 setLocale:currentLocale];

NSNumber *newNum = [nf1 numberFromString:digitsString];
value = [[newNum stringValue] UTF8String];
break;
}
case LocaleString_MonetarySymbol:
value = [currentLocale.currencySymbol UTF8String];
break;
Expand All @@ -102,6 +157,12 @@
case LocaleString_CurrencyNativeName:
value = [[currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode] UTF8String];
break;
case LocaleString_MonetaryDecimalSeparator:
value = [numberFormatter.currencyDecimalSeparator UTF8String];
break;
case LocaleString_MonetaryThousandSeparator:
value = [numberFormatter.currencyGroupingSeparator UTF8String];
break;
case LocaleString_AMDesignator:
value = [dateFormatter.AMSymbol UTF8String];
break;
Expand All @@ -115,12 +176,23 @@
value = [numberFormatter.minusSign UTF8String];
break;
case LocaleString_Iso639LanguageTwoLetterName:
// check if this is correct
value = [[currentLocale objectForKey:NSLocaleLanguageCode] UTF8String];
break;
case LocaleString_Iso639LanguageThreeLetterName:
{
NSString *iso639_2 = [currentLocale objectForKey:NSLocaleLanguageCode];
value = uloc_getISO3LanguageByLangCode([iso639_2 UTF8String]);
break;
}
case LocaleString_Iso3166CountryName:
value = [currentLocale.countryCode UTF8String];
value = [[currentLocale objectForKey:NSLocaleCountryCode] UTF8String];
break;
case LocaleString_Iso3166CountryName2:
{
const char *countryCode = strdup([[currentLocale objectForKey:NSLocaleCountryCode] UTF8String]);
value = uloc_getISO3CountryByCountryCode(countryCode);
break;
}
case LocaleString_NaNSymbol:
value = [numberFormatter.notANumberSymbol UTF8String];
break;
Expand All @@ -136,19 +208,20 @@
case LocaleString_PerMilleSymbol:
value = [numberFormatter.perMillSymbol UTF8String];
break;
// TODO find mapping for below cases
// https://github.com/dotnet/runtime/issues/83514
case LocaleString_Digits:
case LocaleString_MonetaryDecimalSeparator:
case LocaleString_MonetaryThousandSeparator:
case LocaleString_Iso639LanguageThreeLetterName:
case LocaleString_ParentName:
case LocaleString_Iso3166CountryName2:
{
char localeNameTemp[FULLNAME_CAPACITY];
const char* lName = [currentLocale.localeIdentifier UTF8String];
GetParent(lName, localeNameTemp, FULLNAME_CAPACITY);
value = strdup(localeNameTemp);
break;
}
default:
value = "";
break;
}
return strdup(value);

return value ? strdup(value) : "";
}

// invariant character definitions
Expand Down