1 using System;
2
3
4
5 namespace HttpTokens
6 {
7 public const int END = 0;
8 public const int DIGIT = 1;
9 public const int HEX = 2;
10 public const int ALPHA = 3;
11 public const int HT = 4;
12 public const int DQ = 5;
13 public const int CR = 6;
14 public const int LF = 7;
15 public const int CTL = 8;
16 public const int SP = 9;
17 public const int COLON = 10;
18 public const int SEMICOLON = 11;
19 public const int AT = 12;
20 public const int COMMA = 13;
21 public const int DOT = 14;
22 public const int LPAREN = 15;
23 public const int RPAREN = 16;
24 public const int LANGLE = 17;
25 public const int RANGLE = 18;
26 public const int LBRACKET = 19;
27 public const int RBRACKET = 20;
28 public const int LBRACE = 21;
29 public const int RBRACE = 22;
30 public const int SLASH = 23;
31 public const int BACKSLASH = 24;
32 public const int QUEST = 25;
33 public const int EQ = 26;
34 public const int CHAR = 27;
35 public const int TEXT = 28;
36 public const int OCTET = 29;
37 internal class TokenMap
38 {
39 static TokenMap() :
40 instance(new TokenMap())
41 {
42 }
43 public static TokenMap& Instance()
44 {
45 return *instance;
46 }
47 public int GetTokenId(const ustring& tokenName)
48 {
49 System.Collections.Map<ustring, int>.ConstIterator it = tokenIdMap.CFind(tokenName);
50 if (it != tokenIdMap.CEnd())
51 {
52 return it->second;
53 }
54 else
55 {
56 return -1;
57 }
58 }
59 public ustring GetTokenName(int tokenId)
60 {
61 return tokenNameList[tokenId];
62 }
63 public ustring GetTokenInfo(int tokenId)
64 {
65 return tokenInfoList[tokenId];
66 }
67 private TokenMap()
68 {
69 tokenIdMap[u"ALPHA"] = 3;
70 tokenIdMap[u"AT"] = 12;
71 tokenIdMap[u"BACKSLASH"] = 24;
72 tokenIdMap[u"CHAR"] = 27;
73 tokenIdMap[u"COLON"] = 10;
74 tokenIdMap[u"COMMA"] = 13;
75 tokenIdMap[u"CR"] = 6;
76 tokenIdMap[u"CTL"] = 8;
77 tokenIdMap[u"DIGIT"] = 1;
78 tokenIdMap[u"DOT"] = 14;
79 tokenIdMap[u"DQ"] = 5;
80 tokenIdMap[u"EQ"] = 26;
81 tokenIdMap[u"HEX"] = 2;
82 tokenIdMap[u"HT"] = 4;
83 tokenIdMap[u"LANGLE"] = 17;
84 tokenIdMap[u"LBRACE"] = 21;
85 tokenIdMap[u"LBRACKET"] = 19;
86 tokenIdMap[u"LF"] = 7;
87 tokenIdMap[u"LPAREN"] = 15;
88 tokenIdMap[u"OCTET"] = 29;
89 tokenIdMap[u"QUEST"] = 25;
90 tokenIdMap[u"RANGLE"] = 18;
91 tokenIdMap[u"RBRACE"] = 22;
92 tokenIdMap[u"RBRACKET"] = 20;
93 tokenIdMap[u"RPAREN"] = 16;
94 tokenIdMap[u"SEMICOLON"] = 11;
95 tokenIdMap[u"SLASH"] = 23;
96 tokenIdMap[u"SP"] = 9;
97 tokenIdMap[u"TEXT"] = 28;
98 tokenNameList.Add(u"END");
99 tokenInfoList.Add(u"end of file");
100 tokenNameList.Add(u"DIGIT");
101 tokenInfoList.Add(u"'digit'");
102 tokenNameList.Add(u"HEX");
103 tokenInfoList.Add(u"'hex'");
104 tokenNameList.Add(u"ALPHA");
105 tokenInfoList.Add(u"'alpha'");
106 tokenNameList.Add(u"HT");
107 tokenInfoList.Add(u"'\t'");
108 tokenNameList.Add(u"DQ");
109 tokenInfoList.Add(u"'dq'");
110 tokenNameList.Add(u"CR");
111 tokenInfoList.Add(u"'\r'");
112 tokenNameList.Add(u"LF");
113 tokenInfoList.Add(u"'\n'");
114 tokenNameList.Add(u"CTL");
115 tokenInfoList.Add(u"'ctl'");
116 tokenNameList.Add(u"SP");
117 tokenInfoList.Add(u"' '");
118 tokenNameList.Add(u"COLON");
119 tokenInfoList.Add(u"'colon'");
120 tokenNameList.Add(u"SEMICOLON");
121 tokenInfoList.Add(u"';'");
122 tokenNameList.Add(u"AT");
123 tokenInfoList.Add(u"'@'");
124 tokenNameList.Add(u"COMMA");
125 tokenInfoList.Add(u"','");
126 tokenNameList.Add(u"DOT");
127 tokenInfoList.Add(u"'.'");
128 tokenNameList.Add(u"LPAREN");
129 tokenInfoList.Add(u"'('");
130 tokenNameList.Add(u"RPAREN");
131 tokenInfoList.Add(u"')'");
132 tokenNameList.Add(u"LANGLE");
133 tokenInfoList.Add(u"'<'");
134 tokenNameList.Add(u"RANGLE");
135 tokenInfoList.Add(u"'>'");
136 tokenNameList.Add(u"LBRACKET");
137 tokenInfoList.Add(u"'['");
138 tokenNameList.Add(u"RBRACKET");
139 tokenInfoList.Add(u"']'");
140 tokenNameList.Add(u"LBRACE");
141 tokenInfoList.Add(u"'{'");
142 tokenNameList.Add(u"RBRACE");
143 tokenInfoList.Add(u"'}'");
144 tokenNameList.Add(u"SLASH");
145 tokenInfoList.Add(u"'/'");
146 tokenNameList.Add(u"BACKSLASH");
147 tokenInfoList.Add(u"'\\'");
148 tokenNameList.Add(u"QUEST");
149 tokenInfoList.Add(u"'?'");
150 tokenNameList.Add(u"EQ");
151 tokenInfoList.Add(u"'='");
152 tokenNameList.Add(u"CHAR");
153 tokenInfoList.Add(u"'char'");
154 tokenNameList.Add(u"TEXT");
155 tokenInfoList.Add(u"'text'");
156 tokenNameList.Add(u"OCTET");
157 tokenInfoList.Add(u"'octet'");
158 }
159 private static System.UniquePtr<TokenMap> instance;
160 private System.Collections.Map<ustring, int> tokenIdMap;
161 private System.Collections.List<ustring> tokenNameList;
162 private System.Collections.List<ustring> tokenInfoList;
163 }
164 public int GetTokenId(const ustring& tokenName)
165 {
166 return TokenMap.Instance().GetTokenId(tokenName);
167 }
168 public ustring GetTokenName(int tokenId)
169 {
170 return TokenMap.Instance().GetTokenName(tokenId);
171 }
172 public ustring GetTokenInfo(int tokenId)
173 {
174 return TokenMap.Instance().GetTokenInfo(tokenId);
175 }
176 }