GetDataItemFromCultureID() приватный Метод

private GetDataItemFromCultureID ( int cultureID, String &actualName ) : int
cultureID int
actualName String
Результат int
Пример #1
0
        /// <include file='doc\RegionInfo.uex' path='docs/doc[@for="RegionInfo.RegionInfo1"]/*' />
        public RegionInfo(int culture)
        {
            // Get the culture data item.
            int cultureItem = CultureTable.GetDataItemFromCultureID(CultureInfo.GetLangID(culture));

            if (cultureItem < 0)
            {
                // Not a valid culture ID.
                throw new ArgumentException(Environment.GetResourceString("Argument_CultureNotSupported", culture), "culture");
            }

            if (culture == 0x7F)   //The InvariantCulture has no matching region
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NoRegionInvariantCulture"));
            }

            //
            // From this culture data item, get the region data item.
            // We do this because several culture ID may map to the same region.
            // For example, 0x1009 (English (Canada)) and 0x0c0c (French (Canada)) all map to
            // the same region "CA" (Canada).
            //
            m_dataItem = CultureTable.GetDefaultInt32Value(cultureItem, CultureTable.IREGIONITEM);
            if (m_dataItem == 0xffff)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_CultureIsNeutral", culture), "culture");
            }
        }
Пример #2
0
        internal int culture;               // the culture ID used to create this instance.


        ////////////////////////////////////////////////////////////////////////
        //
        //  CompareInfo Constructor
        //
        //
        ////////////////////////////////////////////////////////////////////////


        // Constructs an instance that most closely corresponds to the NLS locale
        // identifier.
        internal unsafe CompareInfo(GlobalizationAssembly ga, int culture)
        {
            if (culture < 0)
            {
                throw new ArgumentOutOfRangeException("culture", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
            }

            // NOTENOTE YSLin: In the future, move all the culture validation to the native code InitializeCompareInfo, since we make three
            // native calls below, which are expansive.

            //
            // Verify that this is a valid culture.
            //
            int dataItem = CultureTable.GetDataItemFromCultureID(CultureInfo.GetLangID(culture));

            if (dataItem == -1)
            {
                throw new ArgumentException(
                          String.Format(Environment.GetResourceString("Argument_CultureNotSupported"), culture), "culture");
            }

            // We do the following because the native C++ SortingTable is based on the
            // WIN32 LCID.  It doesn't work for neutral cultures liek 0x0009.  So we convert culture
            // to a Win32 LCID here.

            // Note that we have to get Sort ID from culture.  This will affect the result of string comparison.
            this.win32LCID = CultureTable.GetDefaultInt32Value(dataItem, CultureTable.WIN32LANGID);

            int sortID = CultureInfo.GetSortID(culture);

            if (sortID != 0)
            {
                // Need to verify if the Sort ID is valid.
                if (!CultureTable.IsValidSortID(dataItem, sortID))
                {
                    throw new ArgumentException(
                              String.Format(Environment.GetResourceString("Argument_CultureNotSupported"), culture), "culture");
                }
                // This is an alterinative sort LCID.  Hey man, don't forget to take your SORTID with you.
                win32LCID |= sortID << 16;
            }

            // TODO: InitializeCompareInfo should use ga instead of getting the default instance.

            // Call to the native side to create/get the corresponding native C++ SortingTable for this culture.
            // The returned value is a 32-bit pointer to the native C++ SortingTable instance.
            // We cache this pointer so that we can call methods of the SortingTable directly.
            pSortingTable = InitializeCompareInfo(GlobalizationAssembly.m_defaultInstance.pNativeGlobalizationAssembly, win32LCID);
            // Since win32LCID can be different from the passed-in culture in the case of neutral cultures, store the culture ID in a different place.
            this.culture = culture;
        }
Пример #3
0
        /// <include file='doc\CultureInfo.uex' path='docs/doc[@for="CultureInfo.CultureInfo3"]/*' />
        public CultureInfo(int culture, bool useUserOverride)
        {
            if (culture < 0)
            {
                throw new ArgumentOutOfRangeException("culture",
                                                      Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
            }

            if (culture == SPANISH_TRADITIONAL_SORT)
            {
                // HACKHACK
                // We are nuking 0x040a (Spanish Traditional sort) in NLS+.
                // So if you create 0x040a, it's just like 0x0c0a (Spanish International sort).
                // For a table setup reason, we can not really remove the data item for 0x040a in culture.nlp.
                // As a workaround, what we do is to make the data for 0x040a to be exactly the same as 0x0c0a.
                // Unfortunately, the culture name is the only exception.
                // So in the table, we still have "es-ES-Ts" in there which we can not make it "es-ES".
                // Again, this is for table setup reason.  So if we are creating
                // CultureInfo using 0x040a, hardcode culture name to be "es-ES" here so that we won't
                // get "es-ES-Ts" in the table.
                m_name = "es-ES";
            }
            m_dataItem = CultureTable.GetDataItemFromCultureID(GetLangID(culture));

            if (m_dataItem < 0)
            {
                throw new ArgumentException(
                          String.Format(Environment.GetResourceString("Argument_CultureNotSupported"), culture), "culture");
            }
            this.m_useUserOverride = useUserOverride;

            int sortID;

            if ((sortID = GetSortID(culture)) != 0)
            {
                //
                // Check if the sort ID is valid.
                //
                if (!CultureTable.IsValidSortID(m_dataItem, sortID))
                {
                    throw new ArgumentException(
                              String.Format(Environment.GetResourceString("Argument_CultureNotSupported"), culture), "culture");
                }
            }
            this.cultureID = culture;
        }