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