示例#1
0
        private static int IcuGetDigitSubstitution(string cultureName)
        {
            Debug.Assert(!GlobalizationMode.UseNls);
            int digitSubstitution = IcuLocaleData.GetLocaleDataNumericPart(cultureName, IcuLocaleDataParts.DigitSubstitutionOrListSeparator);

            return(digitSubstitution == -1 ? (int)DigitShapes.None : (int)(digitSubstitution & DigitSubstitutionMask));
        }
示例#2
0
        private static string IcuGetListSeparator(string?cultureName)
        {
            Debug.Assert(!GlobalizationMode.UseNls);
            Debug.Assert(cultureName != null);

            int separator = IcuLocaleData.GetLocaleDataNumericPart(cultureName, IcuLocaleDataParts.DigitSubstitutionOrListSeparator);

            if (separator != -1)
            {
                switch (separator & ListSeparatorMask)
                {
                case IcuLocaleData.CommaSep:
                    return(",");

                case IcuLocaleData.SemicolonSep:
                    return(";");

                case IcuLocaleData.ArabicCommaSep:
                    return("\u060C");

                case IcuLocaleData.ArabicSemicolonSep:
                    return("\u061B");

                case IcuLocaleData.DoubleCommaSep:
                    return(",,");

                default:
                    Debug.Assert(false, "[CultureData.IcuGetListSeparator] Unexpected ListSeparator value.");
                    break;
                }
            }

            return(","); // default separator
        }
示例#3
0
        private static int IcuGetEbcdicCodePage(string cultureName)
        {
            Debug.Assert(!GlobalizationMode.UseNls);
            int ebcdicCodePage = IcuLocaleData.GetLocaleDataNumericPart(cultureName, IcuLocaleDataParts.EbcdicCodePage);

            return(ebcdicCodePage == -1 ? CultureData.Invariant.EBCDICCodePage : ebcdicCodePage);
        }
示例#4
0
        private static int IcuGetGeoId(string cultureName)
        {
            Debug.Assert(!GlobalizationMode.UseNls);
            int geoId = IcuLocaleData.GetLocaleDataNumericPart(cultureName, IcuLocaleDataParts.GeoId);

            return(geoId == -1 ? CultureData.Invariant.GeoId : geoId);
        }
示例#5
0
        private const int ICU_ULOC_FULLNAME_CAPACITY           = 157; // max size of locale name

        /// <summary>
        /// This method uses the sRealName field (which is initialized by the constructor before this is called) to
        /// initialize the rest of the state of CultureData based on the underlying OS globalization library.
        /// </summary>
        private bool InitIcuCultureDataCore()
        {
            Debug.Assert(_sRealName != null);
            Debug.Assert(!GlobalizationMode.Invariant);

            const string ICU_COLLATION_KEYWORD = "@collation=";
            string       realNameBuffer        = _sRealName;

            // Basic validation
            if (!IsValidCultureName(realNameBuffer, out var index))
            {
                return(false);
            }

            // Replace _ (alternate sort) with @collation= for ICU
            ReadOnlySpan <char> alternateSortName = default;

            if (index > 0)
            {
                alternateSortName = realNameBuffer.AsSpan(index + 1);
                realNameBuffer    = string.Concat(realNameBuffer.AsSpan(0, index), ICU_COLLATION_KEYWORD, alternateSortName);
            }

            // Get the locale name from ICU
            if (!GetLocaleName(realNameBuffer, out _sWindowsName))
            {
                return(false); // fail
            }

            // Replace the ICU collation keyword with an _
            Debug.Assert(_sWindowsName != null);
            index = _sWindowsName.IndexOf(ICU_COLLATION_KEYWORD, StringComparison.Ordinal);
            if (index >= 0)
            {
                // Use original culture name if alternateSortName is not set, which is possible even if the normalized
                // culture name has "@collation=".
                // "zh-TW-u-co-zhuyin" is a good example. The term "u-co-" means the following part will be the sort name
                // and it will be treated in ICU as "zh-TW@collation=zhuyin".
                _sName = alternateSortName.Length == 0 ? realNameBuffer : string.Concat(_sWindowsName.AsSpan(0, index), "_", alternateSortName);
            }
            else
            {
                _sName = _sWindowsName;
            }
            _sRealName = _sName;

            _iLanguage = LCID;
            if (_iLanguage == 0)
            {
                _iLanguage = CultureInfo.LOCALE_CUSTOM_UNSPECIFIED;
            }
            _bNeutral         = TwoLetterISOCountryName.Length == 0;
            _sSpecificCulture = _bNeutral ? IcuLocaleData.GetSpecificCultureName(_sRealName) : _sRealName;
            // Remove the sort from sName unless custom culture
            if (index > 0 && !_bNeutral && !IsCustomCultureId(_iLanguage))
            {
                _sName = _sWindowsName.Substring(0, index);
            }
            return(true);
        }
示例#6
0
        private static string?IcuLCIDToLocaleName(int culture)
        {
            Debug.Assert(!GlobalizationMode.Invariant);
            Debug.Assert(!GlobalizationMode.UseNls);

            return(IcuLocaleData.LCIDToLocaleName(culture));
        }
示例#7
0
        private static int IcuGetOemCodePage(string cultureName)
        {
            Debug.Assert(!GlobalizationMode.UseNls);
            int oemCodePage = IcuLocaleData.GetLocaleDataNumericPart(cultureName, IcuLocaleDataParts.OemCodePage);

            return(oemCodePage == -1 ? CultureData.Invariant.OEMCodePage : oemCodePage);
        }
示例#8
0
        private static int IcuGetAnsiCodePage(string cultureName)
        {
            Debug.Assert(!GlobalizationMode.UseNls);
            int ansiCodePage = IcuLocaleData.GetLocaleDataNumericPart(cultureName, IcuLocaleDataParts.AnsiCodePage);

            return(ansiCodePage == -1 ? CultureData.Invariant.ANSICodePage : ansiCodePage);
        }
示例#9
0
        private const int ICU_ULOC_FULLNAME_CAPACITY           = 157; // max size of locale name

        /// <summary>
        /// This method uses the sRealName field (which is initialized by the constructor before this is called) to
        /// initialize the rest of the state of CultureData based on the underlying OS globalization library.
        /// </summary>
        private bool InitIcuCultureDataCore()
        {
            Debug.Assert(_sRealName != null);
            Debug.Assert(!GlobalizationMode.Invariant);

            const string ICU_COLLATION_KEYWORD = "@collation=";
            string       realNameBuffer        = _sRealName;

            // Basic validation
            if (!IsValidCultureName(realNameBuffer, out var index))
            {
                return(false);
            }

            // Replace _ (alternate sort) with @collation= for ICU
            ReadOnlySpan <char> alternateSortName = default;

            if (index > 0)
            {
                alternateSortName = realNameBuffer.AsSpan(index + 1);
                realNameBuffer    = string.Concat(realNameBuffer.AsSpan(0, index), ICU_COLLATION_KEYWORD, alternateSortName);
            }

            // Get the locale name from ICU
            if (!GetLocaleName(realNameBuffer, out _sWindowsName))
            {
                return(false); // fail
            }

            // Replace the ICU collation keyword with an _
            Debug.Assert(_sWindowsName != null);
            index = _sWindowsName.IndexOf(ICU_COLLATION_KEYWORD, StringComparison.Ordinal);
            if (index >= 0)
            {
                _sName = string.Concat(_sWindowsName.AsSpan(0, index), "_", alternateSortName);
            }
            else
            {
                _sName = _sWindowsName;
            }
            _sRealName = _sName;

            _iLanguage = LCID;
            if (_iLanguage == 0)
            {
                _iLanguage = CultureInfo.LOCALE_CUSTOM_UNSPECIFIED;
            }

            _bNeutral = TwoLetterISOCountryName.Length == 0;

            _sSpecificCulture = _bNeutral ? IcuLocaleData.GetSpecificCultureName(_sRealName) : _sRealName;

            // Remove the sort from sName unless custom culture
            if (index > 0 && !_bNeutral && !IsCustomCultureId(_iLanguage))
            {
                _sName = _sWindowsName.Substring(0, index);
            }
            return(true);
        }
示例#10
0
        private static int IcuLocaleNameToLCID(string cultureName)
        {
            Debug.Assert(!GlobalizationMode.Invariant);
            Debug.Assert(!GlobalizationMode.UseNls);

            int lcid = IcuLocaleData.GetLocaleDataNumericPart(cultureName, IcuLocaleDataParts.Lcid);

            return(lcid == -1 ? CultureInfo.LOCALE_CUSTOM_UNSPECIFIED : lcid);
        }
示例#11
0
        private static int GetEbcdicCodePage(string cultureName)
        {
            int ebcdicCodePage = IcuLocaleData.GetLocaleDataNumericPart(cultureName, IcuLocaleDataParts.EbcdicCodePage);

            return(ebcdicCodePage == -1 ? CultureData.Invariant.EBCDICCodePage : ebcdicCodePage);
        }
示例#12
0
        private static int GetOemCodePage(string cultureName)
        {
            int oemCodePage = IcuLocaleData.GetLocaleDataNumericPart(cultureName, IcuLocaleDataParts.OemCodePage);

            return(oemCodePage == -1 ? CultureData.Invariant.OEMCodePage : oemCodePage);
        }
示例#13
0
        private static int GetAnsiCodePage(string cultureName)
        {
            int ansiCodePage = IcuLocaleData.GetLocaleDataNumericPart(cultureName, IcuLocaleDataParts.AnsiCodePage);

            return(ansiCodePage == -1 ? CultureData.Invariant.ANSICodePage : ansiCodePage);
        }
示例#14
0
 private static string IcuGetThreeLetterWindowsLanguageName(string cultureName)
 {
     Debug.Assert(!GlobalizationMode.UseNls);
     return(IcuLocaleData.GetThreeLetterWindowsLanguageName(cultureName) ?? "ZZZ" /* default lang name */);
 }
示例#15
0
        private static int GetMacCodePage(string cultureName)
        {
            int macCodePage = IcuLocaleData.GetLocaleDataNumericPart(cultureName, IcuLocaleDataParts.MacCodePage);

            return(macCodePage == -1 ? CultureData.Invariant.MacCodePage : macCodePage);
        }
示例#16
0
 private static string IcuGetConsoleFallbackName(string cultureName)
 {
     Debug.Assert(!GlobalizationMode.UseNls);
     return(IcuLocaleData.GetConsoleUICulture(cultureName));
 }
示例#17
0
        /// <summary>
        /// This method uses the sRealName field (which is initialized by the constructor before this is called) to
        /// initialize the rest of the state of CultureData based on the underlying OS globalization library.
        /// </summary>
        private unsafe bool IcuInitCultureData()
        {
            Debug.Assert(_sRealName != null);

            Debug.Assert(!GlobalizationMode.Invariant);
            Debug.Assert(!GlobalizationMode.UseNls);

            string realNameBuffer = _sRealName;

            // Basic validation
            if (realNameBuffer.Contains('@'))
            {
                return(false); // don't allow ICU variants to come in directly
            }

            // Replace _ (alternate sort) with @collation= for ICU
            ReadOnlySpan <char> alternateSortName = default;
            int index = realNameBuffer.IndexOf('_');

            if (index > 0)
            {
                if (index >= (realNameBuffer.Length - 1) || // must have characters after _
                    realNameBuffer.IndexOf('_', index + 1) >= 0) // only one _ allowed
                {
                    return(false);                               // fail
                }
                alternateSortName = realNameBuffer.AsSpan(index + 1);
                realNameBuffer    = string.Concat(realNameBuffer.AsSpan(0, index), ICU_COLLATION_KEYWORD, alternateSortName);
            }

            // Get the locale name from ICU
            if (!GetLocaleName(realNameBuffer, out _sWindowsName))
            {
                return(false); // fail
            }

            // Replace the ICU collation keyword with an _
            Debug.Assert(_sWindowsName != null);
            index = _sWindowsName.IndexOf(ICU_COLLATION_KEYWORD, StringComparison.Ordinal);
            if (index >= 0)
            {
                _sName = string.Concat(_sWindowsName.AsSpan(0, index), "_", alternateSortName);
            }
            else
            {
                _sName = _sWindowsName;
            }
            _sRealName = _sName;

            _iLanguage = LCID;
            if (_iLanguage == 0)
            {
                _iLanguage = CultureInfo.LOCALE_CUSTOM_UNSPECIFIED;
            }

            _bNeutral = TwoLetterISOCountryName.Length == 0;

            _sSpecificCulture = _bNeutral ? IcuLocaleData.GetSpecificCultureName(_sRealName) : _sRealName;

            // Remove the sort from sName unless custom culture
            if (index > 0 && !_bNeutral && !IsCustomCultureId(_iLanguage))
            {
                _sName = _sWindowsName.Substring(0, index);
            }
            return(true);
        }