Beispiel #1
0
        /*=================================GetDataItemFromName============================
         **Action:   Given a culture name, return a index which points to a data item in
         **          the Culture Data Table
         **Returns:  the data item index. Or -1 if the culture name is invalid.
         **Arguments:
         **      name culture name
         **Exceptions:
         **==============================================================================*/
        unsafe internal int GetDataItemFromCultureName(String name, out int culture, out String actualName)
        {
            BCLDebug.Assert(name != null, "CultureTable.GetDataItemFromCultureName(): name!=null");
            culture    = -1;
            actualName = "";

            CultureTableItem cti = (CultureTableItem)hashByName[name];

            if (null != cti &&
                0 != cti.culture)
            {
                culture    = cti.culture;
                actualName = cti.name;
                return(cti.dataItem);
            }

            int left  = 0;
            int right = m_pCultureHeader->numCultureNames - 1;

            while (left <= right)
            {
                int mid = (left + right) / 2;

                int result = CompareStringToStringPoolStringBinary(name, m_pCultureNameIndex[mid].strOffset);

                if (result == 0)
                {
                    cti = new CultureTableItem();
                    int index = cti.dataItem = m_pCultureNameIndex[mid].dataItemIndex;
                    culture    = cti.culture = m_pCultureNameIndex[mid].actualCultureID;
                    actualName = cti.name = GetStringPoolString(m_pCultureNameIndex[mid].strOffset);

                    // m_pCultureNameIndex[i].dateItemIndex is the record number for
                    // the information of a culture.
                    // The trick that we play to remove es-ES-Ts is to put a duplicate entry
                    // in the name offset table for es-ES, so that es-ES-Ts is not in the name offset table
                    // Therefore, es-ES-Ts becomes an invalid name.
                    // However, the data item for es-ES-Ts is still there.  It is just that
                    // you can not find it by calling GetDataItemFromName.
                    hashByName[name] = cti;
                    return(index);
                }
                if (result < 0)
                {
                    right = mid - 1;
                }
                else
                {
                    left = mid + 1;
                }
            }

            culture = -1;
            return(-1);
        }
Beispiel #2
0
        /*=================================GetDataItemFromCultureID============================
         **Action:   Given a culture ID, return a index which points to a data item in
         **          the Culture Data Table
         **Returns:  the data item index.  Or -1 if the culture ID is invalid.
         **Arguments:
         **      cultureID
         **Exceptions: None.
         **==============================================================================*/

        unsafe internal int GetDataItemFromCultureID(int cultureID, out String actualName)
        {
            BCLDebug.Assert(cultureID != 0, "CultureTable.GetDataItemFromCultureID(): cultureID!=0");

            CultureTableItem cti = (CultureTableItem)hashByLcid[cultureID];

            if (null != cti &&
                0 != cti.culture)
            {
                actualName = cti.name;
                return(cti.dataItem);
            }

            int left  = 0;
            int right = m_pCultureHeader->numCultureNames - 1;

            while (left <= right)
            {
                int mid    = (left + right) / 2;
                int result = cultureID - this.m_pCultureIDIndex[mid].actualCultureID;
                if (result == 0)
                {
                    cti = new CultureTableItem();
                    int index   = cti.dataItem = m_pCultureIDIndex[mid].dataItemIndex;
                    int culture = cti.culture = cultureID;

                    actualName = cti.name = GetStringPoolString(m_pCultureIDIndex[mid].strOffset);

                    hashByLcid[cultureID] = cti;
                    return(index);
                }
                if (result < 0)
                {
                    right = mid - 1;
                }
                else
                {
                    left = mid + 1;
                }
            }

            actualName = "";
            return(-1);
        }
        /*=================================GetDataItemFromCultureID============================
        **Action:   Given a culture ID, return a index which points to a data item in
        **          the Culture Data Table
        **Returns:  the data item index.  Or -1 if the culture ID is invalid.
        **Arguments:
        **      cultureID
        **Exceptions: None.
        ==============================================================================*/

        unsafe internal int GetDataItemFromCultureID(int cultureID, out String actualName)
        {
            BCLDebug.Assert(cultureID!=0,"CultureTable.GetDataItemFromCultureID(): cultureID!=0");

            CultureTableItem cti  = (CultureTableItem)hashByLcid[cultureID];
            if(null != cti &&
               0 != cti.culture) {
                actualName = cti.name;
                return (cti.dataItem);
            }

            int left = 0;
            int right = m_pCultureHeader->numCultureNames - 1;

            while (left <= right) {
                int mid = (left+right)/2;
                int result =  cultureID - this.m_pCultureIDIndex[mid].actualCultureID;
                if (result == 0) {
                    cti = new CultureTableItem();
                    int index = cti.dataItem = m_pCultureIDIndex[mid].dataItemIndex;
                    int culture = cti.culture = cultureID;

                    actualName = cti.name = GetStringPoolString(m_pCultureIDIndex[mid].strOffset);

                    hashByLcid[cultureID] = cti;
                    return (index);
                }
                if (result < 0) {
                    right = mid - 1;
                } else {
                    left = mid + 1;
                }
            }

            actualName = "";
            return (-1);
        }
        /*=================================GetDataItemFromName============================
        **Action:   Given a culture name, return a index which points to a data item in
        **          the Culture Data Table
        **Returns:  the data item index. Or -1 if the culture name is invalid.
        **Arguments:
        **      name culture name
        **Exceptions:
        ==============================================================================*/
        unsafe internal int GetDataItemFromCultureName(String name, out int culture, out String actualName) {
            BCLDebug.Assert(name!=null,"CultureTable.GetDataItemFromCultureName(): name!=null");
            culture = -1;
            actualName = "";

            CultureTableItem cti  = (CultureTableItem)hashByName[name];
            if(null != cti &&
               0 != cti.culture) {
                culture = cti.culture;
                actualName = cti.name;
                return (cti.dataItem);
            }

            int left = 0;
            int right = m_pCultureHeader->numCultureNames - 1;

            while (left <= right) {
                int mid = (left+right)/2;

                int result = CompareStringToStringPoolStringBinary(name, m_pCultureNameIndex[mid].strOffset);

                if (result == 0) {
                    cti = new CultureTableItem();
                    int index = cti.dataItem = m_pCultureNameIndex[mid].dataItemIndex;
                    culture = cti.culture = m_pCultureNameIndex[mid].actualCultureID;
                    actualName = cti.name = GetStringPoolString(m_pCultureNameIndex[mid].strOffset);

                    // m_pCultureNameIndex[i].dateItemIndex is the record number for
                    // the information of a culture.
                    // The trick that we play to remove es-ES-Ts is to put a duplicate entry
                    // in the name offset table for es-ES, so that es-ES-Ts is not in the name offset table
                    // Therefore, es-ES-Ts becomes an invalid name.
                    // However, the data item for es-ES-Ts is still there.  It is just that
                    // you can not find it by calling GetDataItemFromName.
                    hashByName[name] = cti;
                    return (index);
                }
                if (result < 0) {
                    right = mid - 1;
                } else {
                    left = mid + 1;
                }
            }

            culture = -1;
            return (-1);
        }