remove canNormalize because String#normalize is now everywhere
This commit is contained in:
parent
0b57137a4b
commit
aa985bb2db
2 changed files with 10 additions and 24 deletions
|
@ -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<string, string>(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, string>): string {
|
||||
if (!canNormalize || !str) {
|
||||
if (!str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -36,7 +28,7 @@ function normalize(str: string, form: string, normalizedCache: LRUCache<string,
|
|||
|
||||
let res: string;
|
||||
if (nonAsciiCharactersPattern.test(str)) {
|
||||
res = (<any>str).normalize(form);
|
||||
res = str.normalize(form);
|
||||
} else {
|
||||
res = str;
|
||||
}
|
||||
|
@ -48,15 +40,10 @@ function normalize(str: string, form: string, normalizedCache: LRUCache<string,
|
|||
}
|
||||
|
||||
export const removeAccents: (str: string) => 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, '');
|
||||
};
|
||||
})();
|
||||
|
|
|
@ -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 });
|
||||
|
||||
|
|
Loading…
Reference in a new issue