1 using System;
2
3
4
5 namespace JsonTokens
6 {
7 public const int END = 0;
8
9 public const int STRING = 1;
10
11 public const int NUMBER = 2;
12
13 public const int LBRACKET = 3;
14
15 public const int RBRACKET = 4;
16
17 public const int LBRACE = 5;
18
19 public const int RBRACE = 6;
20
21 public const int COMMA = 7;
22
23 public const int COLON = 8;
24
25 public const int TRUE = 9;
26
27 public const int FALSE = 10;
28
29 public const int NULL = 11;
30
31 internal class TokenMap
32 {
33 static TokenMap() :
34 instance(new TokenMap())
35 {
36 }
37 public static TokenMap& Instance()
38 {
39 return *instance;
40 }
41 public int GetTokenId(const ustring& tokenName)
42 {
43 System.Collections.Map<ustring, int>.ConstIterator it = tokenIdMap.CFind(tokenName);
44 if (it != tokenIdMap.CEnd())
45 {
46 return it->second;
47 }
48 else
49 {
50 return -1;
51 }
52 }
53 public ustring GetTokenName(int tokenId)
54 {
55 return tokenNameList[tokenId];
56 }
57 public ustring GetTokenInfo(int tokenId)
58 {
59 return tokenInfoList[tokenId];
60 }
61 private TokenMap()
62 {
63 tokenIdMap[u"COLON"] = 8;
64 tokenIdMap[u"COMMA"] = 7;
65 tokenIdMap[u"FALSE"] = 10;
66 tokenIdMap[u"LBRACE"] = 5;
67 tokenIdMap[u"LBRACKET"] = 3;
68 tokenIdMap[u"NULL"] = 11;
69 tokenIdMap[u"NUMBER"] = 2;
70 tokenIdMap[u"RBRACE"] = 6;
71 tokenIdMap[u"RBRACKET"] = 4;
72 tokenIdMap[u"STRING"] = 1;
73 tokenIdMap[u"TRUE"] = 9;
74 tokenNameList.Add(u"END");
75 tokenInfoList.Add(u"end of file");
76 tokenNameList.Add(u"STRING");
77 tokenInfoList.Add(u"'string'");
78 tokenNameList.Add(u"NUMBER");
79 tokenInfoList.Add(u"'number'");
80 tokenNameList.Add(u"LBRACKET");
81 tokenInfoList.Add(u"'['");
82 tokenNameList.Add(u"RBRACKET");
83 tokenInfoList.Add(u"']");
84 tokenNameList.Add(u"LBRACE");
85 tokenInfoList.Add(u"{'");
86 tokenNameList.Add(u"RBRACE");
87 tokenInfoList.Add(u"'}'");
88 tokenNameList.Add(u"COMMA");
89 tokenInfoList.Add(u"','");
90 tokenNameList.Add(u"COLON");
91 tokenInfoList.Add(u"':'");
92 tokenNameList.Add(u"TRUE");
93 tokenInfoList.Add(u"'true'");
94 tokenNameList.Add(u"FALSE");
95 tokenInfoList.Add(u"'false'");
96 tokenNameList.Add(u"NULL");
97 tokenInfoList.Add(u"'null'");
98 }
99 private static System.UniquePtr<TokenMap> instance;
100 private System.Collections.Map<ustring, int> tokenIdMap;
101 private System.Collections.List<ustring> tokenNameList;
102 private System.Collections.List<ustring> tokenInfoList;
103 }
104 public int GetTokenId(const ustring& tokenName)
105 {
106 return TokenMap.Instance().GetTokenId(tokenName);
107 }
108
109 public ustring GetTokenName(int tokenId)
110 {
111 return TokenMap.Instance().GetTokenName(tokenId);
112 }
113
114 public ustring GetTokenInfo(int tokenId)
115 {
116 return TokenMap.Instance().GetTokenInfo(tokenId);
117 }
118 }