We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- namespace System.Globalization
- {
- using System;
- using System.Collections;
- using System.IO;
- using System.Runtime.Remoting;
- using System.Runtime.InteropServices;
- using System.Runtime.CompilerServices;
- using System.Threading;
- using System.Security.Permissions;
- using System.Runtime.Versioning;
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
- internal abstract class BaseInfoTable
- {
-
- unsafe internal byte* m_pDataFileStart;
-
- protected MemoryMapFile memoryMapFile = null;
-
-
- unsafe protected CultureTableHeader* m_pCultureHeader;
-
-
- unsafe internal byte* m_pItemData;
-
-
- internal uint m_numItem;
-
-
- internal uint m_itemSize;
-
- unsafe internal ushort* m_pDataPool;
-
-
- internal bool fromAssembly;
- internal string fileName;
-
- protected bool m_valid = true;
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
- unsafe internal BaseInfoTable(string fileName, bool fromAssembly)
- {
- this.fileName = fileName;
- this.fromAssembly = fromAssembly;
- InitializeBaseInfoTablePointers(fileName, fromAssembly);
- }
-
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
- unsafe internal void InitializeBaseInfoTablePointers(string fileName, bool fromAssembly)
- {
- if (fromAssembly) {
- m_pDataFileStart = GlobalizationAssembly.GetGlobalizationResourceBytePtr(typeof(BaseInfoTable).Assembly, fileName);
- }
- else {
- this.memoryMapFile = new MemoryMapFile(fileName);
-
- if (this.memoryMapFile.FileSize == 0) {
- m_valid = false;
- return;
- }
-
- this.m_pDataFileStart = this.memoryMapFile.GetBytePtr();
- }
- EndianessHeader* pEndianHeader = (EndianessHeader*)m_pDataFileStart;
-
-
-
- #if BIGENDIAN
- BCLDebug.Assert(pEndianHeader->beOffset != 0, "Big-Endian data is expected.");
- m_pCultureHeader = (CultureTableHeader*)(m_pDataFileStart + pEndianHeader->beOffset);
- #else
- BCLDebug.Assert(pEndianHeader->leOffset != 0, "Little-Endian data is expected.");
- m_pCultureHeader = (CultureTableHeader*)(m_pDataFileStart + pEndianHeader->leOffset);
- #endif
-
-
-
- SetDataItemPointers();
- }
-
-
-
-
-
-
-
- internal bool IsValid {
- get { return m_valid; }
- }
-
- unsafe public override bool Equals(object value)
- {
- BaseInfoTable that = value as BaseInfoTable;
- return (that != null) && (this.fromAssembly == that.fromAssembly && CultureInfo.InvariantCulture.CompareInfo.Compare(this.fileName, that.fileName, CompareOptions.IgnoreCase) == 0);
- }
-
- public override int GetHashCode()
- {
- return (this.fileName.GetHashCode());
- }
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
- ////////////////////////////////////////////////////////////////////////
- unsafe internal abstract void SetDataItemPointers();
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
- ////////////////////////////////////////////////////////////////////////
- unsafe internal string GetStringPoolString(uint offset)
- {
- char* pCharValues = unchecked((char*)(m_pDataPool + offset));
-
- if (pCharValues[1] == 0)
- return (String.Empty);
- return (new string(pCharValues + 1, 0, (int)pCharValues[0]));
- }
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
- ////////////////////////////////////////////////////////////////////////
- unsafe internal string[] GetStringArray(uint iOffset)
- {
-
- if (iOffset == 0)
- return new string[0];
-
-
- ushort* pCount = m_pDataPool + iOffset;
- int count = (int)pCount[0];
-
- string[] values = new string[count];
-
-
- uint* pStringArray = (uint*)(pCount + 1);
-
-
- for (int i = 0; i < count; i++)
- values[i] = GetStringPoolString(pStringArray[i]);
-
- return (values);
- }
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
- unsafe internal int[][] GetWordArrayArray(uint iOffset)
- {
-
- if (iOffset == 0)
- return new int[0][];
-
-
-
- short* pCount = (short*)(m_pDataPool + iOffset);
- int countArrays = (int)pCount[0];
-
- int[][] values = new int[countArrays][];
-
-
- uint* pWordArrays = (uint*)(pCount + 1);
-
-
- for (int i = 0; i < countArrays; i++) {
- pCount = (short*)(m_pDataPool + pWordArrays[i]);
- int count = pCount[0];
- pCount++;
-
- values[i] = new int[count];
- for (int j = 0; j < count; j++) {
- values[i][j] = pCount[j];
- }
- }
-
- return (values);
- }
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
- unsafe internal int CompareStringToStringPoolStringBinary(string name, int offset)
- {
- int test = 0;
- char* pCharValues = unchecked((char*)(m_pDataPool + offset));
-
- if (pCharValues[1] == 0) {
- if (name.Length == 0) {
- return (0);
- }
- return (1);
- }
-
- for (int i = 0; (i < (int)pCharValues[0]) && (i < name.Length); i++) {
- BCLDebug.Assert(!(name[i] >= 'A' && name[i] <= 'Z'), "name should be in lowercase");
-
- test = name[i] - ((pCharValues[i + 1] <= 'Z' && pCharValues[i + 1] >= 'A') ? (pCharValues[i + 1] + 'a' - 'A') : (pCharValues[i + 1]));
-
- if (test != 0) {
- break;
- }
- }
-
- return (test == 0 ? name.Length - (int)pCharValues[0] : test);
- }
- }
- }