@@ -139,7 +139,7 @@ export const enum CharCode {
139139}
140140
141141/** Tests if the specified character code is some sort of line break. */
142- export function isLineBreak ( c : CharCode ) : bool {
142+ export function isLineBreak ( c : i32 ) : bool {
143143 switch ( c ) {
144144 case CharCode . LINEFEED :
145145 case CharCode . CARRIAGERETURN :
@@ -175,45 +175,48 @@ export function isWhiteSpace(c: i32): bool {
175175 }
176176}
177177
178+ export function isAlpha ( c : i32 ) : bool {
179+ let c0 = c | 32 ; // unify uppercases and lowercases a|A - z|Z
180+ return c0 >= CharCode . a && c0 <= CharCode . z ;
181+ }
182+
178183/** Tests if the specified character code is a valid decimal digit. */
179- export function isDecimalDigit ( c : i32 ) : bool {
184+ export function isDecimal ( c : i32 ) : bool {
180185 return c >= CharCode . _0 && c <= CharCode . _9 ;
181186}
182187
183188/** Tests if the specified character code is a valid octal digit. */
184- export function isOctalDigit ( c : i32 ) : bool {
189+ export function isOctal ( c : i32 ) : bool {
185190 return c >= CharCode . _0 && c <= CharCode . _7 ;
186191}
187192
188193/** Tests if the specified character code is a valid hexadecimal digit. */
189- export function isHexDigit ( c : i32 ) : bool {
190- return isDecimalDigit ( c ) || ( ( c | 32 ) >= CharCode . a && ( c | 32 ) <= CharCode . f ) ;
194+ export function isHex ( c : i32 ) : bool {
195+ let c0 = c | 32 ; // unify uppercases and lowercases a|A - f|F
196+ return isDecimal ( c ) || ( c0 >= CharCode . a && c0 <= CharCode . f ) ;
191197}
192198
193199/** Tests if the specified character code is trivially alphanumeric. */
194- export function isTrivialAlphanum ( code : i32 ) : bool {
195- return code >= CharCode . a && code <= CharCode . z
196- || code >= CharCode . A && code <= CharCode . Z
197- || code >= CharCode . _0 && code <= CharCode . _9 ;
200+ export function isAlphaOrDecimal ( c : i32 ) : bool {
201+ return isAlpha ( c ) || isDecimal ( c ) ;
198202}
199203
200204/** Tests if the specified character code is a valid start of an identifier. */
201205export function isIdentifierStart ( c : i32 ) : bool {
202- let c0 = c | 32 ; // unify uppercases and lowercases a|A - z|Z
203- return c0 >= CharCode . a && c0 <= CharCode . z
206+ return isAlpha ( c )
204207 || c == CharCode . _
205208 || c == CharCode . DOLLAR
206- || c > 0x7F && isUnicodeIdentifierStart ( c ) ;
209+ || c >= 170 && c <= 65500
210+ && lookupInUnicodeMap ( c as u16 , unicodeIdentifierStart ) ;
207211}
208212
209213/** Tests if the specified character code is a valid part of an identifier. */
210214export function isIdentifierPart ( c : i32 ) : bool {
211- const c0 = c | 32 ; // unify uppercases and lowercases a|A - z|Z
212- return c0 >= CharCode . a && c0 <= CharCode . z
213- || c >= CharCode . _0 && c <= CharCode . _9
215+ return isAlphaOrDecimal ( c )
214216 || c == CharCode . _
215217 || c == CharCode . DOLLAR
216- || c > 0x7F && isUnicodeIdentifierPart ( c ) ;
218+ || c >= 170 && c <= 65500
219+ && lookupInUnicodeMap ( c as u16 , unicodeIdentifierPart ) ;
217220}
218221
219222// storing as u16 to save memory
@@ -354,15 +357,13 @@ const unicodeIdentifierPart: u16[] = [
354357] ;
355358
356359function lookupInUnicodeMap ( code : u16 , map : u16 [ ] ) : bool {
357- if ( code < map [ 0 ] ) return false ;
358-
359360 var lo = 0 ;
360361 var hi = map . length ;
361- var mid : i32 ;
362+ var mid : u32 ;
362363 var midVal : u16 ;
363364
364365 while ( lo + 1 < hi ) {
365- mid = lo + ( ( hi - lo ) >> 1 ) ;
366+ mid = lo + ( ( hi - lo ) >>> 1 ) ;
366367 mid -= ( mid & 1 ) ;
367368 midVal = map [ mid ] ;
368369 if ( midVal <= code && code <= map [ mid + 1 ] ) {
@@ -377,16 +378,6 @@ function lookupInUnicodeMap(code: u16, map: u16[]): bool {
377378 return false ;
378379}
379380
380- function isUnicodeIdentifierStart ( code : i32 ) : bool {
381- return code < 170 || code > 65500 ? false :
382- lookupInUnicodeMap ( code as u16 , unicodeIdentifierStart ) ;
383- }
384-
385- function isUnicodeIdentifierPart ( code : i32 ) : bool {
386- return code < 170 || code > 65500 ? false :
387- lookupInUnicodeMap ( code as u16 , unicodeIdentifierPart ) ;
388- }
389-
390381const indentX1 = " " ;
391382const indentX2 = " " ;
392383const indentX4 = " " ;
0 commit comments