Replace substr with substring. (#9129)

* Replace substr with substring.
This commit is contained in:
Sean McManus 2022-04-04 19:42:19 -07:00 коммит произвёл GitHub
Родитель dda36530cd
Коммит 504800336c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 49 добавлений и 44 удалений

Просмотреть файл

@ -94,11 +94,11 @@ function removePathPrefix(path, prefix) {
}
let ch = prefix.charAt(prefix.length - 1);
if (ch === '/' || ch === '\\') {
return path.substr(prefix.length);
return path.substring(prefix.length);
}
ch = path.charAt(prefix.length);
if (ch === '/' || ch === '\\') {
return path.substr(prefix.length + 1);
return path.substring(prefix.length + 1);
}
return path;
}
@ -378,7 +378,7 @@ const generateLocalizedWalkthroughHtmlFiles = () => {
return es.through(function (file) {
let relativePath = removePathPrefix(file.path, file.cwd);
languages.map((language) => {
let newPath = relativePath.substr(0, relativePath.lastIndexOf(".")) + `.nls.${language.id}.md`;
let newPath = relativePath.substring(0, relativePath.lastIndexOf(".")) + `.nls.${language.id}.md`;
let newContent = generateLocalizedHtmlFilesImpl(file, relativePath, language, true);
this.queue(new vinyl({
path: newPath,
@ -386,7 +386,7 @@ const generateLocalizedWalkthroughHtmlFiles = () => {
}));
});
// Put the original in an 'en' file.
let newPath = relativePath.substr(0, relativePath.lastIndexOf(".")) + ".nls.en.md";
let newPath = relativePath.substring(0, relativePath.lastIndexOf(".")) + ".nls.en.md";
this.queue(new vinyl({
path: newPath,
contents: file.contents

Просмотреть файл

@ -32,7 +32,7 @@ export class ParsedEnvironmentFile {
// Remove UTF-8 BOM if present
if (content.charAt(0) === '\uFEFF') {
content = content.substr(1);
content = content.substring(1);
}
const parseErrors: string[] = [];

Просмотреть файл

@ -341,7 +341,7 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
if ((compilerName !== "clang-cl.exe") && (compilerName !== "clang-cpp.exe")) {
const suffixIndex: number = compilerName.indexOf("-");
if (suffixIndex !== -1) {
const suffix: string = compilerName.substr(suffixIndex);
const suffix: string = compilerName.substring(suffixIndex);
debuggerName += suffix;
}
}

Просмотреть файл

@ -39,8 +39,8 @@ export class DocumentSymbolProvider implements vscode.DocumentSymbolProvider {
}
const offset_scope: number = symbol.name.lastIndexOf("::", offset_paren - 2);
if (offset_scope > 0) {
detail = symbol.name.substr(0, offset_scope);
symbol.name = symbol.name.substr(offset_scope + 2);
detail = symbol.name.substring(0, offset_scope);
symbol.name = symbol.name.substring(offset_scope + 2);
}
}

Просмотреть файл

@ -1922,7 +1922,7 @@ export class DefaultClient implements Client {
if (tuSearchStart >= 0) {
const tuSearchEnd: number = response.diagnostics.indexOf("Translation Unit Configurations:");
if (tuSearchEnd >= 0 && tuSearchEnd > tuSearchStart) {
let tuSearchString: string = response.diagnostics.substr(tuSearchStart, tuSearchEnd - tuSearchStart);
let tuSearchString: string = response.diagnostics.substring(tuSearchStart, tuSearchEnd);
let tuSearchIndex: number = tuSearchString.indexOf("[");
while (tuSearchIndex >= 0) {
const tuMatch: RegExpMatchArray | null = tuSearchString.match(/\[\s(.*)\s\]/);
@ -1935,7 +1935,7 @@ export class DefaultClient implements Client {
configurationLoggingStr += `[ ${tuMatch[1]} ]\n${this.configurationLogging.get(tuPath)}\n`;
}
}
tuSearchString = tuSearchString.substr(tuSearchIndex + 1);
tuSearchString = tuSearchString.substring(tuSearchIndex + 1);
tuSearchIndex = tuSearchString.indexOf("[");
}
}
@ -2271,7 +2271,7 @@ export class DefaultClient implements Client {
if (cppSettings.autoAddFileAssociations) {
const is_c: boolean = languageStr.startsWith("c;");
const is_cuda: boolean = languageStr.startsWith("cu;");
languageStr = languageStr.substr(is_c ? 2 : (is_cuda ? 3 : 1));
languageStr = languageStr.substring(is_c ? 2 : (is_cuda ? 3 : 1));
this.addFileAssociations(languageStr, is_c ? "c" : (is_cuda ? "cuda-cpp" : "cpp"));
}
}
@ -2323,7 +2323,7 @@ export class DefaultClient implements Client {
for (const assoc in assocs) {
const dotIndex: number = assoc.lastIndexOf('.');
if (dotIndex !== -1) {
const ext: string = assoc.substr(dotIndex + 1);
const ext: string = assoc.substring(dotIndex + 1);
this.associations_for_did_change.add(ext);
}
}
@ -2339,7 +2339,7 @@ export class DefaultClient implements Client {
await this.updateActiveDocumentTextOptions();
}
if (dotIndex !== -1) {
const ext: string = uri.fsPath.substr(dotIndex + 1);
const ext: string = uri.fsPath.substring(dotIndex + 1);
if (this.associations_for_did_change?.has(ext)) {
// VS Code has a bug that causes onDidChange events to happen to files that aren't changed,
// which causes a large backlog of "files to parse" to accumulate.
@ -2395,7 +2395,7 @@ export class DefaultClient implements Client {
}
const j: number = file.lastIndexOf('.');
if (j !== -1) {
const ext: string = file.substr(j);
const ext: string = file.substring(j);
if ((("*" + ext) in assocs) || (("**/*" + ext) in assocs)) {
continue; // Extension already has an association.
}

Просмотреть файл

@ -1378,11 +1378,11 @@ export class CppProperties {
// resolve WSL paths
if (isWindows && result.startsWith("/")) {
const mntStr: string = "/mnt/";
if (result.length > "/mnt/c/".length && result.substr(0, mntStr.length) === mntStr) {
result = result.substr(mntStr.length);
result = result.substr(0, 1) + ":" + result.substr(1);
if (result.length > "/mnt/c/".length && result.substring(0, mntStr.length) === mntStr) {
result = result.substring(mntStr.length);
result = result.substring(0, 1) + ":" + result.substring(1);
} else if (this.rootfs && this.rootfs.length > 0) {
result = this.rootfs + result.substr(1);
result = this.rootfs + result.substring(1);
// TODO: Handle WSL symlinks.
}
}
@ -1600,8 +1600,12 @@ export class CppProperties {
// Get env text
let envText: string = "";
const envStart: number = curText.search(/\"env\"\s*:\s*\{/);
const envEnd: number = envStart === -1 ? -1 : curText.indexOf("},", envStart);
envText = curText.substr(envStart, envEnd);
if (envStart >= 0) {
const envEnd: number = curText.indexOf("},", envStart);
if (envEnd >= 0) {
envText = curText.substring(envStart, envEnd);
}
}
const envTextStartOffSet: number = envStart + 1;
// Check if all config names are unique.
@ -1615,11 +1619,11 @@ export class CppProperties {
const configNames: Map<string, vscode.Range[]> = new Map<string, []>();
let dupErrorMsg: string;
while (configStart !== -1) {
allConfigText = allConfigText.substr(configStart);
allConfigText = allConfigText.substring(configStart);
allConfigTextOffset += configStart;
configNameStart = allConfigText.indexOf('"', allConfigText.indexOf(':') + 1) + 1;
configNameEnd = allConfigText.indexOf('"', configNameStart);
configName = allConfigText.substr(configNameStart, configNameEnd - configNameStart);
configName = allConfigText.substring(configNameStart, configNameEnd);
const newRange: vscode.Range = new vscode.Range(0, allConfigTextOffset + configNameStart, 0, allConfigTextOffset + configNameEnd);
const allRanges: vscode.Range[] | undefined = configNames.get(configName);
if (allRanges) {
@ -1628,7 +1632,7 @@ export class CppProperties {
} else {
configNames.set(configName, [newRange]);
}
allConfigText = allConfigText.substr(configNameEnd + 1);
allConfigText = allConfigText.substring(configNameEnd + 1);
allConfigTextOffset += configNameEnd + 1;
configStart = allConfigText.search(new RegExp(nameRegex));
}
@ -1652,19 +1656,19 @@ export class CppProperties {
return;
}
curTextStartOffset = configStart + 1;
curText = curText.substr(curTextStartOffset); // Remove earlier configs.
curText = curText.substring(curTextStartOffset); // Remove earlier configs.
const nameEnd: number = curText.indexOf(":");
curTextStartOffset += nameEnd + 1;
curText = curText.substr(nameEnd + 1);
curText = curText.substring(nameEnd + 1);
const nextNameStart: number = curText.search(new RegExp('"name"\\s*:\\s*"'));
if (nextNameStart !== -1) {
curText = curText.substr(0, nextNameStart + 6); // Remove later configs.
curText = curText.substring(0, nextNameStart + 6); // Remove later configs.
const nextNameStart2: number = curText.search(new RegExp('\\s*}\\s*,\\s*{\\s*"name"'));
if (nextNameStart2 === -1) {
telemetry.logLanguageServerEvent("ConfigSquiggles", { "error": "next config name not first" });
return;
}
curText = curText.substr(0, nextNameStart2);
curText = curText.substring(0, nextNameStart2);
}
if (this.prevSquiggleMetrics.get(currentConfiguration.name) === undefined) {
this.prevSquiggleMetrics.set(currentConfiguration.name, { PathNonExistent: 0, PathNotAFile: 0, PathNotADirectory: 0, CompilerPathMissingQuotes: 0, CompilerModeMismatch: 0 });
@ -1864,7 +1868,7 @@ export class CppProperties {
let curOffset: number = 0;
let endOffset: number = 0;
for (const curMatch of configMatches) {
curOffset = curText.substr(endOffset).search(pattern) + endOffset;
curOffset = curText.substring(endOffset).search(pattern) + endOffset;
endOffset = curOffset + curMatch.length;
if (curOffset >= compilerPathStart && curOffset <= compilerPathEnd) {
continue;
@ -1901,12 +1905,13 @@ export class CppProperties {
diagnostics.push(diagnostic);
}
} else if (envText) {
// TODO: This never matches. https://github.com/microsoft/vscode-cpptools/issues/9140
const envMatches: string[] | null = envText.match(pattern);
if (envMatches) {
let curOffset: number = 0;
let endOffset: number = 0;
for (const curMatch of envMatches) {
curOffset = envText.substr(endOffset).search(pattern) + endOffset;
curOffset = envText.substring(endOffset).search(pattern) + endOffset;
endOffset = curOffset + curMatch.length;
let message: string;
if (!pathExists) {

Просмотреть файл

@ -577,7 +577,7 @@ async function onSwitchHeaderSource(): Promise<void> {
clients.forEach(client => {
if (!targetFileNameReplaced && client.RootRealPath && client.RootPath !== client.RootRealPath
&& targetFileName.indexOf(client.RootRealPath) === 0) {
targetFileName = client.RootPath + targetFileName.substr(client.RootRealPath.length);
targetFileName = client.RootPath + targetFileName.substring(client.RootRealPath.length);
targetFileNameReplaced = true;
}
});
@ -966,7 +966,7 @@ function handleMacCrashFileRead(err: NodeJS.ErrnoException | undefined | null, d
let binaryVersion: string = "";
const startVersion: number = data.indexOf("Version:");
if (startVersion >= 0) {
data = data.substr(startVersion);
data = data.substring(startVersion);
const binaryVersionMatches: string[] | null = data.match(/^Version:\s*(\d*\.\d*\.\d*\.\d*|\d)/);
binaryVersion = binaryVersionMatches && binaryVersionMatches.length > 1 ? binaryVersionMatches[1] : "";
}
@ -985,7 +985,7 @@ function handleMacCrashFileRead(err: NodeJS.ErrnoException | undefined | null, d
if (endCrash <= startCrash) {
return logMacCrashTelemetry("No crash end");
}
data = data.substr(startCrash, endCrash - startCrash);
data = data.substring(startCrash, endCrash);
// Get rid of the memory addresses (which breaks being able get a hit count for each crash call stack).
data = data.replace(/0x................ /g, "");
@ -1018,7 +1018,7 @@ function handleMacCrashFileRead(err: NodeJS.ErrnoException | undefined | null, d
data = data.trimRight();
if (data.length > 8192) { // The API has an 8k limit.
data = data.substr(0, 8189) + "...";
data = data.substring(0, 8189) + "...";
}
logMacCrashTelemetry(data);

Просмотреть файл

@ -43,7 +43,7 @@ function escape(chars: string): string {
function getMLBeginPattern(insert: string): string | undefined {
if (insert.startsWith("/*")) {
const match: string = escape(insert.substr(2)); // trim the leading '/*' and escape any troublesome characters.
const match: string = escape(insert.substring(2)); // trim the leading '/*' and escape any troublesome characters.
return `^\\s*\\/\\*${match}(?!\\/)([^\\*]|\\*(?!\\/))*$`;
}
return undefined;
@ -64,7 +64,7 @@ function getMLContinuePattern(insert: string): string | undefined {
if (insert) {
const match: string = escape(insert.trimRight());
if (match) {
const right: string = escape(insert.substr(insert.trimRight().length));
const right: string = escape(insert.substring(insert.trimRight().length));
return `^(\\t|[ ])*${match}(${right}([^\\*]|\\*(?!\\/))*)?$`;
}
// else: if the continuation is just whitespace, vscode already does indentation preservation.
@ -76,7 +76,7 @@ function getMLEmptyEndPattern(insert: string): string | undefined {
insert = insert.trimRight();
if (insert !== "") {
if (insert.endsWith('*')) {
insert = insert.substr(0, insert.length - 1);
insert = insert.substring(0, insert.length - 1);
}
const match: string = escape(insert.trimRight());
return `^(\\t|[ ])*${match}\\*\\/\\s*$`;

Просмотреть файл

@ -193,7 +193,7 @@ export class SettingsTracker {
}
}
if (value && value.length > maxSettingLengthForTelemetry) {
value = value.substr(0, maxSettingLengthForTelemetry) + "...";
value = value.substring(0, maxSettingLengthForTelemetry) + "...";
}
return {key: key, value: value};
}

Просмотреть файл

@ -919,10 +919,10 @@ export function extractCompilerPathAndArgs(inputCompilerPath?: string, inputComp
compilerName = path.basename(compilerPath);
} else if (compilerPath.startsWith("\"")) {
// Input has quotes around compiler path
const endQuote: number = compilerPath.substr(1).search("\"") + 1;
const endQuote: number = compilerPath.substring(1).search("\"") + 1;
if (endQuote !== -1) {
additionalArgs = extractArgs(compilerPath.substr(endQuote + 1));
compilerPath = compilerPath.substr(1, endQuote - 1);
additionalArgs = extractArgs(compilerPath.substring(endQuote + 1));
compilerPath = compilerPath.substring(1, endQuote);
compilerName = path.basename(compilerPath);
}
} else {
@ -934,7 +934,7 @@ export function extractCompilerPathAndArgs(inputCompilerPath?: string, inputComp
} else if (spaceStart !== -1 && !checkFileExistsSync(compilerPath)) {
// Get compiler name if compiler path has spaces and args.
// Go from right to left checking if a valid path is to the left of a space.
let potentialCompilerPath: string = compilerPath.substr(0, spaceStart);
let potentialCompilerPath: string = compilerPath.substring(0, spaceStart);
while (!checkFileExistsSync(potentialCompilerPath)) {
spaceStart = potentialCompilerPath.lastIndexOf(" ");
if (spaceStart === -1) {
@ -942,11 +942,11 @@ export function extractCompilerPathAndArgs(inputCompilerPath?: string, inputComp
potentialCompilerPath = compilerPath;
break;
}
potentialCompilerPath = potentialCompilerPath.substr(0, spaceStart);
potentialCompilerPath = potentialCompilerPath.substring(0, spaceStart);
}
if (compilerPath !== potentialCompilerPath) {
// Found a valid compilerPath and args.
additionalArgs = extractArgs(compilerPath.substr(spaceStart + 1));
additionalArgs = extractArgs(compilerPath.substring(spaceStart + 1));
compilerPath = potentialCompilerPath;
compilerName = path.basename(potentialCompilerPath);
}

Просмотреть файл

@ -33,7 +33,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CppToo
class SchemaProvider implements vscode.TextDocumentContentProvider {
public async provideTextDocumentContent(uri: vscode.Uri): Promise<string> {
console.assert(uri.path[0] === '/', "A preceeding slash is expected on schema uri path");
const fileName: string = uri.path.substr(1);
const fileName: string = uri.path.substring(1);
const locale: string = util.getLocaleId();
let localizedFilePath: string = util.getExtensionFilePath(path.join("dist/schema/", locale, fileName));
const fileExists: boolean = await util.checkFileExists(localizedFilePath);