1
1
module hunt.sql.parser.CharTypes ;
2
2
3
3
// import hunt.sql.parser.LayoutCharacters.EOI;
4
- import std.conv ;
5
4
import hunt.sql.parser.LayoutCharacters;
6
5
7
- public class CharTypes {
8
-
9
- private static bool [] hexFlags = new bool [256 ];
10
-
11
-
12
- public static bool isHex (char c) {
13
- return c < 256 && hexFlags[c];
14
- }
15
-
16
- public static bool isDigit (char c) {
17
- return c >= ' 0' && c <= ' 9' ;
18
- }
19
-
20
- private static bool [] firstIdentifierFlags = new bool [256 ];
21
-
22
-
23
- public static bool isFirstIdentifierChar (char c) {
24
- if (c <= firstIdentifierFlags.length) {
25
- return firstIdentifierFlags[c];
26
- }
27
- return c != ' ' && c != ' ,' ;
28
- }
29
-
30
- private static string [] stringCache = new string [256 ];
31
- private static bool [] identifierFlags = new bool [256 ];
32
-
33
-
34
- public static bool isIdentifierChar (char c) {
35
- if (c <= identifierFlags.length) {
36
- return identifierFlags[c];
37
- }
38
- return c != ' ' && c != ' ,' && c != ' )' ;
39
- }
6
+ import std.conv ;
7
+ import std.stdio ;
40
8
41
- public static string valueOf (char ch) {
42
- if (ch < stringCache.length) {
43
- return stringCache[ch];
44
- }
45
- return null ;
46
- }
9
+ public class CharTypes {
47
10
48
- private static bool [] whitespaceFlags = new bool [256 ];
11
+ private __gshared bool [] hexFlags;
12
+ private __gshared bool [] firstIdentifierFlags;
13
+ private __gshared string [] stringCache;
14
+ private __gshared bool [] identifierFlags;
15
+ private __gshared bool [] whitespaceFlags;
49
16
50
- /**
51
- * @return false if {@link LayoutCharacters#EOI}
52
- */
53
- public static bool isWhitespace (char c) {
54
- return (c <= whitespaceFlags.length && whitespaceFlags[c]) //
55
- || c == ' ' ; // Chinese space
56
- }
17
+ shared static this () {
18
+ hexFlags = new bool [256 ];
19
+ firstIdentifierFlags = new bool [256 ];
20
+ stringCache = new string [256 ];
21
+ identifierFlags = new bool [256 ];
22
+ whitespaceFlags = new bool [256 ];
57
23
58
- }
59
-
60
- static this ()
61
- {
62
- import std.stdio ;
63
24
for (dchar c = 0 ; c < CharTypes.hexFlags.length; ++ c) {
64
25
if (c >= ' A' && c <= ' F' ) {
65
26
CharTypes.hexFlags[c] = true ;
@@ -111,6 +72,49 @@ static this()
111
72
CharTypes.whitespaceFlags[i] = true ;
112
73
}
113
74
114
- CharTypes.whitespaceFlags[160 ] = true ; // 特别处理
75
+ CharTypes.whitespaceFlags[160 ] = true ;
76
+ }
77
+
78
+
79
+ public static bool isHex (char c) {
80
+ return c < 256 && hexFlags[c];
81
+ }
82
+
83
+ public static bool isDigit (char c) {
84
+ return c >= ' 0' && c <= ' 9' ;
85
+ }
86
+
115
87
116
- }
88
+ public static bool isFirstIdentifierChar (char c) {
89
+ if (c <= firstIdentifierFlags.length) {
90
+ return firstIdentifierFlags[c];
91
+ }
92
+ return c != ' ' && c != ' ,' ;
93
+ }
94
+
95
+
96
+
97
+ public static bool isIdentifierChar (char c) {
98
+ if (c <= identifierFlags.length) {
99
+ return identifierFlags[c];
100
+ }
101
+ return c != ' ' && c != ' ,' && c != ' )' ;
102
+ }
103
+
104
+ public static string valueOf (char ch) {
105
+ if (ch < stringCache.length) {
106
+ return stringCache[ch];
107
+ }
108
+ return null ;
109
+ }
110
+
111
+
112
+ /**
113
+ * @return false if {@link LayoutCharacters#EOI}
114
+ */
115
+ public static bool isWhitespace (char c) {
116
+ return (c <= whitespaceFlags.length && whitespaceFlags[c]) //
117
+ || c == ' ' ; // Chinese space
118
+ }
119
+
120
+ }
0 commit comments