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.Text;
- using System.Runtime.InteropServices;
- using System;
- using System.Collections;
- using System.Runtime.CompilerServices;
- using System.Threading;
-
-
-
-
-
-
-
- static internal class EncodingTable
- {
-
-
-
- private static int lastEncodingItem = GetNumEncodingItems() - 1;
-
-
- private static int lastCodePageItem;
-
-
-
-
- unsafe static internal InternalEncodingDataItem* encodingDataPtr = GetEncodingData();
-
-
-
-
- unsafe static internal InternalCodePageDataItem* codePageDataPtr = GetCodePageData();
-
-
-
- static internal Hashtable hashByName = new Hashtable(StringComparer.OrdinalIgnoreCase);
-
-
-
- static internal Hashtable hashByCodePage = new Hashtable();
-
-
-
- unsafe private static int internalGetCodePageFromName(string name)
- {
- int left = 0;
- int right = lastEncodingItem;
- int index;
- int result;
-
-
-
- while ((right - left) > 3) {
- index = ((right - left) / 2) + left;
-
- bool success;
- result = String.nativeCompareOrdinalWC(name, encodingDataPtr[index].webName, true, out success);
-
- if (result == 0) {
-
- return (encodingDataPtr[index].codePage);
- }
- else if (result < 0) {
-
- right = index;
- }
- else {
-
- left = index;
- }
- }
-
-
- for (; left <= right; left++) {
- bool success;
- if (String.nativeCompareOrdinalWC(name, encodingDataPtr[left].webName, true, out success) == 0) {
- return (encodingDataPtr[left].codePage);
- }
- }
-
- throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_EncodingNotSupported"), name), "name");
- }
-
-
- unsafe static internal EncodingInfo[] GetEncodings()
- {
- if (lastCodePageItem == 0) {
- int count;
- for (count = 0; codePageDataPtr[count].codePage != 0; count++) {
-
- }
- lastCodePageItem = count;
- }
-
- EncodingInfo[] arrayEncodingInfo = new EncodingInfo[lastCodePageItem];
-
- int i;
- for (i = 0; i < lastCodePageItem; i++)
- arrayEncodingInfo[i] = new EncodingInfo(codePageDataPtr[i].codePage, new string(codePageDataPtr[i].webName), Environment.GetResourceString("Globalization.cp_" + codePageDataPtr[i].codePage));
-
- return arrayEncodingInfo;
- }
-
-
-
- static internal int GetCodePageFromName(string name)
- {
- if (name == null) {
- throw new ArgumentNullException("name");
- }
-
- object codePageObj;
-
-
-
-
-
- codePageObj = hashByName[name];
- if (codePageObj != null) {
- return ((int)codePageObj);
- }
-
-
-
- int codePage = internalGetCodePageFromName(name);
-
- hashByName[name] = codePage;
- return (codePage);
- }
-
- unsafe static internal CodePageDataItem GetCodePageDataItem(int codepage)
- {
- CodePageDataItem dataItem;
-
-
- dataItem = (CodePageDataItem)hashByCodePage[codepage];
-
-
- if (dataItem != null) {
- return (dataItem);
- }
-
-
-
-
-
- int i = 0;
- int data;
- while ((data = codePageDataPtr[i].codePage) != 0) {
- if (data == codepage) {
- dataItem = new CodePageDataItem(i);
- hashByCodePage[codepage] = dataItem;
- return (dataItem);
- }
- i++;
- }
-
- return (null);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe private static extern InternalEncodingDataItem* GetEncodingData();
-
-
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern int GetNumEncodingItems();
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe private static extern InternalCodePageDataItem* GetCodePageData();
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe static internal extern byte* nativeCreateOpenFileMapping(string inSectionName, int inBytesToAllocate, out IntPtr mappedFileHandle);
- }
-
-
-
- [System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential)]
- unsafe internal struct InternalEncodingDataItem
- {
- internal char* webName;
- internal int codePage;
- }
-
-
-
- [System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential)]
- unsafe internal struct InternalCodePageDataItem
- {
- internal int codePage;
- internal int uiFamilyCodePage;
- internal char* webName;
- internal char* headerName;
- internal char* bodyName;
- internal uint flags;
- }
-
- }