@@ -5,6 +5,7 @@ export const enum Char {
5
5
FormFeed = 0x0c ,
6
6
CarriageReturn = 0x0d ,
7
7
LineFeed = 0x0a ,
8
+ Space = 0x20 ,
8
9
Dollar = 0x24 , // "$"
9
10
LeftParenthesis = 0x28 ,
10
11
RightParenthesis = 0x29 ,
@@ -14,11 +15,13 @@ export const enum Char {
14
15
Minus = 0x2d , // "-"
15
16
Dot = 0x2e , // "."
16
17
Zero = 0x30 ,
18
+ Nine = 0x39 ,
17
19
Question = 0x3f , // "?"
18
20
A = 0x41 ,
19
21
D = 0x44 ,
20
22
S = 0x53 ,
21
23
W = 0x57 ,
24
+ Z = 0x5a ,
22
25
LeftSquareBracket = 0x5b , // "["
23
26
Backslash = 0x5c , // "\"
24
27
RightSquareBracket = 0x5d , // "]"
@@ -35,40 +38,58 @@ export const enum Char {
35
38
v = 0x76 ,
36
39
w = 0x77 ,
37
40
x = 0x78 ,
41
+ z = 0x7a ,
38
42
LeftCurlyBrace = 0x7b /* { */ ,
39
43
VerticalBar = 0x7c /* | */ ,
40
- RightCurlyBrace = 0x7d /* */ ,
44
+ RightCurlyBrace = 0x7d /* { */ ,
45
+ NonBreakingSpace = 0xa0 ,
46
+ }
47
+
48
+ // @ts -ignore
49
+ @inline
50
+ function inRange ( value : u32 , from : u32 , to : u32 ) : bool {
51
+ if ( ASC_TARGET == 1 ) {
52
+ // makes use of unsigned integer operations, making this
53
+ // approach a little faster when compiled to WASM
54
+ return value - from < ( to - from + 1 ) ;
55
+ } else {
56
+ return value >= from && value <= to ;
57
+ }
41
58
}
42
59
43
60
export function isDigit ( code : u32 ) : bool {
44
- return code - Char . Zero < 10 ;
61
+ return inRange ( code , Char . Zero , Char . Nine ) ;
45
62
}
46
63
47
64
export function isHexadecimalDigit ( code : u32 ) : bool {
48
- return isDigit ( code ) || code - Char . a < 6 ;
65
+ return isDigit ( code ) || inRange ( code , Char . a , Char . f ) ;
49
66
}
50
67
51
68
export function isLowercaseAlpha ( code : u32 ) : bool {
52
- return code - Char . a < 26 ;
69
+ return inRange ( code , Char . a , Char . z ) ;
53
70
}
54
71
55
72
export function isUppercaseAlpha ( code : u32 ) : bool {
56
- return code - Char . A < 26 ;
73
+ return inRange ( code , Char . A , Char . Z ) ;
57
74
}
58
75
59
76
export function isAlpha ( code : u32 ) : bool {
60
- return ( code | 32 ) - Char . a < 26 ;
77
+ if ( ASC_TARGET == 1 ) {
78
+ return ( code | 32 ) - Char . a < 26 ;
79
+ } else {
80
+ return inRange ( code , Char . a , Char . z ) || inRange ( code , Char . A , Char . Z ) ;
81
+ }
61
82
}
62
83
63
84
export function isWhitespace ( code : u32 ) : bool {
64
- if ( code < 0x1680 ) {
65
- // < <LS> (1)
66
- // <SP>, <TAB>, <LF>, <VT>, <FF>, <CR> and <NBSP>
67
- // @ts -ignore: cast
68
- return ( ( code | 0x80 ) == 0xa0 ) | ( code - 0x09 <= 0x0d - 0x09 ) ;
69
- }
70
- if ( code - 0x2000 <= 0x200a - 0x2000 ) return true ;
71
85
switch ( code ) {
86
+ case Char . Space :
87
+ case Char . HorizontalTab :
88
+ case Char . VerticalTab :
89
+ case Char . FormFeed :
90
+ case Char . LineFeed :
91
+ case Char . CarriageReturn :
92
+ case Char . NonBreakingSpace :
72
93
case 0x1680 : // <LS> (1)
73
94
case 0x2028 : // <LS> (2)
74
95
case 0x2029 : // <PS>
@@ -78,5 +99,8 @@ export function isWhitespace(code: u32): bool {
78
99
case 0xfeff :
79
100
return true ; // <ZWNBSP>
80
101
}
102
+ if ( inRange ( code , 0x2000 , 0x200a ) ) {
103
+ return true ;
104
+ }
81
105
return false ;
82
106
}
0 commit comments