1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
9 namespace System.Globalization
12 // Data item for EncodingTable. Along with EncodingTable, they are used by
13 // System.Text.Encoding.
15 // This class stores a pointer to the internal data and the index into that data
16 // where our required information is found. We load the code page, flags and uiFamilyCodePage
17 // immediately because they don't require creating an object. Creating any of the string
18 // names is delayed until somebody actually asks for them and the names are then cached.
20 internal class CodePageDataItem
22 internal int m_dataIndex;
23 internal int m_uiFamilyCodePage;
24 internal String m_webName;
25 internal String m_headerName;
26 internal String m_bodyName;
27 internal uint m_flags;
29 internal unsafe CodePageDataItem(int dataIndex)
31 m_dataIndex = dataIndex;
32 m_uiFamilyCodePage = EncodingTable.codePageDataPtr[dataIndex].uiFamilyCodePage;
33 m_flags = EncodingTable.codePageDataPtr[dataIndex].flags;
36 internal static unsafe String CreateString(sbyte* pStrings, uint index)
38 if (pStrings[0] == '|') // |str1|str2|str3
42 for (int i = 1; true; i++)
44 sbyte ch = pStrings[i];
46 if ((ch == '|') || (ch == 0))
50 return new String(pStrings, start, i - start);
63 throw new ArgumentException(null, nameof(pStrings));
67 return new String(pStrings);
71 public unsafe String WebName
75 if (m_webName == null)
77 m_webName = CreateString(EncodingTable.codePageDataPtr[m_dataIndex].Names, 0);
83 public virtual int UIFamilyCodePage
87 return m_uiFamilyCodePage;
91 public unsafe String HeaderName
95 if (m_headerName == null)
97 m_headerName = CreateString(EncodingTable.codePageDataPtr[m_dataIndex].Names, 1);
103 public unsafe String BodyName
107 if (m_bodyName == null)
109 m_bodyName = CreateString(EncodingTable.codePageDataPtr[m_dataIndex].Names, 2);
115 public unsafe uint Flags