From 5ac94619c584cb1f7d157bd81c64840262b2393b Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 20 Jul 2023 16:37:19 +0200 Subject: [PATCH 01/12] Cahnges to return missing locale properties --- .../CultureInfo/CultureInfoNativeName.cs | 3 +- .../CultureInfoThreeLetterISOInfo.cs | 31 + .../System.Globalization.IOS.Tests.csproj | 5 + .../System/Globalization/RegionInfoTests.cs | 7 +- .../src/System/Globalization/CultureData.cs | 2 +- .../System.Globalization.Native/pal_locale.m | 581 +++++++++++++++++- 6 files changed, 616 insertions(+), 13 deletions(-) create mode 100644 src/libraries/System.Globalization/tests/CultureInfo/CultureInfoThreeLetterISOInfo.cs diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs index 8293613177688c..35ecb0039df563 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs @@ -13,10 +13,11 @@ public static IEnumerable 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 { diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoThreeLetterISOInfo.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoThreeLetterISOInfo.cs new file mode 100644 index 00000000000000..cc23d2b5dfb0b8 --- /dev/null +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoThreeLetterISOInfo.cs @@ -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 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); + } + } +} diff --git a/src/libraries/System.Globalization/tests/Hybrid/System.Globalization.IOS.Tests.csproj b/src/libraries/System.Globalization/tests/Hybrid/System.Globalization.IOS.Tests.csproj index da9a1a79c18f02..9581d3429a5fb8 100644 --- a/src/libraries/System.Globalization/tests/Hybrid/System.Globalization.IOS.Tests.csproj +++ b/src/libraries/System.Globalization/tests/Hybrid/System.Globalization.IOS.Tests.csproj @@ -6,8 +6,13 @@ + + + + + diff --git a/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs b/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs index 6fd30317d7f06b..fcae8e9928597e 100644 --- a/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs +++ b/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs @@ -5,7 +5,6 @@ using System.Diagnostics; using System.Linq; using System.Tests; -using Microsoft.DotNet.RemoteExecutor; using Xunit; namespace System.Globalization.Tests @@ -63,7 +62,7 @@ public void CurrentRegion_Unix() } } - [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + /*[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [PlatformSpecific(TestPlatforms.Windows)] public void CurrentRegion_Windows() { @@ -95,7 +94,7 @@ public void ValidateUsingCasedRegionName(string regionName) string expectedName = new RegionInfo(name.ToUpperInvariant()).Name; Assert.Equal(expectedName, resultedName); }, regionName).Dispose(); - } + }*/ [Theory] [InlineData("en-US", "United States")] @@ -219,7 +218,7 @@ public void MiscTest(int lcid, int geoId, string currencyEnglishName, string cur Assert.Equal(geoId, ri.GeoId); // Android has its own ICU, which doesn't 100% map to UsingLimitedCultures - if (PlatformDetection.IsUsingLimitedCultures && !PlatformDetection.IsAndroid) + if (PlatformDetection.IsUsingLimitedCultures && !PlatformDetection.IsAndroid && !PlatformDetection.IsHybridGlobalizationOnOSX) { Assert.Equal(currencyShortName, ri.CurrencyEnglishName); Assert.Equal(currencyShortName, ri.CurrencyNativeName); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs index 0aa517ef6990f7..088dcfe2e8bc4f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -2360,7 +2360,7 @@ private string GetLocaleInfoCore(string localeName, LocaleStringData type, strin return GlobalizationMode.UseNls ? NlsGetLocaleInfo(localeName, type) : IcuGetLocaleInfo(localeName, type, uiCultureName); #endif } - +// private int[] GetLocaleInfoCoreUserOverride(LocaleGroupingData type) { // This is never reached but helps illinker statically remove dependencies diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index fb4e2ab9db7e48..252d662601ed70 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. #include +#include +#include #include "pal_locale_internal.h" #include "pal_localeStringData.h" #include "pal_localeNumberData.h" @@ -41,6 +43,541 @@ return strdup(value); } +/** + * NUL-terminate a string no matter what its type. + * Set warning and error codes accordingly. + */ +#define __TERMINATE_STRING(dest, destCapacity, length) { \ + if(length<0) { \ + /* assume that the caller handles this */ \ + } else if(length 0) { + // primary lang subtag und (undefined). + if (strnicmp(localeID, "und-", 4) == 0) { + localeID += 3; + i -= 3; + memmove(parent, localeID, MIN(i, parentCapacity)); + } else if (parent != localeID) { + memcpy(parent, localeID, MIN(i, parentCapacity)); + } + } + + return TerminateChars(parent, parentCapacity, i); +} + +/* ### Data tables **************************************************/ + +/** + * Table of language codes, both 2- and 3-letter, with preference + * given to 2-letter codes where possible. Includes 3-letter codes + * that lack a 2-letter equivalent. + * + * This list must be in sorted order. This list is returned directly + * to the user by some API. + * + * This list must be kept in sync with LANGUAGES_3, with corresponding + * entries matched. + * + * This table should be terminated with a NULL entry, followed by a + * second list, and another NULL entry. The first list is visible to + * user code when this array is returned by API. The second list + * contains codes we support, but do not expose through user API. + * + * Notes + * + * Tables updated per http://lcweb.loc.gov/standards/iso639-2/ to + * include the revisions up to 2001/7/27 *CWB* + * + * The 3 character codes are the terminology codes like RFC 3066. This + * is compatible with prior ICU codes + * + * "in" "iw" "ji" "jw" & "sh" have been withdrawn but are still in the + * table but now at the end of the table because 3 character codes are + * duplicates. This avoids bad searches going from 3 to 2 character + * codes. + * + * The range qaa-qtz is reserved for local use + */ +/* Generated using org.unicode.cldr.icu.GenerateISO639LanguageTables */ +/* ISO639 table version is 20150505 */ +/* Subsequent hand addition of selected languages */ +static const char * const LANGUAGES[] = { + "aa", "ab", "ace", "ach", "ada", "ady", "ae", "aeb", + "af", "afh", "agq", "ain", "ak", "akk", "akz", "ale", + "aln", "alt", "am", "an", "ang", "anp", "ar", "arc", + "arn", "aro", "arp", "arq", "ars", "arw", "ary", "arz", "as", + "asa", "ase", "ast", "av", "avk", "awa", "ay", "az", + "ba", "bal", "ban", "bar", "bas", "bax", "bbc", "bbj", + "be", "bej", "bem", "bew", "bez", "bfd", "bfq", "bg", + "bgc", "bgn", "bho", "bi", "bik", "bin", "bjn", "bkm", "bla", + "bm", "bn", "bo", "bpy", "bqi", "br", "bra", "brh", + "brx", "bs", "bss", "bua", "bug", "bum", "byn", "byv", + "ca", "cad", "car", "cay", "cch", "ccp", "ce", "ceb", "cgg", + "ch", "chb", "chg", "chk", "chm", "chn", "cho", "chp", + "chr", "chy", "ckb", "co", "cop", "cps", "cr", "crh", + "cs", "csb", "cu", "cv", "cy", + "da", "dak", "dar", "dav", "de", "del", "den", "dgr", + "din", "dje", "doi", "dsb", "dtp", "dua", "dum", "dv", + "dyo", "dyu", "dz", "dzg", + "ebu", "ee", "efi", "egl", "egy", "eka", "el", "elx", + "en", "enm", "eo", "es", "esu", "et", "eu", "ewo", + "ext", + "fa", "fan", "fat", "ff", "fi", "fil", "fit", "fj", + "fo", "fon", "fr", "frc", "frm", "fro", "frp", "frr", + "frs", "fur", "fy", + "ga", "gaa", "gag", "gan", "gay", "gba", "gbz", "gd", + "gez", "gil", "gl", "glk", "gmh", "gn", "goh", "gom", + "gon", "gor", "got", "grb", "grc", "gsw", "gu", "guc", + "gur", "guz", "gv", "gwi", + "ha", "hai", "hak", "haw", "he", "hi", "hif", "hil", + "hit", "hmn", "ho", "hr", "hsb", "hsn", "ht", "hu", + "hup", "hy", "hz", + "ia", "iba", "ibb", "id", "ie", "ig", "ii", "ik", + "ilo", "inh", "io", "is", "it", "iu", "izh", + "ja", "jam", "jbo", "jgo", "jmc", "jpr", "jrb", "jut", + "jv", + "ka", "kaa", "kab", "kac", "kaj", "kam", "kaw", "kbd", + "kbl", "kcg", "kde", "kea", "ken", "kfo", "kg", "kgp", + "kha", "kho", "khq", "khw", "ki", "kiu", "kj", "kk", + "kkj", "kl", "kln", "km", "kmb", "kn", "ko", "koi", + "kok", "kos", "kpe", "kr", "krc", "kri", "krj", "krl", + "kru", "ks", "ksb", "ksf", "ksh", "ku", "kum", "kut", + "kv", "kw", "ky", + "la", "lad", "lag", "lah", "lam", "lb", "lez", "lfn", + "lg", "li", "lij", "liv", "lkt", "lmo", "ln", "lo", + "lol", "loz", "lrc", "lt", "ltg", "lu", "lua", "lui", + "lun", "luo", "lus", "luy", "lv", "lzh", "lzz", + "mad", "maf", "mag", "mai", "mak", "man", "mas", "mde", + "mdf", "mdh", "mdr", "men", "mer", "mfe", "mg", "mga", + "mgh", "mgo", "mh", "mi", "mic", "min", "mis", "mk", + "ml", "mn", "mnc", "mni", + "moh", "mos", "mr", "mrj", + "ms", "mt", "mua", "mul", "mus", "mwl", "mwr", "mwv", + "my", "mye", "myv", "mzn", + "na", "nan", "nap", "naq", "nb", "nd", "nds", "ne", + "new", "ng", "nia", "niu", "njo", "nl", "nmg", "nn", + "nnh", "no", "nog", "non", "nov", "nqo", "nr", "nso", + "nus", "nv", "nwc", "ny", "nym", "nyn", "nyo", "nzi", + "oc", "oj", "om", "or", "os", "osa", "ota", + "pa", "pag", "pal", "pam", "pap", "pau", "pcd", "pcm", "pdc", + "pdt", "peo", "pfl", "phn", "pi", "pl", "pms", "pnt", + "pon", "prg", "pro", "ps", "pt", + "qu", "quc", "qug", + "raj", "rap", "rar", "rgn", "rif", "rm", "rn", "ro", + "rof", "rom", "rtm", "ru", "rue", "rug", "rup", + "rw", "rwk", + "sa", "sad", "sah", "sam", "saq", "sas", "sat", "saz", + "sba", "sbp", "sc", "scn", "sco", "sd", "sdc", "sdh", + "se", "see", "seh", "sei", "sel", "ses", "sg", "sga", + "sgs", "shi", "shn", "shu", "si", "sid", "sk", + "sl", "sli", "sly", "sm", "sma", "smj", "smn", "sms", + "sn", "snk", "so", "sog", "sq", "sr", "srn", "srr", + "ss", "ssy", "st", "stq", "su", "suk", "sus", "sux", + "sv", "sw", "swb", "syc", "syr", "szl", + "ta", "tcy", "te", "tem", "teo", "ter", "tet", "tg", + "th", "ti", "tig", "tiv", "tk", "tkl", "tkr", + "tlh", "tli", "tly", "tmh", "tn", "to", "tog", "tpi", + "tr", "tru", "trv", "ts", "tsd", "tsi", "tt", "ttt", + "tum", "tvl", "tw", "twq", "ty", "tyv", "tzm", + "udm", "ug", "uga", "uk", "umb", "und", "ur", "uz", + "vai", "ve", "vec", "vep", "vi", "vls", "vmf", "vo", + "vot", "vro", "vun", + "wa", "wae", "wal", "war", "was", "wbp", "wo", "wuu", + "xal", "xh", "xmf", "xog", + "yao", "yap", "yav", "ybb", "yi", "yo", "yrl", "yue", + "za", "zap", "zbl", "zea", "zen", "zgh", "zh", "zu", + "zun", "zxx", "zza", +NULL, + "in", "iw", "ji", "jw", "mo", "sh", "swc", "tl", /* obsolete language codes */ +NULL +}; + +static const char* const DEPRECATED_LANGUAGES[]={ + "in", "iw", "ji", "jw", "mo", NULL, NULL +}; +static const char* const REPLACEMENT_LANGUAGES[]={ + "id", "he", "yi", "jv", "ro", NULL, NULL +}; + +/** + * Table of 3-letter language codes. + * + * This is a lookup table used to convert 3-letter language codes to + * their 2-letter equivalent, where possible. It must be kept in sync + * with LANGUAGES. For all valid i, LANGUAGES[i] must refer to the + * same language as LANGUAGES_3[i]. The commented-out lines are + * copied from LANGUAGES to make eyeballing this baby easier. + * + * Where a 3-letter language code has no 2-letter equivalent, the + * 3-letter code occupies both LANGUAGES[i] and LANGUAGES_3[i]. + * + * This table should be terminated with a NULL entry, followed by a + * second list, and another NULL entry. The two lists correspond to + * the two lists in LANGUAGES. + */ +/* Generated using org.unicode.cldr.icu.GenerateISO639LanguageTables */ +/* ISO639 table version is 20150505 */ +/* Subsequent hand addition of selected languages */ +static const char * const LANGUAGES_3[] = { + "aar", "abk", "ace", "ach", "ada", "ady", "ave", "aeb", + "afr", "afh", "agq", "ain", "aka", "akk", "akz", "ale", + "aln", "alt", "amh", "arg", "ang", "anp", "ara", "arc", + "arn", "aro", "arp", "arq", "ars", "arw", "ary", "arz", "asm", + "asa", "ase", "ast", "ava", "avk", "awa", "aym", "aze", + "bak", "bal", "ban", "bar", "bas", "bax", "bbc", "bbj", + "bel", "bej", "bem", "bew", "bez", "bfd", "bfq", "bul", + "bgc", "bgn", "bho", "bis", "bik", "bin", "bjn", "bkm", "bla", + "bam", "ben", "bod", "bpy", "bqi", "bre", "bra", "brh", + "brx", "bos", "bss", "bua", "bug", "bum", "byn", "byv", + "cat", "cad", "car", "cay", "cch", "ccp", "che", "ceb", "cgg", + "cha", "chb", "chg", "chk", "chm", "chn", "cho", "chp", + "chr", "chy", "ckb", "cos", "cop", "cps", "cre", "crh", + "ces", "csb", "chu", "chv", "cym", + "dan", "dak", "dar", "dav", "deu", "del", "den", "dgr", + "din", "dje", "doi", "dsb", "dtp", "dua", "dum", "div", + "dyo", "dyu", "dzo", "dzg", + "ebu", "ewe", "efi", "egl", "egy", "eka", "ell", "elx", + "eng", "enm", "epo", "spa", "esu", "est", "eus", "ewo", + "ext", + "fas", "fan", "fat", "ful", "fin", "fil", "fit", "fij", + "fao", "fon", "fra", "frc", "frm", "fro", "frp", "frr", + "frs", "fur", "fry", + "gle", "gaa", "gag", "gan", "gay", "gba", "gbz", "gla", + "gez", "gil", "glg", "glk", "gmh", "grn", "goh", "gom", + "gon", "gor", "got", "grb", "grc", "gsw", "guj", "guc", + "gur", "guz", "glv", "gwi", + "hau", "hai", "hak", "haw", "heb", "hin", "hif", "hil", + "hit", "hmn", "hmo", "hrv", "hsb", "hsn", "hat", "hun", + "hup", "hye", "her", + "ina", "iba", "ibb", "ind", "ile", "ibo", "iii", "ipk", + "ilo", "inh", "ido", "isl", "ita", "iku", "izh", + "jpn", "jam", "jbo", "jgo", "jmc", "jpr", "jrb", "jut", + "jav", + "kat", "kaa", "kab", "kac", "kaj", "kam", "kaw", "kbd", + "kbl", "kcg", "kde", "kea", "ken", "kfo", "kon", "kgp", + "kha", "kho", "khq", "khw", "kik", "kiu", "kua", "kaz", + "kkj", "kal", "kln", "khm", "kmb", "kan", "kor", "koi", + "kok", "kos", "kpe", "kau", "krc", "kri", "krj", "krl", + "kru", "kas", "ksb", "ksf", "ksh", "kur", "kum", "kut", + "kom", "cor", "kir", + "lat", "lad", "lag", "lah", "lam", "ltz", "lez", "lfn", + "lug", "lim", "lij", "liv", "lkt", "lmo", "lin", "lao", + "lol", "loz", "lrc", "lit", "ltg", "lub", "lua", "lui", + "lun", "luo", "lus", "luy", "lav", "lzh", "lzz", + "mad", "maf", "mag", "mai", "mak", "man", "mas", "mde", + "mdf", "mdh", "mdr", "men", "mer", "mfe", "mlg", "mga", + "mgh", "mgo", "mah", "mri", "mic", "min", "mis", "mkd", + "mal", "mon", "mnc", "mni", + "moh", "mos", "mar", "mrj", + "msa", "mlt", "mua", "mul", "mus", "mwl", "mwr", "mwv", + "mya", "mye", "myv", "mzn", + "nau", "nan", "nap", "naq", "nob", "nde", "nds", "nep", + "new", "ndo", "nia", "niu", "njo", "nld", "nmg", "nno", + "nnh", "nor", "nog", "non", "nov", "nqo", "nbl", "nso", + "nus", "nav", "nwc", "nya", "nym", "nyn", "nyo", "nzi", + "oci", "oji", "orm", "ori", "oss", "osa", "ota", + "pan", "pag", "pal", "pam", "pap", "pau", "pcd", "pcm", "pdc", + "pdt", "peo", "pfl", "phn", "pli", "pol", "pms", "pnt", + "pon", "prg", "pro", "pus", "por", + "que", "quc", "qug", + "raj", "rap", "rar", "rgn", "rif", "roh", "run", "ron", + "rof", "rom", "rtm", "rus", "rue", "rug", "rup", + "kin", "rwk", + "san", "sad", "sah", "sam", "saq", "sas", "sat", "saz", + "sba", "sbp", "srd", "scn", "sco", "snd", "sdc", "sdh", + "sme", "see", "seh", "sei", "sel", "ses", "sag", "sga", + "sgs", "shi", "shn", "shu", "sin", "sid", "slk", + "slv", "sli", "sly", "smo", "sma", "smj", "smn", "sms", + "sna", "snk", "som", "sog", "sqi", "srp", "srn", "srr", + "ssw", "ssy", "sot", "stq", "sun", "suk", "sus", "sux", + "swe", "swa", "swb", "syc", "syr", "szl", + "tam", "tcy", "tel", "tem", "teo", "ter", "tet", "tgk", + "tha", "tir", "tig", "tiv", "tuk", "tkl", "tkr", + "tlh", "tli", "tly", "tmh", "tsn", "ton", "tog", "tpi", + "tur", "tru", "trv", "tso", "tsd", "tsi", "tat", "ttt", + "tum", "tvl", "twi", "twq", "tah", "tyv", "tzm", + "udm", "uig", "uga", "ukr", "umb", "und", "urd", "uzb", + "vai", "ven", "vec", "vep", "vie", "vls", "vmf", "vol", + "vot", "vro", "vun", + "wln", "wae", "wal", "war", "was", "wbp", "wol", "wuu", + "xal", "xho", "xmf", "xog", + "yao", "yap", "yav", "ybb", "yid", "yor", "yrl", "yue", + "zha", "zap", "zbl", "zea", "zen", "zgh", "zho", "zul", + "zun", "zxx", "zza", +NULL, +/* "in", "iw", "ji", "jw", "mo", "sh", "swc", "tl", */ + "ind", "heb", "yid", "jaw", "mol", "srp", "swc", "tgl", +NULL +}; + +/** + * Table of 2-letter country codes. + * + * This list must be in sorted order. This list is returned directly + * to the user by some API. + * + * This list must be kept in sync with COUNTRIES_3, with corresponding + * entries matched. + * + * This table should be terminated with a NULL entry, followed by a + * second list, and another NULL entry. The first list is visible to + * user code when this array is returned by API. The second list + * contains codes we support, but do not expose through user API. + * + * Notes: + * + * ZR(ZAR) is now CD(COD) and FX(FXX) is PS(PSE) as per + * http://www.evertype.com/standards/iso3166/iso3166-1-en.html added + * new codes keeping the old ones for compatibility updated to include + * 1999/12/03 revisions *CWB* + * + * RO(ROM) is now RO(ROU) according to + * http://www.iso.org/iso/en/prods-services/iso3166ma/03updates-on-iso-3166/nlv3e-rou.html + */ +static const char * const COUNTRIES[] = { + "AD", "AE", "AF", "AG", "AI", "AL", "AM", + "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", + "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", + "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", + "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", + "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", + "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DG", "DJ", "DK", + "DM", "DO", "DZ", "EA", "EC", "EE", "EG", "EH", "ER", + "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", + "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", + "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", + "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", + "IC", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", + "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", + "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", + "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", + "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", + "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", + "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", + "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", + "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", + "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", + "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", + "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", + "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", + "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", + "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", + "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", + "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", + "WS", "XK", "YE", "YT", "ZA", "ZM", "ZW", +NULL, + "AN", "BU", "CS", "FX", "RO", "SU", "TP", "YD", "YU", "ZR", /* obsolete country codes */ +NULL +}; + +static const char* const DEPRECATED_COUNTRIES[] = { + "AN", "BU", "CS", "DD", "DY", "FX", "HV", "NH", "RH", "SU", "TP", "UK", "VD", "YD", "YU", "ZR", NULL, NULL /* deprecated country list */ +}; +static const char* const REPLACEMENT_COUNTRIES[] = { +/* "AN", "BU", "CS", "DD", "DY", "FX", "HV", "NH", "RH", "SU", "TP", "UK", "VD", "YD", "YU", "ZR" */ + "CW", "MM", "RS", "DE", "BJ", "FR", "BF", "VU", "ZW", "RU", "TL", "GB", "VN", "YE", "RS", "CD", NULL, NULL /* replacement country codes */ +}; + +/** + * Table of 3-letter country codes. + * + * This is a lookup table used to convert 3-letter country codes to + * their 2-letter equivalent. It must be kept in sync with COUNTRIES. + * For all valid i, COUNTRIES[i] must refer to the same country as + * COUNTRIES_3[i]. The commented-out lines are copied from COUNTRIES + * to make eyeballing this baby easier. + * + * This table should be terminated with a NULL entry, followed by a + * second list, and another NULL entry. The two lists correspond to + * the two lists in COUNTRIES. + */ +static const char * const COUNTRIES_3[] = { +/* "AD", "AE", "AF", "AG", "AI", "AL", "AM", */ + "AND", "ARE", "AFG", "ATG", "AIA", "ALB", "ARM", +/* "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", */ + "AGO", "ATA", "ARG", "ASM", "AUT", "AUS", "ABW", "ALA", "AZE", +/* "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", */ + "BIH", "BRB", "BGD", "BEL", "BFA", "BGR", "BHR", "BDI", +/* "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", */ + "BEN", "BLM", "BMU", "BRN", "BOL", "BES", "BRA", "BHS", "BTN", "BVT", +/* "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", */ + "BWA", "BLR", "BLZ", "CAN", "CCK", "COD", "CAF", "COG", +/* "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", */ + "CHE", "CIV", "COK", "CHL", "CMR", "CHN", "COL", "CRI", +/* "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DG", "DJ", "DK", */ + "CUB", "CPV", "CUW", "CXR", "CYP", "CZE", "DEU", "DGA", "DJI", "DNK", +/* "DM", "DO", "DZ", "EA", "EC", "EE", "EG", "EH", "ER", */ + "DMA", "DOM", "DZA", "XEA", "ECU", "EST", "EGY", "ESH", "ERI", +/* "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", */ + "ESP", "ETH", "FIN", "FJI", "FLK", "FSM", "FRO", "FRA", +/* "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", */ + "GAB", "GBR", "GRD", "GEO", "GUF", "GGY", "GHA", "GIB", "GRL", +/* "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", */ + "GMB", "GIN", "GLP", "GNQ", "GRC", "SGS", "GTM", "GUM", +/* "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", */ + "GNB", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN", +/* "IC", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS" */ + "XIC", "IDN", "IRL", "ISR", "IMN", "IND", "IOT", "IRQ", "IRN", "ISL", +/* "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", */ + "ITA", "JEY", "JAM", "JOR", "JPN", "KEN", "KGZ", "KHM", "KIR", +/* "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", */ + "COM", "KNA", "PRK", "KOR", "KWT", "CYM", "KAZ", "LAO", +/* "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", */ + "LBN", "LCA", "LIE", "LKA", "LBR", "LSO", "LTU", "LUX", +/* "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", */ + "LVA", "LBY", "MAR", "MCO", "MDA", "MNE", "MAF", "MDG", "MHL", "MKD", +/* "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", */ + "MLI", "MMR", "MNG", "MAC", "MNP", "MTQ", "MRT", "MSR", +/* "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", */ + "MLT", "MUS", "MDV", "MWI", "MEX", "MYS", "MOZ", "NAM", +/* "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", */ + "NCL", "NER", "NFK", "NGA", "NIC", "NLD", "NOR", "NPL", +/* "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", */ + "NRU", "NIU", "NZL", "OMN", "PAN", "PER", "PYF", "PNG", +/* "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", */ + "PHL", "PAK", "POL", "SPM", "PCN", "PRI", "PSE", "PRT", +/* "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", */ + "PLW", "PRY", "QAT", "REU", "ROU", "SRB", "RUS", "RWA", "SAU", +/* "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", */ + "SLB", "SYC", "SDN", "SWE", "SGP", "SHN", "SVN", "SJM", +/* "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", */ + "SVK", "SLE", "SMR", "SEN", "SOM", "SUR", "SSD", "STP", "SLV", +/* "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", */ + "SXM", "SYR", "SWZ", "TCA", "TCD", "ATF", "TGO", "THA", "TJK", +/* "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", */ + "TKL", "TLS", "TKM", "TUN", "TON", "TUR", "TTO", "TUV", +/* "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", */ + "TWN", "TZA", "UKR", "UGA", "UMI", "USA", "URY", "UZB", +/* "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", */ + "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", +/* "WS", "XK", "YE", "YT", "ZA", "ZM", "ZW", */ + "WSM", "XKK", "YEM", "MYT", "ZAF", "ZMB", "ZWE", +NULL, +/* "AN", "BU", "CS", "FX", "RO", "SU", "TP", "YD", "YU", "ZR" */ + "ANT", "BUR", "SCG", "FXX", "ROM", "SUN", "TMP", "YMD", "YUG", "ZAR", +NULL +}; + +/** + * Useful constant for the maximum size of the language part of a locale ID. + * (including the terminating NULL). + * @stable ICU 2.0 + */ +#define ULOC_LANG_CAPACITY 12 + +/** + * Lookup 'key' in the array 'list'. The array 'list' should contain + * a NULL entry, followed by more entries, and a second NULL entry. + * + * The 'list' param should be LANGUAGES, LANGUAGES_3, COUNTRIES, or + * COUNTRIES_3. + */ +static int16_t _findIndex(const char* const* list, const char* key) +{ + const char* const* anchor = list; + int32_t pass = 0; + + /* Make two passes through two NULL-terminated arrays at 'list' */ + while (pass++ < 2) { + while (*list) { + if (strcmp(key, *list) == 0) { + return (int16_t)(list - anchor); + } + list++; + } + ++list; /* skip final NULL *CWB*/ + } + return -1; +} + +static const char* GetISO3Country(const char* countryCode) +{ + int16_t offset = _findIndex(COUNTRIES, countryCode); + if (offset < 0) + return ""; + + return COUNTRIES_3[offset]; +} + +static const char* GetISO3Language(const char* languageCode) +{ + int16_t offset = _findIndex(LANGUAGES, languageCode); + if (offset < 0) + return ""; + return LANGUAGES_3[offset]; +} + const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData) { const char* value; @@ -114,13 +651,6 @@ case LocaleString_NegativeSign: value = [numberFormatter.minusSign UTF8String]; break; - case LocaleString_Iso639LanguageTwoLetterName: - // check if this is correct - value = [[currentLocale objectForKey:NSLocaleLanguageCode] UTF8String]; - break; - case LocaleString_Iso3166CountryName: - value = [currentLocale.countryCode UTF8String]; - break; case LocaleString_NaNSymbol: value = [numberFormatter.notANumberSymbol UTF8String]; break; @@ -136,18 +666,55 @@ case LocaleString_PerMilleSymbol: value = [numberFormatter.perMillSymbol UTF8String]; break; + case LocaleString_Iso639LanguageTwoLetterName: + value = [[currentLocale objectForKey:NSLocaleLanguageCode] UTF8String]; + break; + case LocaleString_Iso3166CountryName: + value = [[currentLocale objectForKey:NSLocaleCountryCode] UTF8String]; + break; // TODO find mapping for below cases // https://github.com/dotnet/runtime/issues/83514 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_MonetaryDecimalSeparator: + value = [numberFormatter.currencyDecimalSeparator UTF8String]; + break; case LocaleString_MonetaryThousandSeparator: + value = [numberFormatter.currencyGroupingSeparator UTF8String]; + break; case LocaleString_Iso639LanguageThreeLetterName: + { + NSString *iso639_2 = [currentLocale objectForKey:NSLocaleLanguageCode]; + value = GetISO3Language([iso639_2 UTF8String]); + break; + } case LocaleString_ParentName: + { + char localeNameTemp[ULOC_FULLNAME_CAPACITY]; + const char* lName = [currentLocale.localeIdentifier UTF8String]; + GetParent(lName, localeNameTemp, ULOC_FULLNAME_CAPACITY); + value = strdup(localeNameTemp); + break; + } case LocaleString_Iso3166CountryName2: + { + const char *countryCode = strdup([[currentLocale objectForKey:NSLocaleCountryCode] UTF8String]); + value = GetISO3Country(countryCode); + break; + } default: value = ""; break; } + value = value ? value : ""; return strdup(value); } From 548e34a36b9c134c65e16ad1199461bd4db3e888 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Fri, 21 Jul 2023 13:26:27 +0200 Subject: [PATCH 02/12] Refactor functions --- .../System/Globalization/RegionInfoTests.cs | 7 ++- .../src/System/Globalization/CultureData.cs | 2 +- .../System.Globalization.Native/pal_locale.m | 55 +++++++------------ 3 files changed, 24 insertions(+), 40 deletions(-) diff --git a/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs b/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs index fcae8e9928597e..6fd30317d7f06b 100644 --- a/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs +++ b/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Linq; using System.Tests; +using Microsoft.DotNet.RemoteExecutor; using Xunit; namespace System.Globalization.Tests @@ -62,7 +63,7 @@ public void CurrentRegion_Unix() } } - /*[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [PlatformSpecific(TestPlatforms.Windows)] public void CurrentRegion_Windows() { @@ -94,7 +95,7 @@ public void ValidateUsingCasedRegionName(string regionName) string expectedName = new RegionInfo(name.ToUpperInvariant()).Name; Assert.Equal(expectedName, resultedName); }, regionName).Dispose(); - }*/ + } [Theory] [InlineData("en-US", "United States")] @@ -218,7 +219,7 @@ public void MiscTest(int lcid, int geoId, string currencyEnglishName, string cur Assert.Equal(geoId, ri.GeoId); // Android has its own ICU, which doesn't 100% map to UsingLimitedCultures - if (PlatformDetection.IsUsingLimitedCultures && !PlatformDetection.IsAndroid && !PlatformDetection.IsHybridGlobalizationOnOSX) + if (PlatformDetection.IsUsingLimitedCultures && !PlatformDetection.IsAndroid) { Assert.Equal(currencyShortName, ri.CurrencyEnglishName); Assert.Equal(currencyShortName, ri.CurrencyNativeName); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs index 088dcfe2e8bc4f..0aa517ef6990f7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -2360,7 +2360,7 @@ private string GetLocaleInfoCore(string localeName, LocaleStringData type, strin return GlobalizationMode.UseNls ? NlsGetLocaleInfo(localeName, type) : IcuGetLocaleInfo(localeName, type, uiCultureName); #endif } -// + private int[] GetLocaleInfoCoreUserOverride(LocaleGroupingData type) { // This is never reached but helps illinker statically remove dependencies diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 252d662601ed70..3db97ff76e60cb 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -43,59 +43,41 @@ return strdup(value); } -/** - * NUL-terminate a string no matter what its type. - * Set warning and error codes accordingly. - */ -#define __TERMINATE_STRING(dest, destCapacity, length) { \ - if(length<0) { \ - /* assume that the caller handles this */ \ - } else if(length= 0 && i < parentCapacity) + parent[i] = 0; + + return i; } /* ### Data tables **************************************************/ @@ -532,7 +518,6 @@ int32_t static GetParent(const char* localeID, char* parent, int32_t parentCapac /** * Useful constant for the maximum size of the language part of a locale ID. * (including the terminating NULL). - * @stable ICU 2.0 */ #define ULOC_LANG_CAPACITY 12 @@ -672,8 +657,6 @@ static int16_t _findIndex(const char* const* list, const char* key) case LocaleString_Iso3166CountryName: value = [[currentLocale objectForKey:NSLocaleCountryCode] UTF8String]; break; - // TODO find mapping for below cases - // https://github.com/dotnet/runtime/issues/83514 case LocaleString_Digits: { NSString *digitsString = @"0123456789"; @@ -698,9 +681,9 @@ static int16_t _findIndex(const char* const* list, const char* key) } case LocaleString_ParentName: { - char localeNameTemp[ULOC_FULLNAME_CAPACITY]; + char localeNameTemp[FULLNAME_CAPACITY]; const char* lName = [currentLocale.localeIdentifier UTF8String]; - GetParent(lName, localeNameTemp, ULOC_FULLNAME_CAPACITY); + GetParent(lName, localeNameTemp, FULLNAME_CAPACITY); value = strdup(localeNameTemp); break; } From a8976ccdb161dbf9ab79753cf2d36173913c8754 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Fri, 21 Jul 2023 14:16:45 +0200 Subject: [PATCH 03/12] Order test files and add EnglishName tests --- .../CultureInfo/CultureInfoEnglishName.cs | 2 +- .../tests/Hybrid/HybridMode.cs | 48 ------------------ .../System.Globalization.IOS.Tests.csproj | 50 +++++++++---------- .../System.Globalization.Native/pal_locale.m | 8 +-- 4 files changed, 30 insertions(+), 78 deletions(-) delete mode 100644 src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs index 67a19e61401164..a1b5cf9445caa7 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs @@ -15,7 +15,7 @@ public static IEnumerable 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)" }; diff --git a/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs b/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs deleted file mode 100644 index f5443f8c2c3c01..00000000000000 --- a/src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; -using Xunit; - -namespace System.Globalization.Tests -{ - public class HybridModeTests - { - public static IEnumerable EnglishName_TestData() - { - yield return new object[] { "en-US", "English (United States)" }; - yield return new object[] { "fr-FR", "French (France)" }; - } - - public static IEnumerable NativeName_TestData() - { - yield return new object[] { "en-US", "English (United States)" }; - yield return new object[] { "fr-FR", "français (France)" }; - yield return new object[] { "en-CA", "English (Canada)" }; - } - - [Theory] - [MemberData(nameof(EnglishName_TestData))] - public void TestEnglishName(string cultureName, string expected) - { - CultureInfo myTestCulture = new CultureInfo(cultureName); - Assert.Equal(expected, myTestCulture.EnglishName); - } - - [Theory] - [MemberData(nameof(NativeName_TestData))] - public void TestNativeName(string cultureName, string expected) - { - CultureInfo myTestCulture = new CultureInfo(cultureName); - Assert.Equal(expected, myTestCulture.NativeName); - } - - [Theory] - [InlineData("de-DE", "de")] - [InlineData("en-US", "en")] - public void TwoLetterISOLanguageName(string name, string expected) - { - Assert.Equal(expected, new CultureInfo(name).TwoLetterISOLanguageName); - } - } -} diff --git a/src/libraries/System.Globalization/tests/Hybrid/System.Globalization.IOS.Tests.csproj b/src/libraries/System.Globalization/tests/Hybrid/System.Globalization.IOS.Tests.csproj index 9581d3429a5fb8..f21ff6dafff2b8 100644 --- a/src/libraries/System.Globalization/tests/Hybrid/System.Globalization.IOS.Tests.csproj +++ b/src/libraries/System.Globalization/tests/Hybrid/System.Globalization.IOS.Tests.csproj @@ -5,44 +5,44 @@ true - - - - + - + + + + + + + + + + - - - + - - - - - - - - - - + + + - + + + + - - - - - - + + + + + + diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 3db97ff76e60cb..1830672f23ba17 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -89,7 +89,7 @@ int static strnicmp(const char *str1, const char *str2, uint32_t n) { return 0; } -int32_t static GetParent(const char* localeID, char* parent, int32_t parentCapacity) +void static GetParent(const char* localeID, char* parent, int32_t parentCapacity) { const char *lastUnderscore; int32_t i; @@ -119,7 +119,7 @@ int32_t static GetParent(const char* localeID, char* parent, int32_t parentCapac if (i >= 0 && i < parentCapacity) parent[i] = 0; - return i; + return; } /* ### Data tables **************************************************/ @@ -697,8 +697,8 @@ static int16_t _findIndex(const char* const* list, const char* key) value = ""; break; } - value = value ? value : ""; - return strdup(value); + + return value ? strdup(value) : ""; } // invariant character definitions From f17d8c03a6a316ec7c708488cf74240fc58281bf Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 24 Jul 2023 13:55:23 +0200 Subject: [PATCH 04/12] update order of LocaleStringData cases --- .../System.Globalization.Native/pal_locale.m | 69 +++++++++---------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 1830672f23ba17..85bf92427ab115 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. #include -#include #include #include "pal_locale_internal.h" #include "pal_localeStringData.h" @@ -611,6 +610,16 @@ static int16_t _findIndex(const char* const* list, const char* key) 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; @@ -624,6 +633,12 @@ static int16_t _findIndex(const char* const* list, const char* key) 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; @@ -636,6 +651,24 @@ static int16_t _findIndex(const char* const* list, const char* key) case LocaleString_NegativeSign: value = [numberFormatter.minusSign UTF8String]; break; + case LocaleString_Iso639LanguageTwoLetterName: + value = [[currentLocale objectForKey:NSLocaleLanguageCode] UTF8String]; + break; + case LocaleString_Iso639LanguageThreeLetterName: + { + NSString *iso639_2 = [currentLocale objectForKey:NSLocaleLanguageCode]; + value = GetISO3Language([iso639_2 UTF8String]); + break; + } + case LocaleString_Iso3166CountryName: + value = [[currentLocale objectForKey:NSLocaleCountryCode] UTF8String]; + break; + case LocaleString_Iso3166CountryName2: + { + const char *countryCode = strdup([[currentLocale objectForKey:NSLocaleCountryCode] UTF8String]); + value = GetISO3Country(countryCode); + break; + } case LocaleString_NaNSymbol: value = [numberFormatter.notANumberSymbol UTF8String]; break; @@ -651,34 +684,6 @@ static int16_t _findIndex(const char* const* list, const char* key) case LocaleString_PerMilleSymbol: value = [numberFormatter.perMillSymbol UTF8String]; break; - case LocaleString_Iso639LanguageTwoLetterName: - value = [[currentLocale objectForKey:NSLocaleLanguageCode] UTF8String]; - break; - case LocaleString_Iso3166CountryName: - value = [[currentLocale objectForKey:NSLocaleCountryCode] 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_MonetaryDecimalSeparator: - value = [numberFormatter.currencyDecimalSeparator UTF8String]; - break; - case LocaleString_MonetaryThousandSeparator: - value = [numberFormatter.currencyGroupingSeparator UTF8String]; - break; - case LocaleString_Iso639LanguageThreeLetterName: - { - NSString *iso639_2 = [currentLocale objectForKey:NSLocaleLanguageCode]; - value = GetISO3Language([iso639_2 UTF8String]); - break; - } case LocaleString_ParentName: { char localeNameTemp[FULLNAME_CAPACITY]; @@ -687,12 +692,6 @@ static int16_t _findIndex(const char* const* list, const char* key) value = strdup(localeNameTemp); break; } - case LocaleString_Iso3166CountryName2: - { - const char *countryCode = strdup([[currentLocale objectForKey:NSLocaleCountryCode] UTF8String]); - value = GetISO3Country(countryCode); - break; - } default: value = ""; break; From f032d86e59f81e431a2e2ff8073c6a4bdfb9eca3 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 24 Jul 2023 13:59:13 +0200 Subject: [PATCH 05/12] clean up the code --- .../System.Globalization.Native/pal_locale.m | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 85bf92427ab115..569028607d0ece 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -248,13 +248,6 @@ void static GetParent(const char* localeID, char* parent, int32_t parentCapacity NULL }; -static const char* const DEPRECATED_LANGUAGES[]={ - "in", "iw", "ji", "jw", "mo", NULL, NULL -}; -static const char* const REPLACEMENT_LANGUAGES[]={ - "id", "he", "yi", "jv", "ro", NULL, NULL -}; - /** * Table of 3-letter language codes. * @@ -426,14 +419,6 @@ void static GetParent(const char* localeID, char* parent, int32_t parentCapacity NULL }; -static const char* const DEPRECATED_COUNTRIES[] = { - "AN", "BU", "CS", "DD", "DY", "FX", "HV", "NH", "RH", "SU", "TP", "UK", "VD", "YD", "YU", "ZR", NULL, NULL /* deprecated country list */ -}; -static const char* const REPLACEMENT_COUNTRIES[] = { -/* "AN", "BU", "CS", "DD", "DY", "FX", "HV", "NH", "RH", "SU", "TP", "UK", "VD", "YD", "YU", "ZR" */ - "CW", "MM", "RS", "DE", "BJ", "FR", "BF", "VU", "ZW", "RU", "TL", "GB", "VN", "YE", "RS", "CD", NULL, NULL /* replacement country codes */ -}; - /** * Table of 3-letter country codes. * @@ -514,12 +499,6 @@ void static GetParent(const char* localeID, char* parent, int32_t parentCapacity NULL }; -/** - * Useful constant for the maximum size of the language part of a locale ID. - * (including the terminating NULL). - */ -#define ULOC_LANG_CAPACITY 12 - /** * Lookup 'key' in the array 'list'. The array 'list' should contain * a NULL entry, followed by more entries, and a second NULL entry. From d800ae61ff6f27e383070a91c331738e5203218d Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 25 Jul 2023 09:47:20 +0200 Subject: [PATCH 06/12] add whitespace --- .../tests/CultureInfo/CultureInfoThreeLetterISOInfo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoThreeLetterISOInfo.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoThreeLetterISOInfo.cs index cc23d2b5dfb0b8..34324b7c347e2b 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoThreeLetterISOInfo.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoThreeLetterISOInfo.cs @@ -13,9 +13,9 @@ public static IEnumerable 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" }; + 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] From 8c53bf5e917452571a8e8cacd71001c90f7c5961 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 25 Jul 2023 14:08:28 +0200 Subject: [PATCH 07/12] use strncasecmp and minor refactorings --- .../CultureInfoThreeLetterISOInfo.cs | 2 +- .../System.Globalization.Native/pal_locale.m | 61 ++++--------------- 2 files changed, 14 insertions(+), 49 deletions(-) diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoThreeLetterISOInfo.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoThreeLetterISOInfo.cs index 34324b7c347e2b..4801d9d9d14287 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoThreeLetterISOInfo.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoThreeLetterISOInfo.cs @@ -20,7 +20,7 @@ public static IEnumerable RegionInfo_TestData() [Theory] [MemberData(nameof(RegionInfo_TestData))] - public void MiscTest(int lcid, int geoId,string name, string threeLetterISORegionName, string threeLetterISOLanguageName) + 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); diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 569028607d0ece..037ae82349fa95 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -48,47 +48,7 @@ */ #define FULLNAME_CAPACITY 157 -int static strnicmp(const char *str1, const char *str2, uint32_t n) { - if (str1 == NULL) { - if (str2 == NULL) { - return 0; - } else { - return -1; - } - } else if (str2 == NULL) { - return 1; - } else { - /* compare non-NULL strings lexically with lowercase */ - int rc; - unsigned char c1, c2; - - for (; n--;) { - c1 = (unsigned char)*str1; - c2 = (unsigned char)*str2; - if (c1 == 0) { - if (c2 == 0) { - return 0; - } else { - return -1; - } - } else if (c2 == 0) { - return 1; - } else { - /* compare non-zero characters with lowercase */ - rc = (int)(unsigned char)tolower(c1) - (int)(unsigned char)tolower(c2); - if (rc != 0) { - return rc; - } - } - ++str1; - ++str2; - } - } - - return 0; -} - -void static GetParent(const char* localeID, char* parent, int32_t parentCapacity) +static void GetParent(const char* localeID, char* parent, int32_t parentCapacity) { const char *lastUnderscore; int32_t i; @@ -97,19 +57,26 @@ void static GetParent(const char* localeID, char* parent, int32_t parentCapacity localeID = [NSLocale systemLocale].localeIdentifier.UTF8String; lastUnderscore = strrchr(localeID, '-'); - if (lastUnderscore != NULL) { + if (lastUnderscore != NULL) + { i = (int32_t)(lastUnderscore - localeID); - } else { + } + else + { i = 0; } - if (i > 0) { + if (i > 0) + { // primary lang subtag und (undefined). - if (strnicmp(localeID, "und-", 4) == 0) { + if (strncasecmp(localeID, "und-", 4) == 0) + { localeID += 3; i -= 3; memmove(parent, localeID, MIN(i, parentCapacity)); - } else if (parent != localeID) { + } + else if (parent != localeID) + { memcpy(parent, localeID, MIN(i, parentCapacity)); } } @@ -117,8 +84,6 @@ void static GetParent(const char* localeID, char* parent, int32_t parentCapacity // terminate chars if (i >= 0 && i < parentCapacity) parent[i] = 0; - - return; } /* ### Data tables **************************************************/ From f6d9afa97ada4feb1fca54a219253dd7dab852f0 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Wed, 26 Jul 2023 13:55:28 +0200 Subject: [PATCH 08/12] Remove static tables and call icu function --- .../System.Globalization.Native/pal_locale.m | 424 +----------------- 1 file changed, 2 insertions(+), 422 deletions(-) diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 037ae82349fa95..05c72a58f0fa0a 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -86,426 +86,6 @@ static void GetParent(const char* localeID, char* parent, int32_t parentCapacity parent[i] = 0; } -/* ### Data tables **************************************************/ - -/** - * Table of language codes, both 2- and 3-letter, with preference - * given to 2-letter codes where possible. Includes 3-letter codes - * that lack a 2-letter equivalent. - * - * This list must be in sorted order. This list is returned directly - * to the user by some API. - * - * This list must be kept in sync with LANGUAGES_3, with corresponding - * entries matched. - * - * This table should be terminated with a NULL entry, followed by a - * second list, and another NULL entry. The first list is visible to - * user code when this array is returned by API. The second list - * contains codes we support, but do not expose through user API. - * - * Notes - * - * Tables updated per http://lcweb.loc.gov/standards/iso639-2/ to - * include the revisions up to 2001/7/27 *CWB* - * - * The 3 character codes are the terminology codes like RFC 3066. This - * is compatible with prior ICU codes - * - * "in" "iw" "ji" "jw" & "sh" have been withdrawn but are still in the - * table but now at the end of the table because 3 character codes are - * duplicates. This avoids bad searches going from 3 to 2 character - * codes. - * - * The range qaa-qtz is reserved for local use - */ -/* Generated using org.unicode.cldr.icu.GenerateISO639LanguageTables */ -/* ISO639 table version is 20150505 */ -/* Subsequent hand addition of selected languages */ -static const char * const LANGUAGES[] = { - "aa", "ab", "ace", "ach", "ada", "ady", "ae", "aeb", - "af", "afh", "agq", "ain", "ak", "akk", "akz", "ale", - "aln", "alt", "am", "an", "ang", "anp", "ar", "arc", - "arn", "aro", "arp", "arq", "ars", "arw", "ary", "arz", "as", - "asa", "ase", "ast", "av", "avk", "awa", "ay", "az", - "ba", "bal", "ban", "bar", "bas", "bax", "bbc", "bbj", - "be", "bej", "bem", "bew", "bez", "bfd", "bfq", "bg", - "bgc", "bgn", "bho", "bi", "bik", "bin", "bjn", "bkm", "bla", - "bm", "bn", "bo", "bpy", "bqi", "br", "bra", "brh", - "brx", "bs", "bss", "bua", "bug", "bum", "byn", "byv", - "ca", "cad", "car", "cay", "cch", "ccp", "ce", "ceb", "cgg", - "ch", "chb", "chg", "chk", "chm", "chn", "cho", "chp", - "chr", "chy", "ckb", "co", "cop", "cps", "cr", "crh", - "cs", "csb", "cu", "cv", "cy", - "da", "dak", "dar", "dav", "de", "del", "den", "dgr", - "din", "dje", "doi", "dsb", "dtp", "dua", "dum", "dv", - "dyo", "dyu", "dz", "dzg", - "ebu", "ee", "efi", "egl", "egy", "eka", "el", "elx", - "en", "enm", "eo", "es", "esu", "et", "eu", "ewo", - "ext", - "fa", "fan", "fat", "ff", "fi", "fil", "fit", "fj", - "fo", "fon", "fr", "frc", "frm", "fro", "frp", "frr", - "frs", "fur", "fy", - "ga", "gaa", "gag", "gan", "gay", "gba", "gbz", "gd", - "gez", "gil", "gl", "glk", "gmh", "gn", "goh", "gom", - "gon", "gor", "got", "grb", "grc", "gsw", "gu", "guc", - "gur", "guz", "gv", "gwi", - "ha", "hai", "hak", "haw", "he", "hi", "hif", "hil", - "hit", "hmn", "ho", "hr", "hsb", "hsn", "ht", "hu", - "hup", "hy", "hz", - "ia", "iba", "ibb", "id", "ie", "ig", "ii", "ik", - "ilo", "inh", "io", "is", "it", "iu", "izh", - "ja", "jam", "jbo", "jgo", "jmc", "jpr", "jrb", "jut", - "jv", - "ka", "kaa", "kab", "kac", "kaj", "kam", "kaw", "kbd", - "kbl", "kcg", "kde", "kea", "ken", "kfo", "kg", "kgp", - "kha", "kho", "khq", "khw", "ki", "kiu", "kj", "kk", - "kkj", "kl", "kln", "km", "kmb", "kn", "ko", "koi", - "kok", "kos", "kpe", "kr", "krc", "kri", "krj", "krl", - "kru", "ks", "ksb", "ksf", "ksh", "ku", "kum", "kut", - "kv", "kw", "ky", - "la", "lad", "lag", "lah", "lam", "lb", "lez", "lfn", - "lg", "li", "lij", "liv", "lkt", "lmo", "ln", "lo", - "lol", "loz", "lrc", "lt", "ltg", "lu", "lua", "lui", - "lun", "luo", "lus", "luy", "lv", "lzh", "lzz", - "mad", "maf", "mag", "mai", "mak", "man", "mas", "mde", - "mdf", "mdh", "mdr", "men", "mer", "mfe", "mg", "mga", - "mgh", "mgo", "mh", "mi", "mic", "min", "mis", "mk", - "ml", "mn", "mnc", "mni", - "moh", "mos", "mr", "mrj", - "ms", "mt", "mua", "mul", "mus", "mwl", "mwr", "mwv", - "my", "mye", "myv", "mzn", - "na", "nan", "nap", "naq", "nb", "nd", "nds", "ne", - "new", "ng", "nia", "niu", "njo", "nl", "nmg", "nn", - "nnh", "no", "nog", "non", "nov", "nqo", "nr", "nso", - "nus", "nv", "nwc", "ny", "nym", "nyn", "nyo", "nzi", - "oc", "oj", "om", "or", "os", "osa", "ota", - "pa", "pag", "pal", "pam", "pap", "pau", "pcd", "pcm", "pdc", - "pdt", "peo", "pfl", "phn", "pi", "pl", "pms", "pnt", - "pon", "prg", "pro", "ps", "pt", - "qu", "quc", "qug", - "raj", "rap", "rar", "rgn", "rif", "rm", "rn", "ro", - "rof", "rom", "rtm", "ru", "rue", "rug", "rup", - "rw", "rwk", - "sa", "sad", "sah", "sam", "saq", "sas", "sat", "saz", - "sba", "sbp", "sc", "scn", "sco", "sd", "sdc", "sdh", - "se", "see", "seh", "sei", "sel", "ses", "sg", "sga", - "sgs", "shi", "shn", "shu", "si", "sid", "sk", - "sl", "sli", "sly", "sm", "sma", "smj", "smn", "sms", - "sn", "snk", "so", "sog", "sq", "sr", "srn", "srr", - "ss", "ssy", "st", "stq", "su", "suk", "sus", "sux", - "sv", "sw", "swb", "syc", "syr", "szl", - "ta", "tcy", "te", "tem", "teo", "ter", "tet", "tg", - "th", "ti", "tig", "tiv", "tk", "tkl", "tkr", - "tlh", "tli", "tly", "tmh", "tn", "to", "tog", "tpi", - "tr", "tru", "trv", "ts", "tsd", "tsi", "tt", "ttt", - "tum", "tvl", "tw", "twq", "ty", "tyv", "tzm", - "udm", "ug", "uga", "uk", "umb", "und", "ur", "uz", - "vai", "ve", "vec", "vep", "vi", "vls", "vmf", "vo", - "vot", "vro", "vun", - "wa", "wae", "wal", "war", "was", "wbp", "wo", "wuu", - "xal", "xh", "xmf", "xog", - "yao", "yap", "yav", "ybb", "yi", "yo", "yrl", "yue", - "za", "zap", "zbl", "zea", "zen", "zgh", "zh", "zu", - "zun", "zxx", "zza", -NULL, - "in", "iw", "ji", "jw", "mo", "sh", "swc", "tl", /* obsolete language codes */ -NULL -}; - -/** - * Table of 3-letter language codes. - * - * This is a lookup table used to convert 3-letter language codes to - * their 2-letter equivalent, where possible. It must be kept in sync - * with LANGUAGES. For all valid i, LANGUAGES[i] must refer to the - * same language as LANGUAGES_3[i]. The commented-out lines are - * copied from LANGUAGES to make eyeballing this baby easier. - * - * Where a 3-letter language code has no 2-letter equivalent, the - * 3-letter code occupies both LANGUAGES[i] and LANGUAGES_3[i]. - * - * This table should be terminated with a NULL entry, followed by a - * second list, and another NULL entry. The two lists correspond to - * the two lists in LANGUAGES. - */ -/* Generated using org.unicode.cldr.icu.GenerateISO639LanguageTables */ -/* ISO639 table version is 20150505 */ -/* Subsequent hand addition of selected languages */ -static const char * const LANGUAGES_3[] = { - "aar", "abk", "ace", "ach", "ada", "ady", "ave", "aeb", - "afr", "afh", "agq", "ain", "aka", "akk", "akz", "ale", - "aln", "alt", "amh", "arg", "ang", "anp", "ara", "arc", - "arn", "aro", "arp", "arq", "ars", "arw", "ary", "arz", "asm", - "asa", "ase", "ast", "ava", "avk", "awa", "aym", "aze", - "bak", "bal", "ban", "bar", "bas", "bax", "bbc", "bbj", - "bel", "bej", "bem", "bew", "bez", "bfd", "bfq", "bul", - "bgc", "bgn", "bho", "bis", "bik", "bin", "bjn", "bkm", "bla", - "bam", "ben", "bod", "bpy", "bqi", "bre", "bra", "brh", - "brx", "bos", "bss", "bua", "bug", "bum", "byn", "byv", - "cat", "cad", "car", "cay", "cch", "ccp", "che", "ceb", "cgg", - "cha", "chb", "chg", "chk", "chm", "chn", "cho", "chp", - "chr", "chy", "ckb", "cos", "cop", "cps", "cre", "crh", - "ces", "csb", "chu", "chv", "cym", - "dan", "dak", "dar", "dav", "deu", "del", "den", "dgr", - "din", "dje", "doi", "dsb", "dtp", "dua", "dum", "div", - "dyo", "dyu", "dzo", "dzg", - "ebu", "ewe", "efi", "egl", "egy", "eka", "ell", "elx", - "eng", "enm", "epo", "spa", "esu", "est", "eus", "ewo", - "ext", - "fas", "fan", "fat", "ful", "fin", "fil", "fit", "fij", - "fao", "fon", "fra", "frc", "frm", "fro", "frp", "frr", - "frs", "fur", "fry", - "gle", "gaa", "gag", "gan", "gay", "gba", "gbz", "gla", - "gez", "gil", "glg", "glk", "gmh", "grn", "goh", "gom", - "gon", "gor", "got", "grb", "grc", "gsw", "guj", "guc", - "gur", "guz", "glv", "gwi", - "hau", "hai", "hak", "haw", "heb", "hin", "hif", "hil", - "hit", "hmn", "hmo", "hrv", "hsb", "hsn", "hat", "hun", - "hup", "hye", "her", - "ina", "iba", "ibb", "ind", "ile", "ibo", "iii", "ipk", - "ilo", "inh", "ido", "isl", "ita", "iku", "izh", - "jpn", "jam", "jbo", "jgo", "jmc", "jpr", "jrb", "jut", - "jav", - "kat", "kaa", "kab", "kac", "kaj", "kam", "kaw", "kbd", - "kbl", "kcg", "kde", "kea", "ken", "kfo", "kon", "kgp", - "kha", "kho", "khq", "khw", "kik", "kiu", "kua", "kaz", - "kkj", "kal", "kln", "khm", "kmb", "kan", "kor", "koi", - "kok", "kos", "kpe", "kau", "krc", "kri", "krj", "krl", - "kru", "kas", "ksb", "ksf", "ksh", "kur", "kum", "kut", - "kom", "cor", "kir", - "lat", "lad", "lag", "lah", "lam", "ltz", "lez", "lfn", - "lug", "lim", "lij", "liv", "lkt", "lmo", "lin", "lao", - "lol", "loz", "lrc", "lit", "ltg", "lub", "lua", "lui", - "lun", "luo", "lus", "luy", "lav", "lzh", "lzz", - "mad", "maf", "mag", "mai", "mak", "man", "mas", "mde", - "mdf", "mdh", "mdr", "men", "mer", "mfe", "mlg", "mga", - "mgh", "mgo", "mah", "mri", "mic", "min", "mis", "mkd", - "mal", "mon", "mnc", "mni", - "moh", "mos", "mar", "mrj", - "msa", "mlt", "mua", "mul", "mus", "mwl", "mwr", "mwv", - "mya", "mye", "myv", "mzn", - "nau", "nan", "nap", "naq", "nob", "nde", "nds", "nep", - "new", "ndo", "nia", "niu", "njo", "nld", "nmg", "nno", - "nnh", "nor", "nog", "non", "nov", "nqo", "nbl", "nso", - "nus", "nav", "nwc", "nya", "nym", "nyn", "nyo", "nzi", - "oci", "oji", "orm", "ori", "oss", "osa", "ota", - "pan", "pag", "pal", "pam", "pap", "pau", "pcd", "pcm", "pdc", - "pdt", "peo", "pfl", "phn", "pli", "pol", "pms", "pnt", - "pon", "prg", "pro", "pus", "por", - "que", "quc", "qug", - "raj", "rap", "rar", "rgn", "rif", "roh", "run", "ron", - "rof", "rom", "rtm", "rus", "rue", "rug", "rup", - "kin", "rwk", - "san", "sad", "sah", "sam", "saq", "sas", "sat", "saz", - "sba", "sbp", "srd", "scn", "sco", "snd", "sdc", "sdh", - "sme", "see", "seh", "sei", "sel", "ses", "sag", "sga", - "sgs", "shi", "shn", "shu", "sin", "sid", "slk", - "slv", "sli", "sly", "smo", "sma", "smj", "smn", "sms", - "sna", "snk", "som", "sog", "sqi", "srp", "srn", "srr", - "ssw", "ssy", "sot", "stq", "sun", "suk", "sus", "sux", - "swe", "swa", "swb", "syc", "syr", "szl", - "tam", "tcy", "tel", "tem", "teo", "ter", "tet", "tgk", - "tha", "tir", "tig", "tiv", "tuk", "tkl", "tkr", - "tlh", "tli", "tly", "tmh", "tsn", "ton", "tog", "tpi", - "tur", "tru", "trv", "tso", "tsd", "tsi", "tat", "ttt", - "tum", "tvl", "twi", "twq", "tah", "tyv", "tzm", - "udm", "uig", "uga", "ukr", "umb", "und", "urd", "uzb", - "vai", "ven", "vec", "vep", "vie", "vls", "vmf", "vol", - "vot", "vro", "vun", - "wln", "wae", "wal", "war", "was", "wbp", "wol", "wuu", - "xal", "xho", "xmf", "xog", - "yao", "yap", "yav", "ybb", "yid", "yor", "yrl", "yue", - "zha", "zap", "zbl", "zea", "zen", "zgh", "zho", "zul", - "zun", "zxx", "zza", -NULL, -/* "in", "iw", "ji", "jw", "mo", "sh", "swc", "tl", */ - "ind", "heb", "yid", "jaw", "mol", "srp", "swc", "tgl", -NULL -}; - -/** - * Table of 2-letter country codes. - * - * This list must be in sorted order. This list is returned directly - * to the user by some API. - * - * This list must be kept in sync with COUNTRIES_3, with corresponding - * entries matched. - * - * This table should be terminated with a NULL entry, followed by a - * second list, and another NULL entry. The first list is visible to - * user code when this array is returned by API. The second list - * contains codes we support, but do not expose through user API. - * - * Notes: - * - * ZR(ZAR) is now CD(COD) and FX(FXX) is PS(PSE) as per - * http://www.evertype.com/standards/iso3166/iso3166-1-en.html added - * new codes keeping the old ones for compatibility updated to include - * 1999/12/03 revisions *CWB* - * - * RO(ROM) is now RO(ROU) according to - * http://www.iso.org/iso/en/prods-services/iso3166ma/03updates-on-iso-3166/nlv3e-rou.html - */ -static const char * const COUNTRIES[] = { - "AD", "AE", "AF", "AG", "AI", "AL", "AM", - "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", - "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", - "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", - "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", - "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", - "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DG", "DJ", "DK", - "DM", "DO", "DZ", "EA", "EC", "EE", "EG", "EH", "ER", - "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", - "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", - "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", - "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", - "IC", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", - "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", - "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", - "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", - "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", - "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", - "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", - "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", - "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", - "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", - "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", - "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", - "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", - "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", - "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", - "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", - "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", - "WS", "XK", "YE", "YT", "ZA", "ZM", "ZW", -NULL, - "AN", "BU", "CS", "FX", "RO", "SU", "TP", "YD", "YU", "ZR", /* obsolete country codes */ -NULL -}; - -/** - * Table of 3-letter country codes. - * - * This is a lookup table used to convert 3-letter country codes to - * their 2-letter equivalent. It must be kept in sync with COUNTRIES. - * For all valid i, COUNTRIES[i] must refer to the same country as - * COUNTRIES_3[i]. The commented-out lines are copied from COUNTRIES - * to make eyeballing this baby easier. - * - * This table should be terminated with a NULL entry, followed by a - * second list, and another NULL entry. The two lists correspond to - * the two lists in COUNTRIES. - */ -static const char * const COUNTRIES_3[] = { -/* "AD", "AE", "AF", "AG", "AI", "AL", "AM", */ - "AND", "ARE", "AFG", "ATG", "AIA", "ALB", "ARM", -/* "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", */ - "AGO", "ATA", "ARG", "ASM", "AUT", "AUS", "ABW", "ALA", "AZE", -/* "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", */ - "BIH", "BRB", "BGD", "BEL", "BFA", "BGR", "BHR", "BDI", -/* "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", */ - "BEN", "BLM", "BMU", "BRN", "BOL", "BES", "BRA", "BHS", "BTN", "BVT", -/* "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", */ - "BWA", "BLR", "BLZ", "CAN", "CCK", "COD", "CAF", "COG", -/* "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", */ - "CHE", "CIV", "COK", "CHL", "CMR", "CHN", "COL", "CRI", -/* "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DG", "DJ", "DK", */ - "CUB", "CPV", "CUW", "CXR", "CYP", "CZE", "DEU", "DGA", "DJI", "DNK", -/* "DM", "DO", "DZ", "EA", "EC", "EE", "EG", "EH", "ER", */ - "DMA", "DOM", "DZA", "XEA", "ECU", "EST", "EGY", "ESH", "ERI", -/* "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", */ - "ESP", "ETH", "FIN", "FJI", "FLK", "FSM", "FRO", "FRA", -/* "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", */ - "GAB", "GBR", "GRD", "GEO", "GUF", "GGY", "GHA", "GIB", "GRL", -/* "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", */ - "GMB", "GIN", "GLP", "GNQ", "GRC", "SGS", "GTM", "GUM", -/* "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", */ - "GNB", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN", -/* "IC", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS" */ - "XIC", "IDN", "IRL", "ISR", "IMN", "IND", "IOT", "IRQ", "IRN", "ISL", -/* "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", */ - "ITA", "JEY", "JAM", "JOR", "JPN", "KEN", "KGZ", "KHM", "KIR", -/* "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", */ - "COM", "KNA", "PRK", "KOR", "KWT", "CYM", "KAZ", "LAO", -/* "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", */ - "LBN", "LCA", "LIE", "LKA", "LBR", "LSO", "LTU", "LUX", -/* "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", */ - "LVA", "LBY", "MAR", "MCO", "MDA", "MNE", "MAF", "MDG", "MHL", "MKD", -/* "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", */ - "MLI", "MMR", "MNG", "MAC", "MNP", "MTQ", "MRT", "MSR", -/* "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", */ - "MLT", "MUS", "MDV", "MWI", "MEX", "MYS", "MOZ", "NAM", -/* "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", */ - "NCL", "NER", "NFK", "NGA", "NIC", "NLD", "NOR", "NPL", -/* "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", */ - "NRU", "NIU", "NZL", "OMN", "PAN", "PER", "PYF", "PNG", -/* "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", */ - "PHL", "PAK", "POL", "SPM", "PCN", "PRI", "PSE", "PRT", -/* "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", */ - "PLW", "PRY", "QAT", "REU", "ROU", "SRB", "RUS", "RWA", "SAU", -/* "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", */ - "SLB", "SYC", "SDN", "SWE", "SGP", "SHN", "SVN", "SJM", -/* "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", */ - "SVK", "SLE", "SMR", "SEN", "SOM", "SUR", "SSD", "STP", "SLV", -/* "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", */ - "SXM", "SYR", "SWZ", "TCA", "TCD", "ATF", "TGO", "THA", "TJK", -/* "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", */ - "TKL", "TLS", "TKM", "TUN", "TON", "TUR", "TTO", "TUV", -/* "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", */ - "TWN", "TZA", "UKR", "UGA", "UMI", "USA", "URY", "UZB", -/* "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", */ - "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", -/* "WS", "XK", "YE", "YT", "ZA", "ZM", "ZW", */ - "WSM", "XKK", "YEM", "MYT", "ZAF", "ZMB", "ZWE", -NULL, -/* "AN", "BU", "CS", "FX", "RO", "SU", "TP", "YD", "YU", "ZR" */ - "ANT", "BUR", "SCG", "FXX", "ROM", "SUN", "TMP", "YMD", "YUG", "ZAR", -NULL -}; - -/** - * Lookup 'key' in the array 'list'. The array 'list' should contain - * a NULL entry, followed by more entries, and a second NULL entry. - * - * The 'list' param should be LANGUAGES, LANGUAGES_3, COUNTRIES, or - * COUNTRIES_3. - */ -static int16_t _findIndex(const char* const* list, const char* key) -{ - const char* const* anchor = list; - int32_t pass = 0; - - /* Make two passes through two NULL-terminated arrays at 'list' */ - while (pass++ < 2) { - while (*list) { - if (strcmp(key, *list) == 0) { - return (int16_t)(list - anchor); - } - list++; - } - ++list; /* skip final NULL *CWB*/ - } - return -1; -} - -static const char* GetISO3Country(const char* countryCode) -{ - int16_t offset = _findIndex(COUNTRIES, countryCode); - if (offset < 0) - return ""; - - return COUNTRIES_3[offset]; -} - -static const char* GetISO3Language(const char* languageCode) -{ - int16_t offset = _findIndex(LANGUAGES, languageCode); - if (offset < 0) - return ""; - return LANGUAGES_3[offset]; -} - const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData) { const char* value; @@ -601,7 +181,7 @@ static int16_t _findIndex(const char* const* list, const char* key) case LocaleString_Iso639LanguageThreeLetterName: { NSString *iso639_2 = [currentLocale objectForKey:NSLocaleLanguageCode]; - value = GetISO3Language([iso639_2 UTF8String]); + value = uloc_getISO3LanguageByLangCode([iso639_2 UTF8String]); break; } case LocaleString_Iso3166CountryName: @@ -610,7 +190,7 @@ static int16_t _findIndex(const char* const* list, const char* key) case LocaleString_Iso3166CountryName2: { const char *countryCode = strdup([[currentLocale objectForKey:NSLocaleCountryCode] UTF8String]); - value = GetISO3Country(countryCode); + value = uloc_getISO3CountryByCountryCode(countryCode); break; } case LocaleString_NaNSymbol: From 5afb93aadef93c5e13dcf674a613b0116817a4f0 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Fri, 28 Jul 2023 16:05:01 +0200 Subject: [PATCH 09/12] not run on OSX platform --- .../src/System.Private.CoreLib.Shared.projitems | 12 ++++++------ .../libs/System.Globalization.Native/pal_casing.m | 2 +- .../libs/System.Globalization.Native/pal_collation.m | 2 +- .../libs/System.Globalization.Native/pal_locale.m | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 65d65ff797e22c..ad0d50d4d11c79 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -332,11 +332,11 @@ - + - + @@ -391,7 +391,7 @@ - + @@ -1290,13 +1290,13 @@ Common\Interop\Interop.Casing.cs - + Common\Interop\Interop.Casing.OSX.cs Common\Interop\Interop.Collation.cs - + Common\Interop\Interop.Collation.OSX.cs @@ -1311,7 +1311,7 @@ Common\Interop\Interop.Locale.cs - + Common\Interop\Interop.Locale.OSX.cs diff --git a/src/native/libs/System.Globalization.Native/pal_casing.m b/src/native/libs/System.Globalization.Native/pal_casing.m index e0bd0f80805c96..eec471f9ab6295 100644 --- a/src/native/libs/System.Globalization.Native/pal_casing.m +++ b/src/native/libs/System.Globalization.Native/pal_casing.m @@ -7,7 +7,7 @@ #import -#if defined(TARGET_OSX) || defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) +#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) /** * Is this code unit a lead surrogate (U+d800..U+dbff)? diff --git a/src/native/libs/System.Globalization.Native/pal_collation.m b/src/native/libs/System.Globalization.Native/pal_collation.m index 4c755ab475685d..ac59a428aa4c2f 100644 --- a/src/native/libs/System.Globalization.Native/pal_collation.m +++ b/src/native/libs/System.Globalization.Native/pal_collation.m @@ -7,7 +7,7 @@ #import -#if defined(TARGET_OSX) || defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) +#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) // Enum that corresponds to C# CompareOptions typedef enum diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 05c72a58f0fa0a..4f31e359e94324 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -32,7 +32,7 @@ return strdup([localeName UTF8String]); } -#if defined(TARGET_OSX) || defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) +#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) const char* GlobalizationNative_GetLocaleNameNative(const char* localeName) { From 98c294472ef0268a09f103027f883463aebfd43f Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Fri, 28 Jul 2023 16:33:46 +0200 Subject: [PATCH 10/12] Rename OSX files to iOS --- ...op.Casing.OSX.cs => Interop.Casing.iOS.cs} | 0 ...lation.OSX.cs => Interop.Collation.iOS.cs} | 0 ...op.Locale.OSX.cs => Interop.Locale.iOS.cs} | 0 .../System.Private.CoreLib.Shared.projitems | 18 ++++++++--------- .../System/Globalization/CompareInfo.Icu.cs | 20 +++++++++---------- .../src/System/Globalization/CompareInfo.cs | 18 ++++++++--------- ...{CompareInfo.OSX.cs => CompareInfo.iOS.cs} | 0 .../System/Globalization/CultureData.Unix.cs | 4 ++-- .../src/System/Globalization/CultureData.cs | 16 +++++++-------- ...{CultureData.OSX.cs => CultureData.iOS.cs} | 0 .../System/Globalization/GlobalizationMode.cs | 4 ++-- .../src/System/Globalization/TextInfo.cs | 2 +- .../{TextInfo.OSX.cs => TextInfo.iOS.cs} | 0 13 files changed, 41 insertions(+), 41 deletions(-) rename src/libraries/Common/src/Interop/{Interop.Casing.OSX.cs => Interop.Casing.iOS.cs} (100%) rename src/libraries/Common/src/Interop/{Interop.Collation.OSX.cs => Interop.Collation.iOS.cs} (100%) rename src/libraries/Common/src/Interop/{Interop.Locale.OSX.cs => Interop.Locale.iOS.cs} (100%) rename src/libraries/System.Private.CoreLib/src/System/Globalization/{CompareInfo.OSX.cs => CompareInfo.iOS.cs} (100%) rename src/libraries/System.Private.CoreLib/src/System/Globalization/{CultureData.OSX.cs => CultureData.iOS.cs} (100%) rename src/libraries/System.Private.CoreLib/src/System/Globalization/{TextInfo.OSX.cs => TextInfo.iOS.cs} (100%) diff --git a/src/libraries/Common/src/Interop/Interop.Casing.OSX.cs b/src/libraries/Common/src/Interop/Interop.Casing.iOS.cs similarity index 100% rename from src/libraries/Common/src/Interop/Interop.Casing.OSX.cs rename to src/libraries/Common/src/Interop/Interop.Casing.iOS.cs diff --git a/src/libraries/Common/src/Interop/Interop.Collation.OSX.cs b/src/libraries/Common/src/Interop/Interop.Collation.iOS.cs similarity index 100% rename from src/libraries/Common/src/Interop/Interop.Collation.OSX.cs rename to src/libraries/Common/src/Interop/Interop.Collation.iOS.cs diff --git a/src/libraries/Common/src/Interop/Interop.Locale.OSX.cs b/src/libraries/Common/src/Interop/Interop.Locale.iOS.cs similarity index 100% rename from src/libraries/Common/src/Interop/Interop.Locale.OSX.cs rename to src/libraries/Common/src/Interop/Interop.Locale.iOS.cs diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index ad0d50d4d11c79..82eb84609a6f09 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -332,11 +332,11 @@ - + - + @@ -391,7 +391,7 @@ - + @@ -1290,14 +1290,14 @@ Common\Interop\Interop.Casing.cs - - Common\Interop\Interop.Casing.OSX.cs + + Common\Interop\Interop.Casing.iOS.cs Common\Interop\Interop.Collation.cs - - Common\Interop\Interop.Collation.OSX.cs + + Common\Interop\Interop.Collation.iOS.cs Common\Interop\Interop.ICU.cs @@ -1311,8 +1311,8 @@ Common\Interop\Interop.Locale.cs - - Common\Interop\Interop.Locale.OSX.cs + + Common\Interop\Interop.Locale.iOS.cs Common\Interop\Interop.Normalization.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Icu.cs index ee4c0758456375..15d8ee0ed3a551 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Icu.cs @@ -24,7 +24,7 @@ private void IcuInitSortHandle(string interopCultureName) _isAsciiEqualityOrdinal = GetIsAsciiEqualityOrdinal(interopCultureName); if (!GlobalizationMode.Invariant) { -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS || TARGET_BROWSER +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS || TARGET_BROWSER if (GlobalizationMode.Hybrid) return; #endif @@ -84,7 +84,7 @@ private unsafe int IcuIndexOfCore(ReadOnlySpan source, ReadOnlySpan fixed (char* pSource = &MemoryMarshal.GetReference(source)) fixed (char* pTarget = &MemoryMarshal.GetReference(target)) { -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) return IndexOfCoreNative(pTarget, target.Length, pSource, source.Length, options, fromBeginning, matchLengthPtr); #endif @@ -203,7 +203,7 @@ private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan source, Rea throw new Exception((string)ex_result); return result; } -#elif TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#elif TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) return IndexOfCoreNative(b, target.Length, a, source.Length, options, fromBeginning, matchLengthPtr); #endif @@ -305,7 +305,7 @@ private unsafe int IndexOfOrdinalHelper(ReadOnlySpan source, ReadOnlySpan< throw new Exception((string)ex_result); return result; } -#elif TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#elif TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) return IndexOfCoreNative(b, target.Length, a, source.Length, options, fromBeginning, matchLengthPtr); #endif @@ -337,7 +337,7 @@ private unsafe bool IcuStartsWith(ReadOnlySpan source, ReadOnlySpan fixed (char* pSource = &MemoryMarshal.GetReference(source)) // could be null (or otherwise unable to be dereferenced) fixed (char* pPrefix = &MemoryMarshal.GetReference(prefix)) { -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) return NativeStartsWith(pPrefix, prefix.Length, pSource, source.Length, options); #endif @@ -420,7 +420,7 @@ private unsafe bool StartsWithOrdinalIgnoreCaseHelper(ReadOnlySpan source, return true; InteropCall: -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) return NativeStartsWith(bp, prefix.Length, ap, source.Length, options); #endif @@ -492,7 +492,7 @@ private unsafe bool StartsWithOrdinalHelper(ReadOnlySpan source, ReadOnlyS return true; InteropCall: -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) return NativeStartsWith(bp, prefix.Length, ap, source.Length, options); #endif @@ -521,7 +521,7 @@ private unsafe bool IcuEndsWith(ReadOnlySpan source, ReadOnlySpan su fixed (char* pSource = &MemoryMarshal.GetReference(source)) // could be null (or otherwise unable to be dereferenced) fixed (char* pSuffix = &MemoryMarshal.GetReference(suffix)) { -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) return NativeEndsWith(pSuffix, suffix.Length, pSource, source.Length, options); #endif @@ -605,7 +605,7 @@ private unsafe bool EndsWithOrdinalIgnoreCaseHelper(ReadOnlySpan source, R return true; InteropCall: -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) return NativeEndsWith(bp, suffix.Length, ap, source.Length, options); #endif @@ -677,7 +677,7 @@ private unsafe bool EndsWithOrdinalHelper(ReadOnlySpan source, ReadOnlySpa return true; InteropCall: -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) return NativeEndsWith(bp, suffix.Length, ap, source.Length, options); #endif diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs index 05bb9f758883d0..1d7a313d14addf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs @@ -490,7 +490,7 @@ private unsafe int CompareStringCore(ReadOnlySpan string1, ReadOnlySpan source, ReadOnlySpan prefix else { // Linguistic comparison requested and we don't need to special-case any args. -#if TARGET_BROWSER || TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_BROWSER || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_HybridGlobalizationWithMatchLength); @@ -762,7 +762,7 @@ public unsafe bool IsSuffix(ReadOnlySpan source, ReadOnlySpan suffix else { // Linguistic comparison requested and we don't need to special-case any args. -#if TARGET_BROWSER || TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_BROWSER || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_HybridGlobalizationWithMatchLength); @@ -1450,7 +1450,7 @@ public SortKey GetSortKey(string source) private SortKey CreateSortKeyCore(string source, CompareOptions options) => GlobalizationMode.UseNls ? NlsCreateSortKey(source, options) : -#if TARGET_BROWSER || TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_BROWSER || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS GlobalizationMode.Hybrid ? throw new PlatformNotSupportedException(GetPNSEText("SortKey")) : #endif @@ -1493,7 +1493,7 @@ public int GetSortKey(ReadOnlySpan source, Span destination, Compare private int GetSortKeyCore(ReadOnlySpan source, Span destination, CompareOptions options) => GlobalizationMode.UseNls ? NlsGetSortKey(source, destination, options) : -#if TARGET_BROWSER || TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_BROWSER || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS GlobalizationMode.Hybrid ? throw new PlatformNotSupportedException(GetPNSEText("SortKey")) : #endif @@ -1530,7 +1530,7 @@ public int GetSortKeyLength(ReadOnlySpan source, CompareOptions options = private int GetSortKeyLengthCore(ReadOnlySpan source, CompareOptions options) => GlobalizationMode.UseNls ? NlsGetSortKeyLength(source, options) : -#if TARGET_BROWSER || TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_BROWSER || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS GlobalizationMode.Hybrid ? throw new PlatformNotSupportedException(GetPNSEText("SortKey")) : #endif @@ -1607,7 +1607,7 @@ public int GetHashCode(ReadOnlySpan source, CompareOptions options) private unsafe int GetHashCodeOfStringCore(ReadOnlySpan source, CompareOptions options) => GlobalizationMode.UseNls ? NlsGetHashCodeOfString(source, options) : -#if TARGET_BROWSER || TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_BROWSER || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS GlobalizationMode.Hybrid ? throw new PlatformNotSupportedException(GetPNSEText("HashCode")) : #endif @@ -1631,7 +1631,7 @@ public SortVersion Version } else { -#if TARGET_BROWSER || TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_BROWSER || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) { throw new PlatformNotSupportedException(GetPNSEText("SortVersion")); @@ -1647,7 +1647,7 @@ public SortVersion Version public int LCID => CultureInfo.GetCultureInfo(Name).LCID; -#if TARGET_BROWSER || TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_BROWSER || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS private static string GetPNSEText(string funcName) => SR.Format(SR.PlatformNotSupported_HybridGlobalization, funcName); #endif } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.OSX.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.iOS.cs similarity index 100% rename from src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.OSX.cs rename to src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.iOS.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs index 76c009beb6466f..533e97b3127d35 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs @@ -8,7 +8,7 @@ namespace System.Globalization internal sealed partial class CultureData { private bool InitCultureDataCore() => -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS GlobalizationMode.Hybrid ? InitAppleCultureDataCore() : InitIcuCultureDataCore(); #else InitIcuCultureDataCore(); @@ -25,7 +25,7 @@ private bool InitCultureDataCore() => private string[]? GetTimeFormatsCore(bool shortFormat) { -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS string format = GlobalizationMode.Hybrid ? GetTimeFormatStringNative(shortFormat) : IcuGetTimeFormatString(shortFormat); #else string format = IcuGetTimeFormatString(shortFormat); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs index 0aa517ef6990f7..51cda682a38133 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -1551,7 +1551,7 @@ internal int FirstDayOfWeek { if (_iFirstDayOfWeek == undef && !GlobalizationMode.Invariant) { -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS _iFirstDayOfWeek = GlobalizationMode.Hybrid ? GetLocaleInfoNative(LocaleNumberData.FirstDayOfWeek) : IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); #else _iFirstDayOfWeek = ShouldUseUserOverrideNlsData ? NlsGetFirstDayOfWeek() : IcuGetLocaleInfo(LocaleNumberData.FirstDayOfWeek); @@ -1963,7 +1963,7 @@ internal string TimeSeparator } else { -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS string? longTimeFormat = GlobalizationMode.Hybrid ? GetTimeFormatStringNative() : IcuGetTimeFormatString(); #else string? longTimeFormat = ShouldUseUserOverrideNlsData ? NlsGetTimeFormatString() : IcuGetTimeFormatString(); @@ -2303,7 +2303,7 @@ private int GetLocaleInfoCore(LocaleNumberData type) // This is never reached but helps illinker statically remove dependencies if (GlobalizationMode.Invariant) return 0; -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type) : IcuGetLocaleInfo(type); #else return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); @@ -2315,7 +2315,7 @@ private int GetLocaleInfoCoreUserOverride(LocaleNumberData type) // This is never reached but helps illinker statically remove dependencies if (GlobalizationMode.Invariant) return 0; -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type) : IcuGetLocaleInfo(type); #else return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); @@ -2328,7 +2328,7 @@ private string GetLocaleInfoCoreUserOverride(LocaleStringData type) if (GlobalizationMode.Invariant) return null!; -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type) : IcuGetLocaleInfo(type); #else return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); @@ -2341,7 +2341,7 @@ private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName = if (GlobalizationMode.Invariant) return null!; -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type) : IcuGetLocaleInfo(type, uiCultureName); #else return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type, uiCultureName); @@ -2354,7 +2354,7 @@ private string GetLocaleInfoCore(string localeName, LocaleStringData type, strin if (GlobalizationMode.Invariant) return null!; -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS return GlobalizationMode.Hybrid ? GetLocaleInfoNative(localeName, type) : IcuGetLocaleInfo(localeName, type, uiCultureName); #else return GlobalizationMode.UseNls ? NlsGetLocaleInfo(localeName, type) : IcuGetLocaleInfo(localeName, type, uiCultureName); @@ -2367,7 +2367,7 @@ private int[] GetLocaleInfoCoreUserOverride(LocaleGroupingData type) if (GlobalizationMode.Invariant) return null!; -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type) : IcuGetLocaleInfo(type); #else return ShouldUseUserOverrideNlsData ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.OSX.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs similarity index 100% rename from src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.OSX.cs rename to src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs index 56be02927c6e8d..a81023eedccc25 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs @@ -13,7 +13,7 @@ internal static partial class GlobalizationMode private static partial class Settings { internal static bool Invariant { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Invariant", "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"); -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS || TARGET_BROWSER +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS || TARGET_BROWSER internal static bool Hybrid { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Hybrid", "DOTNET_SYSTEM_GLOBALIZATION_HYBRID"); #endif internal static bool PredefinedCulturesOnly { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.PredefinedCulturesOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", GlobalizationMode.Invariant); @@ -23,7 +23,7 @@ private static partial class Settings // This allows for the whole Settings nested class to be trimmed when Invariant=true, and allows for the Settings // static cctor (on Unix) to be preserved when Invariant=false. internal static bool Invariant => Settings.Invariant; -#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS || TARGET_BROWSER +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS || TARGET_BROWSER internal static bool Hybrid => Settings.Hybrid; #endif internal static bool PredefinedCulturesOnly => Settings.PredefinedCulturesOnly; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs index d868e0dfca8cac..28b9458abed473 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs @@ -692,7 +692,7 @@ private unsafe void ChangeCaseCore(char* src, int srcLen, char* dstBuffer, int d JsChangeCase(src, srcLen, dstBuffer, dstBufferCapacity, bToUpper); return; } -#elif TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS +#elif TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS if (GlobalizationMode.Hybrid) { ChangeCaseNative(src, srcLen, dstBuffer, dstBufferCapacity, bToUpper); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.OSX.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.iOS.cs similarity index 100% rename from src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.OSX.cs rename to src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.iOS.cs From 123432280e7a01b40525f5f615ae30c4aa93cdc1 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Fri, 28 Jul 2023 17:09:19 +0200 Subject: [PATCH 11/12] update entrypoints --- src/native/libs/System.Globalization.Native/entrypoints.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libs/System.Globalization.Native/entrypoints.c b/src/native/libs/System.Globalization.Native/entrypoints.c index 37246e1bfbdd89..1ba348b910b5ff 100644 --- a/src/native/libs/System.Globalization.Native/entrypoints.c +++ b/src/native/libs/System.Globalization.Native/entrypoints.c @@ -58,7 +58,7 @@ static const Entry s_globalizationNative[] = DllImportEntry(GlobalizationNative_ToAscii) DllImportEntry(GlobalizationNative_ToUnicode) DllImportEntry(GlobalizationNative_WindowsIdToIanaId) -#ifdef __APPLE__ +#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) DllImportEntry(GlobalizationNative_ChangeCaseInvariantNative) DllImportEntry(GlobalizationNative_ChangeCaseNative) DllImportEntry(GlobalizationNative_CompareStringNative) From 6aaa76e68e2d332ac3cfb45190aa2e0e0ef24466 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 31 Jul 2023 17:58:06 +0200 Subject: [PATCH 12/12] inlcude icu lib files for nativeaot tests --- src/tests/build.proj | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tests/build.proj b/src/tests/build.proj index 8737c34181070a..13e3c0f189de71 100644 --- a/src/tests/build.proj +++ b/src/tests/build.proj @@ -427,7 +427,10 @@ <_LinkerFlagsToDrop Include="@(NativeFramework->'-framework %(Identity)')" /> - +