| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- import { toUint8 } from '../../../base/common/uint.js';
- /**
- * A fast character classifier that uses a compact array for ASCII values.
- */
- export class CharacterClassifier {
- constructor(_defaultValue) {
- const defaultValue = toUint8(_defaultValue);
- this._defaultValue = defaultValue;
- this._asciiMap = CharacterClassifier._createAsciiMap(defaultValue);
- this._map = new Map();
- }
- static _createAsciiMap(defaultValue) {
- const asciiMap = new Uint8Array(256);
- for (let i = 0; i < 256; i++) {
- asciiMap[i] = defaultValue;
- }
- return asciiMap;
- }
- set(charCode, _value) {
- const value = toUint8(_value);
- if (charCode >= 0 && charCode < 256) {
- this._asciiMap[charCode] = value;
- }
- else {
- this._map.set(charCode, value);
- }
- }
- get(charCode) {
- if (charCode >= 0 && charCode < 256) {
- return this._asciiMap[charCode];
- }
- else {
- return (this._map.get(charCode) || this._defaultValue);
- }
- }
- }
- export class CharacterSet {
- constructor() {
- this._actual = new CharacterClassifier(0 /* Boolean.False */);
- }
- add(charCode) {
- this._actual.set(charCode, 1 /* Boolean.True */);
- }
- has(charCode) {
- return (this._actual.get(charCode) === 1 /* Boolean.True */);
- }
- }
|