提交 7bbd1338 编写于 作者: C Christof Marti

Remove strings.startsWith() (#103454)

上级 ad5cb8ea
...@@ -144,27 +144,6 @@ export function stripWildcards(pattern: string): string { ...@@ -144,27 +144,6 @@ export function stripWildcards(pattern: string): string {
return pattern.replace(/\*/g, ''); return pattern.replace(/\*/g, '');
} }
/**
* @deprecated ES6: use `String.startsWith`
*/
export function startsWith(haystack: string, needle: string): boolean {
if (haystack.length < needle.length) {
return false;
}
if (haystack === needle) {
return true;
}
for (let i = 0; i < needle.length; i++) {
if (haystack[i] !== needle[i]) {
return false;
}
}
return true;
}
/** /**
* @deprecated ES6: use `String.endsWith` * @deprecated ES6: use `String.endsWith`
*/ */
......
...@@ -7,7 +7,6 @@ import { dirname, basename, distinctParents, joinPath, normalizePath, isAbsolute ...@@ -7,7 +7,6 @@ import { dirname, basename, distinctParents, joinPath, normalizePath, isAbsolute
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { isWindows } from 'vs/base/common/platform'; import { isWindows } from 'vs/base/common/platform';
import { toSlashes } from 'vs/base/common/extpath'; import { toSlashes } from 'vs/base/common/extpath';
import { startsWith } from 'vs/base/common/strings';
import { win32, posix } from 'vs/base/common/path'; import { win32, posix } from 'vs/base/common/path';
...@@ -304,7 +303,7 @@ suite('Resources', () => { ...@@ -304,7 +303,7 @@ suite('Resources', () => {
const p = path.indexOf('/') !== -1 ? posix : win32; const p = path.indexOf('/') !== -1 ? posix : win32;
if (!p.isAbsolute(path)) { if (!p.isAbsolute(path)) {
let expectedPath = isWindows ? toSlashes(path) : path; let expectedPath = isWindows ? toSlashes(path) : path;
expectedPath = startsWith(expectedPath, './') ? expectedPath.substr(2) : expectedPath; expectedPath = expectedPath.startsWith('./') ? expectedPath.substr(2) : expectedPath;
assert.equal(relativePath(u1, actual), expectedPath, `relativePath (${u1.toString()}) on actual (${actual.toString()}) should be to path (${expectedPath})`); assert.equal(relativePath(u1, actual), expectedPath, `relativePath (${u1.toString()}) on actual (${actual.toString()}) should be to path (${expectedPath})`);
} }
} }
......
...@@ -140,16 +140,6 @@ suite('Strings', () => { ...@@ -140,16 +140,6 @@ suite('Strings', () => {
assert.strictEqual(strings.escape('<foo>Hello</foo>'), '&lt;foo&gt;Hello&lt;/foo&gt;'); assert.strictEqual(strings.escape('<foo>Hello</foo>'), '&lt;foo&gt;Hello&lt;/foo&gt;');
}); });
test('startsWith', () => {
assert(strings.startsWith('foo', 'f'));
assert(strings.startsWith('foo', 'fo'));
assert(strings.startsWith('foo', 'foo'));
assert(!strings.startsWith('foo', 'o'));
assert(!strings.startsWith('', 'f'));
assert(strings.startsWith('foo', ''));
assert(strings.startsWith('', ''));
});
test('endsWith', () => { test('endsWith', () => {
assert(strings.endsWith('foo', 'o')); assert(strings.endsWith('foo', 'o'));
assert(strings.endsWith('foo', 'oo')); assert(strings.endsWith('foo', 'oo'));
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { startsWith } from 'vs/base/common/strings';
import { CodeAction, CodeActionTriggerType } from 'vs/editor/common/modes'; import { CodeAction, CodeActionTriggerType } from 'vs/editor/common/modes';
import { Position } from 'vs/editor/common/core/position'; import { Position } from 'vs/editor/common/core/position';
...@@ -27,7 +26,7 @@ export class CodeActionKind { ...@@ -27,7 +26,7 @@ export class CodeActionKind {
} }
public contains(other: CodeActionKind): boolean { public contains(other: CodeActionKind): boolean {
return this.equals(other) || this.value === '' || startsWith(other.value, this.value + CodeActionKind.sep); return this.equals(other) || this.value === '' || other.value.startsWith(this.value + CodeActionKind.sep);
} }
public intersects(other: CodeActionKind): boolean { public intersects(other: CodeActionKind): boolean {
......
...@@ -9,7 +9,6 @@ import { illegalArgument } from 'vs/base/common/errors'; ...@@ -9,7 +9,6 @@ import { illegalArgument } from 'vs/base/common/errors';
import { IRelativePattern } from 'vs/base/common/glob'; import { IRelativePattern } from 'vs/base/common/glob';
import { isMarkdownString } from 'vs/base/common/htmlContent'; import { isMarkdownString } from 'vs/base/common/htmlContent';
import { ResourceMap } from 'vs/base/common/map'; import { ResourceMap } from 'vs/base/common/map';
import { startsWith } from 'vs/base/common/strings';
import { isStringArray } from 'vs/base/common/types'; import { isStringArray } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { generateUuid } from 'vs/base/common/uuid'; import { generateUuid } from 'vs/base/common/uuid';
...@@ -1171,7 +1170,7 @@ export class CodeActionKind { ...@@ -1171,7 +1170,7 @@ export class CodeActionKind {
} }
public contains(other: CodeActionKind): boolean { public contains(other: CodeActionKind): boolean {
return this.value === other.value || startsWith(other.value, this.value + CodeActionKind.sep); return this.value === other.value || other.value.startsWith(this.value + CodeActionKind.sep);
} }
} }
CodeActionKind.Empty = new CodeActionKind(''); CodeActionKind.Empty = new CodeActionKind('');
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry'; import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry';
import * as strings from 'vs/base/common/strings';
import * as resources from 'vs/base/common/resources'; import * as resources from 'vs/base/common/resources';
import { isString } from 'vs/base/common/types'; import { isString } from 'vs/base/common/types';
...@@ -64,7 +63,7 @@ export class JSONValidationExtensionPoint { ...@@ -64,7 +63,7 @@ export class JSONValidationExtensionPoint {
collector.error(nls.localize('invalid.url', "'configuration.jsonValidation.url' must be a URL or relative path")); collector.error(nls.localize('invalid.url', "'configuration.jsonValidation.url' must be a URL or relative path"));
return; return;
} }
if (strings.startsWith(uri, './')) { if (uri.startsWith('./')) {
try { try {
const colorThemeLocation = resources.joinPath(extensionLocation, uri); const colorThemeLocation = resources.joinPath(extensionLocation, uri);
if (!resources.isEqualOrParent(colorThemeLocation, extensionLocation)) { if (!resources.isEqualOrParent(colorThemeLocation, extensionLocation)) {
......
...@@ -379,7 +379,7 @@ export class ProcessRunnerDetector { ...@@ -379,7 +379,7 @@ export class ProcessRunnerDetector {
if (taskName === test) { if (taskName === test) {
taskInfo.index = index; taskInfo.index = index;
taskInfo.exact = 3; taskInfo.exact = 3;
} else if ((Strings.startsWith(taskName, test) || Strings.endsWith(taskName, test)) && taskInfo.exact < 3) { } else if ((taskName.startsWith(test) || taskName.endsWith(test)) && taskInfo.exact < 3) {
taskInfo.index = index; taskInfo.index = index;
taskInfo.exact = 2; taskInfo.exact = 2;
} else if (taskName.indexOf(test) !== -1 && taskInfo.exact < 2) { } else if (taskName.indexOf(test) !== -1 && taskInfo.exact < 2) {
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
import 'vs/css!./welcomePage'; import 'vs/css!./welcomePage';
import 'vs/workbench/contrib/welcome/page/browser/vs_code_welcome_page'; import 'vs/workbench/contrib/welcome/page/browser/vs_code_welcome_page';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import * as strings from 'vs/base/common/strings';
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands'; import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
import * as arrays from 'vs/base/common/arrays'; import * as arrays from 'vs/base/common/arrays';
import { WalkThroughInput } from 'vs/workbench/contrib/welcome/walkThrough/browser/walkThroughInput'; import { WalkThroughInput } from 'vs/workbench/contrib/welcome/walkThrough/browser/walkThroughInput';
...@@ -78,7 +77,7 @@ export class WelcomePageContribution implements IWorkbenchContribution { ...@@ -78,7 +77,7 @@ export class WelcomePageContribution implements IWorkbenchContribution {
.then(folder => { .then(folder => {
const files = folder.children ? folder.children.map(child => child.name) : []; const files = folder.children ? folder.children.map(child => child.name) : [];
const file = files.sort().find(file => strings.startsWith(file.toLowerCase(), 'readme')); const file = files.sort().find(file => file.toLowerCase().startsWith('readme'));
if (file) { if (file) {
return joinPath(folderUri, file); return joinPath(folderUri, file);
} }
...@@ -88,7 +87,7 @@ export class WelcomePageContribution implements IWorkbenchContribution { ...@@ -88,7 +87,7 @@ export class WelcomePageContribution implements IWorkbenchContribution {
.then<any>(readmes => { .then<any>(readmes => {
if (!editorService.activeEditor) { if (!editorService.activeEditor) {
if (readmes.length) { if (readmes.length) {
const isMarkDown = (readme: URI) => strings.endsWith(readme.path.toLowerCase(), '.md'); const isMarkDown = (readme: URI) => readme.path.toLowerCase().endsWith('.md');
return Promise.all([ return Promise.all([
this.commandService.executeCommand('markdown.showPreview', null, readmes.filter(isMarkDown), { locked: true }), this.commandService.executeCommand('markdown.showPreview', null, readmes.filter(isMarkDown), { locked: true }),
editorService.openEditors(readmes.filter(readme => !isMarkDown(readme)) editorService.openEditors(readmes.filter(readme => !isMarkDown(readme))
......
...@@ -19,7 +19,6 @@ import { Registry } from 'vs/platform/registry/common/platform'; ...@@ -19,7 +19,6 @@ import { Registry } from 'vs/platform/registry/common/platform';
import { getParseErrorMessage } from 'vs/base/common/jsonErrorMessages'; import { getParseErrorMessage } from 'vs/base/common/jsonErrorMessages';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { parse as parsePList } from 'vs/workbench/services/themes/common/plistParser'; import { parse as parsePList } from 'vs/workbench/services/themes/common/plistParser';
import { startsWith } from 'vs/base/common/strings';
import { TokenStyle, SemanticTokenRule, ProbeScope, getTokenClassificationRegistry, TokenStyleValue, TokenStyleData, parseClassifierString } from 'vs/platform/theme/common/tokenClassificationRegistry'; import { TokenStyle, SemanticTokenRule, ProbeScope, getTokenClassificationRegistry, TokenStyleValue, TokenStyleData, parseClassifierString } from 'vs/platform/theme/common/tokenClassificationRegistry';
import { MatcherWithPriority, Matcher, createMatchers } from 'vs/workbench/services/themes/common/textMateScopeMatcher'; import { MatcherWithPriority, Matcher, createMatchers } from 'vs/workbench/services/themes/common/textMateScopeMatcher';
import { IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader'; import { IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader';
...@@ -641,7 +640,7 @@ export class ColorThemeData implements IWorkbenchColorTheme { ...@@ -641,7 +640,7 @@ export class ColorThemeData implements IWorkbenchColorTheme {
} }
function toCSSSelector(extensionId: string, path: string) { function toCSSSelector(extensionId: string, path: string) {
if (startsWith(path, './')) { if (path.startsWith('./')) {
path = path.substr(2); path = path.substr(2);
} }
let str = `${extensionId}-${path}`; let str = `${extensionId}-${path}`;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册