2c2c9032e0643efef0b3acee301cb669273c35f156c921129c16144f1e3862e03ace252c2a1abba852d4dbe189bc4ae9efd9f9dda8b175343dc4076d86ce8f 1.2 KB

12345678910111213141516171819202122232425
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import { CharacterClassifier } from './characterClassifier.js';
  6. export class WordCharacterClassifier extends CharacterClassifier {
  7. constructor(wordSeparators) {
  8. super(0 /* WordCharacterClass.Regular */);
  9. for (let i = 0, len = wordSeparators.length; i < len; i++) {
  10. this.set(wordSeparators.charCodeAt(i), 2 /* WordCharacterClass.WordSeparator */);
  11. }
  12. this.set(32 /* CharCode.Space */, 1 /* WordCharacterClass.Whitespace */);
  13. this.set(9 /* CharCode.Tab */, 1 /* WordCharacterClass.Whitespace */);
  14. }
  15. }
  16. function once(computeFn) {
  17. const cache = {}; // TODO@Alex unbounded cache
  18. return (input) => {
  19. if (!cache.hasOwnProperty(input)) {
  20. cache[input] = computeFn(input);
  21. }
  22. return cache[input];
  23. };
  24. }
  25. export const getMapForWordSeparators = once((input) => new WordCharacterClassifier(input));