Skip to content

Commit

Permalink
replace deprecated substr methods (#12551)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladarama authored May 25, 2023
1 parent 887e4a2 commit 52f53af
Show file tree
Hide file tree
Showing 39 changed files with 66 additions and 67 deletions.
2 changes: 1 addition & 1 deletion dev-packages/application-package/src/npm-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class NpmRegistry {
protected async doView(name: string): Promise<ViewResult> {
let url = this.props.registry;
if (name[0] === '@') {
url += '@' + encodeURIComponent(name.substr(1));
url += '@' + encodeURIComponent(name.substring(1));
} else {
url += encodeURIComponent(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ export class BulkEditTreeWidget extends TreeWidget {
const startColumn = +bulkEdit.textEdit.range.startColumn;
const endColumn = +bulkEdit.textEdit.range.endColumn;
const lineText = lines[startLineNum - 1];
const beforeMatch = (startColumn > 26 ? '... ' : '') + lineText.substr(0, startColumn - 1).substr(-25);
const beforeMatch = (startColumn > 26 ? '... ' : '') + lineText.substring(0, startColumn - 1).slice(-25);
const replacedText = lineText.substring(startColumn - 1, endColumn - 1);
const afterMatch = lineText.substr(startColumn - 1 + replacedText.length, 75);
const afterMatch = lineText.substring(startColumn - 1 + replacedText.length, startColumn - 1 + replacedText.length + 75);

return <div className='bulkEditNode'>
<div className='message'>
Expand Down Expand Up @@ -193,9 +193,9 @@ export class BulkEditTreeWidget extends TreeWidget {
const startColumn = node.bulkEdit.textEdit.range.startColumn;
const endColumn = node.bulkEdit.textEdit.range.endColumn;
const lineText = lines[startLineNum - 1];
const beforeMatch = lineText.substr(0, startColumn - 1);
const beforeMatch = lineText.substring(0, startColumn - 1);
const replacedText = lineText.substring(startColumn - 1, endColumn - 1);
const afterMatch = lineText.substr(startColumn - 1 + replacedText.length);
const afterMatch = lineText.substring(startColumn - 1 + replacedText.length);
lines[startLineNum - 1] = beforeMatch + node.bulkEdit.textEdit.text + afterMatch;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/browser/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Endpoint {
return '';
}
if (this.location.pathname.endsWith('/')) {
return this.location.pathname.substr(0, this.location.pathname.length - 1);
return this.location.pathname.substring(0, this.location.pathname.length - 1);
}
return this.location.pathname;
}
Expand Down Expand Up @@ -75,10 +75,10 @@ export class Endpoint {
if (!search) {
return defaultValue;
}
return search.substr(1).split('&')
return search.substring(1).split('&')
.filter(value => value.startsWith(name + '='))
.map(value => {
const encoded = value.substr(name.length + 1);
const encoded = value.substring(name.length + 1);
return decodeURIComponent(encoded);
})[0] || defaultValue;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/keybinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ export class KeybindingRegistry {
const { command, context, when, keybinding } = binding;
if (!this.isUsable(binding)) {
disabled = disabled || new Set<string>();
disabled.add(JSON.stringify({ command: command.substr(1), context, when, keybinding }));
disabled.add(JSON.stringify({ command: command.substring(1), context, when, keybinding }));
return false;
}
return !disabled?.has(JSON.stringify({ command, context, when, keybinding }));
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/label-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class DefaultUriLabelProviderContribution implements LabelProviderContrib

// convert \c:\something => C:\something
if (formatting.normalizeDriveLetter && this.hasDriveLetter(label)) {
label = label.charAt(1).toUpperCase() + label.substr(2);
label = label.charAt(1).toUpperCase() + label.substring(2);
}

if (formatting.tildify) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/browser/preferences/preference-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ export function createPreferenceProxy<T>(preferences: PreferenceService, promise
if (p.startsWith(prefix)) {
const idx = p.indexOf('.', prefix.length);
if (idx !== -1 && isDeep) {
const pre = p.substr(prefix.length, idx - prefix.length);
const pre = p.substring(prefix.length, idx);
if (properties.indexOf(pre) === -1) {
properties.push(pre);
}
}
const prop = p.substr(prefix.length);
const prop = p.substring(prefix.length);
if (isFlat || prop.indexOf('.') === -1) {
properties.push(prop);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/tree/search-box-debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class SearchBoxDebounce implements Disposable {
this.state = input;
} else {
if (input === '\b') {
this.state = this.state.length === 1 ? '' : this.state.substr(0, this.state.length - 1);
this.state = this.state.length === 1 ? '' : this.state.substring(0, this.state.length - 1);
} else {
this.state += input;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/widget-decoration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export namespace WidgetDecoration {
result.push({ data });
}
const { length } = ranges.splice(containerIndex, 1).shift()!;
result.push({ data: caption.substr(i, length), highlight: true });
result.push({ data: caption.substring(i, i + length), highlight: true });
data = '';
i = i + length - 1;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/common/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function parsePattern(arg1: string | IRelativePattern, options: IGlobOptions): P
// Check for Trivias
let match: RegExpExecArray;
if (T1.test(pattern)) { // common pattern: **/*.txt just need endsWith check
const base = pattern.substr(4); // '**/*'.length === 4
const base = pattern.substring(4); // '**/*'.length === 4
parsedPattern = function (path, basename): string {
return path && strings.endsWith(path, base) ? pattern : null!;
};
Expand All @@ -338,7 +338,7 @@ function parsePattern(arg1: string | IRelativePattern, options: IGlobOptions): P
} else if ((options.trimForExclusions ? T3_2 : T3).test(pattern)) { // repetition of common patterns (see above) {**/*.txt,**/*.png}
parsedPattern = trivia3(pattern, options);
} else if (match = T4.exec(trimForExclusions(pattern, options))!) { // common pattern: **/something/else just need endsWith check
parsedPattern = trivia4and5(match[1].substr(1), pattern, true);
parsedPattern = trivia4and5(match[1].substring(1), pattern, true);
} else if (match = T5.exec(trimForExclusions(pattern, options))!) { // common pattern: something/else just need equals check
parsedPattern = trivia4and5(match[1], pattern, false);
}
Expand Down Expand Up @@ -370,7 +370,7 @@ function wrapRelativePattern(parsedPattern: ParsedStringPattern, arg2: string |
}

function trimForExclusions(pattern: string, options: IGlobOptions): string {
return options.trimForExclusions && strings.endsWith(pattern, '/**') ? pattern.substr(0, pattern.length - 2) : pattern; // dropping **, tailing / is dropped later
return options.trimForExclusions && strings.endsWith(pattern, '/**') ? pattern.substring(0, pattern.length - 2) : pattern; // dropping **, tailing / is dropped later
}

// common pattern: **/some.txt just need basename check
Expand Down Expand Up @@ -632,7 +632,7 @@ function parsedExpression(expression: IExpression, options: IGlobOptions): Parse
basename = paths.basename(path);
}
if (!name) {
name = basename.substr(0, basename.length - paths.extname(path).length);
name = basename.substring(0, basename.length - paths.extname(path).length);
}
}
const result = parsedPattern(path, basename, name, hasSibling!);
Expand Down Expand Up @@ -726,7 +726,7 @@ function aggregateBasenameMatches(parsedPatterns: (ParsedStringPattern | ParsedE
break;
}
}
basename = path.substr(i);
basename = path.substring(i);
}
const index = basenames.indexOf(basename);
return index !== -1 ? patterns[index] : null!;
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/common/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ export class Path {
if (path.length >= 3 && path.charCodeAt(0) === 47 /* '/' */ && path.charCodeAt(2) === 58 /* ':' */) {
const code = path.charCodeAt(1);
if (code >= 65 /* A */ && code <= 90 /* Z */) {
path = `/${String.fromCharCode(code + 32)}:${path.substr(3)}`; // "/c:".length === 3
path = `/${String.fromCharCode(code + 32)}:${path.substring(3)}`; // "/c:".length === 3
}
} else if (path.length >= 2 && path.charCodeAt(1) === 58 /* ':' */) {
const code = path.charCodeAt(0);
if (code >= 65 /* A */ && code <= 90 /* Z */) {
path = `${String.fromCharCode(code + 32)}:${path.substr(2)}`; // "c:".length === 2
path = `${String.fromCharCode(code + 32)}:${path.substring(2)}`; // "c:".length === 2
}
if (path.charCodeAt(0) !== 47 /* '/' */) {
path = `${String.fromCharCode(47)}${path}`;
Expand Down Expand Up @@ -147,13 +147,13 @@ export class Path {
const firstIndex = this.raw.indexOf(Path.separator);
const lastIndex = this.raw.lastIndexOf(Path.separator);
this.isAbsolute = firstIndex === 0;
this.base = lastIndex === -1 ? this.raw : this.raw.substr(lastIndex + 1);
this.base = lastIndex === -1 ? this.raw : this.raw.substring(lastIndex + 1);
this.isRoot = this.isAbsolute && firstIndex === lastIndex && (!this.base || Path.isDrive(this.base));
this.root = this.computeRoot();

const extIndex = this.base.lastIndexOf('.');
this.name = extIndex === -1 ? this.base : this.base.substr(0, extIndex);
this.ext = extIndex === -1 ? '' : this.base.substr(extIndex);
this.name = extIndex === -1 ? this.base : this.base.substring(0, extIndex);
this.ext = extIndex === -1 ? '' : this.base.substring(extIndex);
}

protected computeRoot(): Path | undefined {
Expand All @@ -173,7 +173,7 @@ export class Path {
}
// '/c:/foo/bar' -> '/c:'
// '/foo/bar' -> '/'
return new Path(this.raw.substr(0, index)).root;
return new Path(this.raw.substring(0, index)).root;
}

/**
Expand Down Expand Up @@ -204,10 +204,10 @@ export class Path {
if (this.isAbsolute) {
const firstIndex = this.raw.indexOf(Path.separator);
if (firstIndex === lastIndex) {
return new Path(this.raw.substr(0, firstIndex + 1));
return new Path(this.raw.substring(0, firstIndex + 1));
}
}
return new Path(this.raw.substr(0, lastIndex));
return new Path(this.raw.substring(0, lastIndex));
}

join(...paths: string[]): Path {
Expand Down Expand Up @@ -274,7 +274,7 @@ export class Path {
if (!path.raw.startsWith(raw)) {
return undefined;
}
const relativePath = path.raw.substr(raw.length);
const relativePath = path.raw.substring(raw.length);
return new Path(relativePath);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function basename(path: string): string {
} else if (~idx === path.length - 1) {
return basename(path.substring(0, path.length - 1));
} else {
return path.substr(~idx + 1);
return path.substring(~idx + 1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class IPCConnectionProvider {
const inspectArgPrefix = `--${options.serverName}-inspect`;
const inspectArg = process.argv.find(v => v.startsWith(inspectArgPrefix));
if (inspectArg !== undefined) {
forkOptions.execArgv = ['--nolazy', `--inspect${inspectArg.substr(inspectArgPrefix.length)}`];
forkOptions.execArgv = ['--nolazy', `--inspect${inspectArg.substring(inspectArgPrefix.length)}`];
}

const childProcess = cp.fork(path.join(__dirname, 'ipc-bootstrap'), options.args, forkOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class WindowsExternalTerminalService implements ExternalTerminalService {

// Make the drive letter uppercase on Windows (https://github.com/microsoft/vscode/issues/9448).
if (cwd && cwd[1] === ':') {
cwd = cwd[0].toUpperCase() + cwd.substr(1);
cwd = cwd[0].toUpperCase() + cwd.substring(1);
}

// cmder ignores the environment cwd and instead opts to always open in %USERPROFILE%
Expand Down
2 changes: 1 addition & 1 deletion packages/file-search/src/browser/quick-file-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export class QuickFileOpenService implements QuickAccessProvider {
const startColumn = Number.isFinite(column) && column > 0 ? column - 1 : 0;
const position = Position.create(lineNumber, startColumn);

filter = expression.substr(0, patternMatch.index);
filter = expression.substring(0, patternMatch.index);
range = Range.create(position, position);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class FileSystemFrontendContribution implements FrontendApplicationContri
toClose.set(uriString, widgets);
} else if (event.contains(uri, FileChangeType.ADDED)) {
if (deleted) {
widget.title.label = widget.title.label.substr(0, label.length - this.deletedSuffix.length);
widget.title.label = widget.title.label.substring(0, label.length - this.deletedSuffix.length);
this.onDidChangeEditorFileEmitter.fire({ editor: widget, type: FileChangeType.ADDED });
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/git/src/browser/git-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ export class GitContribution implements CommandContribution, MenuContribution, T
const signOff = `\n\nSigned-off-by: ${username} <${email}>`;
const value = scmRepository.input.value;
if (value.endsWith(signOff)) {
scmRepository.input.value = value.substr(0, value.length - signOff.length);
scmRepository.input.value = value.substring(0, value.length - signOff.length);
} else {
scmRepository.input.value = `${value}${signOff}`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class GitCommitDetailHeaderWidget extends ReactWidget {
) {
super();
this.id = 'commit-header' + commitDetailOptions.commitSha;
this.title.label = commitDetailOptions.commitSha.substr(0, 8);
this.title.label = commitDetailOptions.commitSha.substring(0, 8);
this.options = {
range: {
fromRevision: commitDetailOptions.commitSha + '~1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class GitCommitDetailWidget extends BaseWidget implements StatefulWidget
) {
super();
this.id = 'commit' + options.commitSha;
this.title.label = options.commitSha.substr(0, 8);
this.title.label = options.commitSha.substring(0, 8);
this.title.closable = true;
this.title.iconClass = codicon('git-commit');

Expand Down
4 changes: 2 additions & 2 deletions packages/git/src/node/dugite-git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export namespace GitBlameParser {
} else if (firstPart === 'summary') {
let summary = parts.slice(1).join(' ');
if (summary.startsWith('"') && summary.endsWith('"')) {
summary = summary.substr(1, summary.length - 2);
summary = summary.substring(1, summary.length - 1);
}
entry.summary = uncommitted ? 'uncommitted' : summary;
} else if (firstPart === 'previous') {
Expand Down Expand Up @@ -726,7 +726,7 @@ export class DugiteGit implements Git {
if (nl > 0) {
nl = revOutput.indexOf('\n', nl + 1);
}
return revOutput.substr(Math.max(0, nl)).trim();
return revOutput.substring(Math.max(0, nl)).trim();
};
const blame = await this.blameParser.parse(uri, output, commitBodyReader);
return blame;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class FileLocationMapper implements LocationMapper {
}
let rawLocation = uri.path.toString();
if (rawLocation.charAt(0) === '/') {
rawLocation = rawLocation.substr(1);
rawLocation = rawLocation.substring(1);
}
return this.miniBrowserEnvironment.getRandomEndpoint().getRestUrl().resolve(rawLocation).toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ElectronMiniBrowserEnvironment extends MiniBrowserEnvironment {

protected override getDefaultHostname(): string {
const query = self.location.search
.substr(1) // remove leading `?`
.substring(1) // remove leading `?`
.split('&')
.map(entry => entry
.split('=', 2)
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-ext/src/common/paths-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function resolve(...paths: string[]): string {

const resolved = normalize(processed.join(sep));
if (resolved.length > 1 && resolved.charAt(resolved.length - 1) === sep) {
return resolved.substr(0, resolved.length - 1);
return resolved.substring(0, resolved.length - 1);
}

return resolved;
Expand Down Expand Up @@ -108,7 +108,7 @@ export function relative(from: string, to: string): string {
rv += downSegments.join(sep);

if (rv.length > 1 && rv.charAt(rv.length - 1) === sep) {
rv = rv.substr(0, rv.length - 1);
rv = rv.substring(0, rv.length - 1);
}
return rv;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/hosted/browser/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ export class HostedPluginSupport {
// should be aligned with https://github.com/microsoft/vscode/blob/da5fb7d5b865aa522abc7e82c10b746834b98639/src/vs/workbench/api/node/extHostExtensionService.ts#L460-L469
for (const activationEvent of activationEvents) {
if (/^workspaceContains:/.test(activationEvent)) {
const fileNameOrGlob = activationEvent.substr('workspaceContains:'.length);
const fileNameOrGlob = activationEvent.substring('workspaceContains:'.length);
if (fileNameOrGlob.indexOf(ALL_ACTIVATION_EVENT) >= 0 || fileNameOrGlob.indexOf('?') >= 0) {
includePatterns.push(fileNameOrGlob);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function loadManifest(pluginModel: PluginModel): Promise<any> {
// translate vscode builtins, as they are published with a prefix.
const built_prefix = '@theia/vscode-builtin-';
if (manifest && manifest.name && manifest.name.startsWith(built_prefix)) {
manifest.name = manifest.name.substr(built_prefix.length);
manifest.name = manifest.name.substring(built_prefix.length);
}
return manifest && translations && Object.keys(translations).length ?
localize(manifest, translations) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class HostedPluginProcess implements ServerPluginRunner {
const inspectArgPrefix = `--${options.serverName}-inspect`;
const inspectArg = process.argv.find(v => v.startsWith(inspectArgPrefix));
if (inspectArg !== undefined) {
forkOptions.execArgv = ['--nolazy', `--inspect${inspectArg.substr(inspectArgPrefix.length)}`];
forkOptions.execArgv = ['--nolazy', `--inspect${inspectArg.substring(inspectArgPrefix.length)}`];
}

const childProcess = cp.fork(this.configuration.path, options.args, forkOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function loadManifest(pluginPath: string): Promise<PluginPackage> {
// translate vscode builtins, as they are published with a prefix. See https://github.com/theia-ide/vscode-builtin-extensions/blob/master/src/republish.js#L50
const built_prefix = '@theia/vscode-builtin-';
if (manifest && manifest.name && manifest.name.startsWith(built_prefix)) {
manifest.name = manifest.name.substr(built_prefix.length);
manifest.name = manifest.name.substring(built_prefix.length);
}
manifest.publisher ??= PluginIdentifiers.UNPUBLISHED;
updateActivationEvents(manifest);
Expand Down
Loading

0 comments on commit 52f53af

Please sign in to comment.