File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,14 +12,14 @@ export class CharacterClassifier<T extends number> {
1212 /**
1313 * Maintain a compact (fully initialized ASCII map for quickly classifying ASCII characters - used more often in code).
1414 */
15- private _asciiMap : Uint8Array ;
15+ protected _asciiMap : Uint8Array ;
1616
1717 /**
1818 * The entire map (sparse array).
1919 */
20- private _map : Map < number , number > ;
20+ protected _map : Map < number , number > ;
2121
22- private _defaultValue : number ;
22+ protected _defaultValue : number ;
2323
2424 constructor ( _defaultValue : T ) {
2525 let defaultValue = toUint8 ( _defaultValue ) ;
Original file line number Diff line number Diff line change @@ -38,19 +38,23 @@ class WrappingCharacterClassifier extends CharacterClassifier<CharacterClass> {
3838 }
3939
4040 public get ( charCode : number ) : CharacterClass {
41- // Initialize CharacterClass.BREAK_IDEOGRAPHIC for these Unicode ranges:
42- // 1. CJK Unified Ideographs (0x4E00 -- 0x9FFF)
43- // 2. CJK Unified Ideographs Extension A (0x3400 -- 0x4DBF)
44- // 3. Hiragana and Katakana (0x3040 -- 0x30FF)
45- if (
46- ( charCode >= 0x3040 && charCode <= 0x30FF )
47- || ( charCode >= 0x3400 && charCode <= 0x4DBF )
48- || ( charCode >= 0x4E00 && charCode <= 0x9FFF )
49- ) {
50- return CharacterClass . BREAK_IDEOGRAPHIC ;
51- }
41+ if ( charCode >= 0 && charCode < 256 ) {
42+ return < CharacterClass > this . _asciiMap [ charCode ] ;
43+ } else {
44+ // Initialize CharacterClass.BREAK_IDEOGRAPHIC for these Unicode ranges:
45+ // 1. CJK Unified Ideographs (0x4E00 -- 0x9FFF)
46+ // 2. CJK Unified Ideographs Extension A (0x3400 -- 0x4DBF)
47+ // 3. Hiragana and Katakana (0x3040 -- 0x30FF)
48+ if (
49+ ( charCode >= 0x3040 && charCode <= 0x30FF )
50+ || ( charCode >= 0x3400 && charCode <= 0x4DBF )
51+ || ( charCode >= 0x4E00 && charCode <= 0x9FFF )
52+ ) {
53+ return CharacterClass . BREAK_IDEOGRAPHIC ;
54+ }
5255
53- return super . get ( charCode ) ;
56+ return < CharacterClass > ( this . _map . get ( charCode ) || this . _defaultValue ) ;
57+ }
5458 }
5559}
5660
You can’t perform that action at this time.
0 commit comments