From aa985bb2db7d93a766b924ea288bae8649bed0db Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 5 Jul 2021 09:24:06 +0200 Subject: [PATCH] remove canNormalize because String#normalize is now everywhere --- src/vs/base/common/normalization.ts | 29 ++++++++------------------- src/vs/base/test/node/pfs/pfs.test.ts | 5 ++--- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/vs/base/common/normalization.ts b/src/vs/base/common/normalization.ts index 3a94fb716ec..01bd9d5cca4 100644 --- a/src/vs/base/common/normalization.ts +++ b/src/vs/base/common/normalization.ts @@ -5,14 +5,6 @@ import { LRUCache } from 'vs/base/common/map'; -/** - * The normalize() method returns the Unicode Normalization Form of a given string. The form will be - * the Normalization Form Canonical Composition. - * - * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize} - */ -export const canNormalize = typeof (String.prototype as any /* standalone editor compilation */).normalize === 'function'; - const nfcCache = new LRUCache(10000); // bounded to 10000 elements export function normalizeNFC(str: string): string { return normalize(str, 'NFC', nfcCache); @@ -25,7 +17,7 @@ export function normalizeNFD(str: string): string { const nonAsciiCharactersPattern = /[^\u0000-\u0080]/; function normalize(str: string, form: string, normalizedCache: LRUCache): string { - if (!canNormalize || !str) { + if (!str) { return str; } @@ -36,7 +28,7 @@ function normalize(str: string, form: string, normalizedCache: LRUCachestr).normalize(form); + res = str.normalize(form); } else { res = str; } @@ -48,15 +40,10 @@ function normalize(str: string, form: string, normalizedCache: LRUCache string = (function () { - if (!canNormalize) { - // no ES6 features... - return function (str: string) { return str; }; - } else { - // transform into NFD form and remove accents - // see: https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript/37511463#37511463 - const regex = /[\u0300-\u036f]/g; - return function (str: string) { - return normalizeNFD(str).replace(regex, ''); - }; - } + // transform into NFD form and remove accents + // see: https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript/37511463#37511463 + const regex = /[\u0300-\u036f]/g; + return function (str: string) { + return normalizeNFD(str).replace(regex, ''); + }; })(); diff --git a/src/vs/base/test/node/pfs/pfs.test.ts b/src/vs/base/test/node/pfs/pfs.test.ts index 345e11ed991..fe1f05e6954 100644 --- a/src/vs/base/test/node/pfs/pfs.test.ts +++ b/src/vs/base/test/node/pfs/pfs.test.ts @@ -10,7 +10,6 @@ import { join, sep } from 'vs/base/common/path'; import { generateUuid } from 'vs/base/common/uuid'; import { Promises, RimRafMode, rimrafSync, SymlinkSupport, writeFileSync } from 'vs/base/node/pfs'; import { timeout } from 'vs/base/common/async'; -import { canNormalize } from 'vs/base/common/normalization'; import { VSBuffer } from 'vs/base/common/buffer'; import { flakySuite, getRandomTestPath, getPathFromAmdModule } from 'vs/base/test/node/testUtils'; import { isWindows } from 'vs/base/common/platform'; @@ -346,7 +345,7 @@ flakySuite('PFS', function () { }); test('readdir', async () => { - if (canNormalize && typeof process.versions['electron'] !== 'undefined' /* needs electron */) { + if (typeof process.versions['electron'] !== 'undefined' /* needs electron */) { const id = generateUuid(); const newDir = join(testDir, 'pfs', id, 'öäü'); @@ -360,7 +359,7 @@ flakySuite('PFS', function () { }); test('readdir (with file types)', async () => { - if (canNormalize && typeof process.versions['electron'] !== 'undefined' /* needs electron */) { + if (typeof process.versions['electron'] !== 'undefined' /* needs electron */) { const newDir = join(testDir, 'öäü'); await Promises.mkdir(newDir, { recursive: true });