Skip to content

Commit b5dccc4

Browse files
committed
replacing deprecated substr
fix #322
1 parent 7d9d147 commit b5dccc4

File tree

5 files changed

+62
-62
lines changed

5 files changed

+62
-62
lines changed

src/backend/gdb_expansion.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin
3737
let stringEnd = 1;
3838
let inString = true;
3939
const charStr = value[0];
40-
let remaining = value.substr(1);
40+
let remaining = value.substring(1);
4141
let escaped = false;
4242
while (inString) {
4343
if (escaped)
@@ -47,11 +47,11 @@ export function expandValue(variableCreate: Function, value: string, root: strin
4747
else if (remaining[0] == charStr)
4848
inString = false;
4949

50-
remaining = remaining.substr(1);
50+
remaining = remaining.substring(1);
5151
stringEnd++;
5252
}
53-
const str = value.substr(0, stringEnd).trim();
54-
value = value.substr(stringEnd).trim();
53+
const str = value.substring(0, stringEnd).trim();
54+
value = value.substring(stringEnd).trim();
5555
return str;
5656
};
5757

@@ -72,7 +72,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin
7272
if (namespace) {
7373
while (name.startsWith("*")) {
7474
prefix += "*";
75-
name = name.substr(1);
75+
name = name.substring(1);
7676
}
7777
namespace = namespace + pointerCombineChar + name;
7878
} else
@@ -89,15 +89,15 @@ export function expandValue(variableCreate: Function, value: string, root: strin
8989
if (value[0] != '{')
9090
return undefined;
9191
const oldContent = value;
92-
value = value.substr(1).trim();
92+
value = value.substring(1).trim();
9393
if (value[0] == '}') {
94-
value = value.substr(1).trim();
94+
value = value.substring(1).trim();
9595
return [];
9696
}
9797
if (value.startsWith("...")) {
98-
value = value.substr(3).trim();
98+
value = value.substring(3).trim();
9999
if (value[0] == '}') {
100-
value = value.substr(1).trim();
100+
value = value.substring(1).trim();
101101
return <any> "<...>";
102102
}
103103
}
@@ -124,7 +124,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin
124124
stack.pop();
125125
values.push(createValue("[" + i + "]", val));
126126
}
127-
value = value.substr(1).trim(); // }
127+
value = value.substring(1).trim(); // }
128128
return values;
129129
}
130130

@@ -134,7 +134,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin
134134
results.push(result);
135135
while (result = parseCommaResult(true))
136136
results.push(result);
137-
value = value.substr(1).trim(); // }
137+
value = value.substring(1).trim(); // }
138138
return results;
139139
}
140140

@@ -149,35 +149,35 @@ export function expandValue(variableCreate: Function, value: string, root: strin
149149
primitive = undefined;
150150
else if (value.startsWith("true")) {
151151
primitive = "true";
152-
value = value.substr(4).trim();
152+
value = value.substring(4).trim();
153153
} else if (value.startsWith("false")) {
154154
primitive = "false";
155-
value = value.substr(5).trim();
155+
value = value.substring(5).trim();
156156
} else if (match = nullpointerRegex.exec(value)) {
157157
primitive = "<nullptr>";
158-
value = value.substr(match[0].length).trim();
158+
value = value.substring(match[0].length).trim();
159159
} else if (match = referenceStringRegex.exec(value)) {
160-
value = value.substr(match[1].length).trim();
160+
value = value.substring(match[1].length).trim();
161161
primitive = parseCString();
162162
} else if (match = referenceRegex.exec(value)) {
163163
primitive = "*" + match[0];
164-
value = value.substr(match[0].length).trim();
164+
value = value.substring(match[0].length).trim();
165165
} else if (match = cppReferenceRegex.exec(value)) {
166166
primitive = match[0];
167-
value = value.substr(match[0].length).trim();
167+
value = value.substring(match[0].length).trim();
168168
} else if (match = charRegex.exec(value)) {
169169
primitive = match[1];
170-
value = value.substr(match[0].length - 1);
170+
value = value.substring(match[0].length - 1);
171171
primitive += " " + parseCString();
172172
} else if (match = numberRegex.exec(value)) {
173173
primitive = match[0];
174-
value = value.substr(match[0].length).trim();
174+
value = value.substring(match[0].length).trim();
175175
} else if (match = variableRegex.exec(value)) {
176176
primitive = match[0];
177-
value = value.substr(match[0].length).trim();
177+
value = value.substring(match[0].length).trim();
178178
} else if (match = errorRegex.exec(value)) {
179179
primitive = match[0];
180-
value = value.substr(match[0].length).trim();
180+
value = value.substring(match[0].length).trim();
181181
} else {
182182
primitive = value;
183183
}
@@ -199,7 +199,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin
199199
const variableMatch = resultRegex.exec(value);
200200
if (!variableMatch)
201201
return undefined;
202-
value = value.substr(variableMatch[0].length).trim();
202+
value = value.substring(variableMatch[0].length).trim();
203203
const name = variable = variableMatch[1];
204204
if (pushToStack)
205205
stack.push(variable);
@@ -240,15 +240,15 @@ export function expandValue(variableCreate: Function, value: string, root: strin
240240
value = value.trim();
241241
if (value[0] != ',')
242242
return undefined;
243-
value = value.substr(1).trim();
243+
value = value.substring(1).trim();
244244
return parseValue();
245245
};
246246

247247
parseCommaResult = (pushToStack: boolean = false) => {
248248
value = value.trim();
249249
if (value[0] != ',')
250250
return undefined;
251-
value = value.substr(1).trim();
251+
value = value.substring(1).trim();
252252
return parseResult(pushToStack);
253253
};
254254

src/backend/mi2/mi2.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ export class MI2 extends EventEmitter implements IBackend {
282282
this.buffer += data.toString("utf8");
283283
const end = this.buffer.lastIndexOf('\n');
284284
if (end != -1) {
285-
this.onOutput(this.buffer.substr(0, end));
286-
this.buffer = this.buffer.substr(end + 1);
285+
this.onOutput(this.buffer.substring(0, end));
286+
this.buffer = this.buffer.substring(end + 1);
287287
}
288288
if (this.buffer.length) {
289289
if (this.onOutputPartial(this.buffer)) {
@@ -299,8 +299,8 @@ export class MI2 extends EventEmitter implements IBackend {
299299
this.errbuf += data.toString("utf8");
300300
const end = this.errbuf.lastIndexOf('\n');
301301
if (end != -1) {
302-
this.onOutputStderr(this.errbuf.substr(0, end));
303-
this.errbuf = this.errbuf.substr(end + 1);
302+
this.onOutputStderr(this.errbuf.substring(0, end));
303+
this.errbuf = this.errbuf.substring(end + 1);
304304
}
305305
if (this.errbuf.length) {
306306
this.logNoNewLine("stderr", this.errbuf);
@@ -583,7 +583,7 @@ export class MI2 extends EventEmitter implements IBackend {
583583
let location = "";
584584
if (breakpoint.countCondition) {
585585
if (breakpoint.countCondition[0] == ">")
586-
location += "-i " + numRegex.exec(breakpoint.countCondition.substr(1))[0] + " ";
586+
location += "-i " + numRegex.exec(breakpoint.countCondition.substring(1))[0] + " ";
587587
else {
588588
const match = numRegex.exec(breakpoint.countCondition)[0];
589589
if (match.length != breakpoint.countCondition.length) {
@@ -820,7 +820,7 @@ export class MI2 extends EventEmitter implements IBackend {
820820

821821
sendUserInput(command: string, threadId: number = 0, frameLevel: number = 0): Thenable<MINode> {
822822
if (command.startsWith("-")) {
823-
return this.sendCommand(command.substr(1));
823+
return this.sendCommand(command.substring(1));
824824
} else {
825825
return this.sendCliCommand(command, threadId, frameLevel);
826826
}

src/backend/mi_parse.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function parseString(str: string): string {
3636
bufIndex += ret.write('\v', bufIndex);
3737
else if (str[i] == '0')
3838
bufIndex += ret.write('\0', bufIndex);
39-
else if (m = octalMatch.exec(str.substr(i))) {
39+
else if (m = octalMatch.exec(str.substring(i))) {
4040
ret.writeUInt8(parseInt(m[0], 8), bufIndex++);
4141
i += 2;
4242
} else
@@ -89,7 +89,7 @@ export class MINode implements MIInfo {
8989
do {
9090
let target = pathRegex.exec(path);
9191
if (target) {
92-
path = path.substr(target[0].length);
92+
path = path.substring(target[0].length);
9393
if (current.length && typeof current != "string") {
9494
const found = [];
9595
for (const element of current) {
@@ -105,11 +105,11 @@ export class MINode implements MIInfo {
105105
} else return undefined;
106106
} else if (path[0] == '@') {
107107
current = [current];
108-
path = path.substr(1);
108+
path = path.substring(1);
109109
} else {
110110
target = indexRegex.exec(path);
111111
if (target) {
112-
path = path.substr(target[0].length);
112+
path = path.substring(target[0].length);
113113
const i = parseInt(target[1]);
114114
if (current.length && typeof current != "string" && i >= 0 && i < current.length) {
115115
current = current[i];
@@ -168,7 +168,7 @@ export function parseMI(output: string): MINode {
168168
return "";
169169
let stringEnd = 1;
170170
let inString = true;
171-
let remaining = output.substr(1);
171+
let remaining = output.substring(1);
172172
let escaped = false;
173173
while (inString) {
174174
if (escaped)
@@ -178,16 +178,16 @@ export function parseMI(output: string): MINode {
178178
else if (remaining[0] == '"')
179179
inString = false;
180180

181-
remaining = remaining.substr(1);
181+
remaining = remaining.substring(1);
182182
stringEnd++;
183183
}
184184
let str;
185185
try {
186-
str = parseString(output.substr(0, stringEnd));
186+
str = parseString(output.substring(0, stringEnd));
187187
} catch (e) {
188-
str = output.substr(0, stringEnd);
188+
str = output.substring(0, stringEnd);
189189
}
190-
output = output.substr(stringEnd);
190+
output = output.substring(stringEnd);
191191
return str;
192192
};
193193

@@ -198,9 +198,9 @@ export function parseMI(output: string): MINode {
198198
return undefined;
199199
const oldContent = output;
200200
const canBeValueList = output[0] == '[';
201-
output = output.substr(1);
201+
output = output.substring(1);
202202
if (output[0] == '}' || output[0] == ']') {
203-
output = output.substr(1); // ] or }
203+
output = output.substring(1); // ] or }
204204
return [];
205205
}
206206
if (canBeValueList) {
@@ -211,7 +211,7 @@ export function parseMI(output: string): MINode {
211211
const remaining = output;
212212
while ((value = parseCommaValue()) !== undefined)
213213
values.push(value);
214-
output = output.substr(1); // ]
214+
output = output.substring(1); // ]
215215
return values;
216216
}
217217
}
@@ -221,7 +221,7 @@ export function parseMI(output: string): MINode {
221221
results.push(result);
222222
while (result = parseCommaResult())
223223
results.push(result);
224-
output = output.substr(1); // }
224+
output = output.substring(1); // }
225225
return results;
226226
}
227227
output = (canBeValueList ? '[' : '{') + output;
@@ -241,29 +241,29 @@ export function parseMI(output: string): MINode {
241241
const variableMatch = variableRegex.exec(output);
242242
if (!variableMatch)
243243
return undefined;
244-
output = output.substr(variableMatch[0].length + 1);
244+
output = output.substring(variableMatch[0].length + 1);
245245
const variable = variableMatch[1];
246246
return [variable, parseValue()];
247247
};
248248

249249
parseCommaValue = () => {
250250
if (output[0] != ',')
251251
return undefined;
252-
output = output.substr(1);
252+
output = output.substring(1);
253253
return parseValue();
254254
};
255255

256256
parseCommaResult = () => {
257257
if (output[0] != ',')
258258
return undefined;
259-
output = output.substr(1);
259+
output = output.substring(1);
260260
return parseResult();
261261
};
262262

263263
let match = undefined;
264264

265265
while (match = outOfBandRecordRegex.exec(output)) {
266-
output = output.substr(match[0].length);
266+
output = output.substring(match[0].length);
267267
if (match[1] && token === undefined && match[1] !== "undefined") {
268268
token = parseInt(match[1]);
269269
}
@@ -294,7 +294,7 @@ export function parseMI(output: string): MINode {
294294
}
295295

296296
if (match = resultRecordRegex.exec(output)) {
297-
output = output.substr(match[0].length);
297+
output = output.substring(match[0].length);
298298
if (match[1] && token === undefined) {
299299
token = parseInt(match[1]);
300300
}

src/frontend/extension.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function activate(context: vscode.ExtensionContext) {
1414
}
1515
const fileName = vscode.window.activeTextEditor.document.fileName;
1616
const ext = path.extname(fileName);
17-
return fileName.substr(0, fileName.length - ext.length);
17+
return fileName.substring(0, fileName.length - ext.length);
1818
}));
1919
context.subscriptions.push(vscode.commands.registerCommand("code-debug.getFileBasenameNoExt", () => {
2020
if (!vscode.window.activeTextEditor || !vscode.window.activeTextEditor.document || !vscode.window.activeTextEditor.document.fileName) {
@@ -23,7 +23,7 @@ export function activate(context: vscode.ExtensionContext) {
2323
}
2424
const fileName = path.basename(vscode.window.activeTextEditor.document.fileName);
2525
const ext = path.extname(fileName);
26-
return fileName.substr(0, fileName.length - ext.length);
26+
return fileName.substring(0, fileName.length - ext.length);
2727
}));
2828
}
2929

@@ -35,16 +35,16 @@ function getMemoryRange(range: string) {
3535
range = range.replace(/\s+/g, "").toLowerCase();
3636
let index;
3737
if ((index = range.indexOf("+")) != -1) {
38-
const from = range.substr(0, index);
39-
let length = range.substr(index + 1);
38+
const from = range.substring(0, index);
39+
let length = range.substring(index + 1);
4040
if (!memoryLocationRegex.exec(from))
4141
return undefined;
4242
if (memoryLocationRegex.exec(length))
43-
length = parseInt(length.substr(2), 16).toString();
43+
length = parseInt(length.substring(2), 16).toString();
4444
return "from=" + encodeURIComponent(from) + "&length=" + encodeURIComponent(length);
4545
} else if ((index = range.indexOf("-")) != -1) {
46-
const from = range.substr(0, index);
47-
const to = range.substr(index + 1);
46+
const from = range.substring(0, index);
47+
const to = range.substring(index + 1);
4848
if (!memoryLocationRegex.exec(from))
4949
return undefined;
5050
if (!memoryLocationRegex.exec(to))
@@ -94,14 +94,14 @@ class MemoryContentProvider implements vscode.TextDocumentContentProvider {
9494
let highlightAt = -1;
9595
const splits = uri.query.split("&");
9696
if (splits[0].split("=")[0] == "at") {
97-
const loc = parseInt(splits[0].split("=")[1].substr(2), 16);
97+
const loc = parseInt(splits[0].split("=")[1].substring(2), 16);
9898
highlightAt = 64;
9999
from = Math.max(loc - 64, 0);
100100
to = Math.max(loc + 768, 0);
101101
} else if (splits[0].split("=")[0] == "from") {
102-
from = parseInt(splits[0].split("=")[1].substr(2), 16);
102+
from = parseInt(splits[0].split("=")[1].substring(2), 16);
103103
if (splits[1].split("=")[0] == "to") {
104-
to = parseInt(splits[1].split("=")[1].substr(2), 16);
104+
to = parseInt(splits[1].split("=")[1].substring(2), 16);
105105
} else if (splits[1].split("=")[0] == "length") {
106106
to = from + parseInt(splits[1].split("=")[1]);
107107
} else return reject("Invalid Range");
@@ -124,7 +124,7 @@ class MemoryContentProvider implements vscode.TextDocumentContentProvider {
124124
}
125125
index++;
126126

127-
const digit = hexString.substr(i, 2);
127+
const digit = hexString.substring(i, i + 2);
128128
const digitNum = parseInt(digit, 16);
129129
if (digitNum >= 32 && digitNum <= 126)
130130
asciiLine += String.fromCharCode(digitNum);

0 commit comments

Comments
 (0)