Merge pull request #1542 from ninjarobot/UriTemplateMatchException
[mono.git] / mcs / class / corlib / ReferenceSources / EncodingDataItem.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 namespace System.Globalization {
7     using System.Text;
8     using System.Runtime.Remoting;
9     using System;
10     using System.Security;
11
12     //
13     // Data item for EncodingTable.  Along with EncodingTable, they are used by 
14     // System.Text.Encoding.
15     // 
16     // This class stores a pointer to the internal data and the index into that data
17     // where our required information is found.  We load the code page, flags and uiFamilyCodePage
18     // immediately because they don't require creating an object.  Creating any of the string
19     // names is delayed until somebody actually asks for them and the names are then cached.
20     
21     [Serializable]
22     internal class CodePageDataItem
23     {
24         internal int    m_dataIndex;
25         internal int    m_uiFamilyCodePage;
26         internal String m_webName;
27         internal String m_headerName;
28         internal String m_bodyName;
29         internal uint   m_flags;
30     
31         [SecurityCritical]
32         unsafe internal CodePageDataItem(int dataIndex) {
33             m_dataIndex = dataIndex;
34             m_uiFamilyCodePage = EncodingTable.codePageDataPtr[dataIndex].uiFamilyCodePage;
35             m_flags = EncodingTable.codePageDataPtr[dataIndex].flags;
36         }
37
38                 static readonly char [] sep = {'|'};
39
40         [System.Security.SecurityCritical]
41         unsafe internal static String CreateString(string pStrings, uint index)
42         {
43             if (pStrings[0] == '|') // |str1|str2|str3
44             {
45                                 return pStrings.Split (sep, StringSplitOptions.RemoveEmptyEntries) [index];
46                                 /*
47                 int start = 1;
48                 
49                 for (int i = 1; true; i ++)
50                 {
51                     sbyte ch = pStrings[i];
52
53                     if ((ch == '|') || (ch == 0))
54                     {
55                         if (index == 0)
56                         {
57                             return new String(pStrings, start, i - start);
58                         }
59
60                         index --;
61                         start = i + 1;
62
63                         if (ch == 0)
64                         {
65                             break;
66                         }
67                     }
68                 }
69
70                 throw new ArgumentException("pStrings");
71                 */
72             }
73             else
74             {
75                                 return pStrings;
76                 //return new String(pStrings);
77             }
78         }
79
80         unsafe public String WebName {
81             [System.Security.SecuritySafeCritical]  // auto-generated
82             get {
83                 if (m_webName==null) {
84                     m_webName = CreateString(EncodingTable.codePageDataPtr[m_dataIndex].Names, 0);
85                 }
86                 return m_webName;
87             }
88         }
89     
90         public virtual int UIFamilyCodePage {
91             get {
92                 return m_uiFamilyCodePage;
93             }
94         }
95     
96         unsafe public String HeaderName {
97             [System.Security.SecuritySafeCritical]  // auto-generated
98             get {
99                 if (m_headerName==null) {
100                     m_headerName = CreateString(EncodingTable.codePageDataPtr[m_dataIndex].Names, 1);
101                 }
102                 return m_headerName;
103             }
104         }
105     
106         unsafe public String BodyName {
107             [System.Security.SecuritySafeCritical]  // auto-generated
108             get {
109                 if (m_bodyName==null) {
110                     m_bodyName = CreateString(EncodingTable.codePageDataPtr[m_dataIndex].Names, 2);
111                 }
112                 return m_bodyName;
113             }
114         }    
115
116         unsafe public uint Flags {
117             get {
118                 return (m_flags);
119             }
120         }
121     }
122 }
123