mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-24 07:02:26 +01:00
Fixed speechmarks not making numeric terminal arguments into strings (#391)
This commit is contained in:
parent
f50b731846
commit
b1af58d6a6
@ -1,8 +1,9 @@
|
|||||||
import { KEY } from "../utils/helpers/keyCodes";
|
import { KEY } from "../utils/helpers/keyCodes";
|
||||||
import { substituteAliases } from "../Alias";
|
import { substituteAliases } from "../Alias";
|
||||||
// Helper function to parse individual arguments into number/boolean/string as appropriate
|
// Helper function to parse individual arguments into number/boolean/string as appropriate
|
||||||
function parseArg(arg: string): string | number | boolean {
|
function parseArg(arg: string, stringOverride: boolean): string | number | boolean {
|
||||||
// Handles all numbers including hexadecimal, octal, and binary representations, returning NaN on an unparsable string
|
// Handles all numbers including hexadecimal, octal, and binary representations, returning NaN on an unparsable string
|
||||||
|
if (stringOverride) return arg;
|
||||||
const asNumber = Number(arg);
|
const asNumber = Number(arg);
|
||||||
if (!isNaN(asNumber)) {
|
if (!isNaN(asNumber)) {
|
||||||
return asNumber;
|
return asNumber;
|
||||||
@ -47,14 +48,17 @@ export function ParseCommand(command: string): (string | number | boolean)[] {
|
|||||||
let lastQuote = "";
|
let lastQuote = "";
|
||||||
|
|
||||||
let arg = "";
|
let arg = "";
|
||||||
|
let stringOverride = false;
|
||||||
|
|
||||||
while (idx < command.length) {
|
while (idx < command.length) {
|
||||||
const c = command.charAt(idx);
|
const c = command.charAt(idx);
|
||||||
|
|
||||||
// If the current character is a backslash, add the next character verbatim to the argument
|
// If the current character is a backslash, add the next character verbatim to the argument
|
||||||
if (c === "\\") {
|
if (c === "\\") {
|
||||||
arg += command.charAt(++idx);
|
arg += command.charAt(++idx);
|
||||||
|
|
||||||
// If the current character is a single- or double-quote mark, add it to the current argument.
|
// If the current character is a single- or double-quote mark, add it to the current argument.
|
||||||
} else if (c === KEY.DOUBLE_QUOTE || c === KEY.QUOTE) {
|
} else if (c === KEY.DOUBLE_QUOTE || c === KEY.QUOTE) {
|
||||||
|
stringOverride = true;
|
||||||
// If we're currently in a quoted string argument and this quote mark is the same as the beginning,
|
// If we're currently in a quoted string argument and this quote mark is the same as the beginning,
|
||||||
// the string is done
|
// the string is done
|
||||||
if (lastQuote !== "" && c === lastQuote) {
|
if (lastQuote !== "" && c === lastQuote) {
|
||||||
@ -69,8 +73,9 @@ export function ParseCommand(command: string): (string | number | boolean)[] {
|
|||||||
// If the current character is a space and we are not inside a string, parse the current argument
|
// If the current character is a space and we are not inside a string, parse the current argument
|
||||||
// and start a new one
|
// and start a new one
|
||||||
} else if (c === KEY.SPACE && lastQuote === "") {
|
} else if (c === KEY.SPACE && lastQuote === "") {
|
||||||
args.push(parseArg(arg));
|
args.push(parseArg(arg, stringOverride));
|
||||||
|
|
||||||
|
stringOverride = false;
|
||||||
arg = "";
|
arg = "";
|
||||||
} else {
|
} else {
|
||||||
// Add the current character to the current argument
|
// Add the current character to the current argument
|
||||||
@ -82,7 +87,7 @@ export function ParseCommand(command: string): (string | number | boolean)[] {
|
|||||||
|
|
||||||
// Add the last arg (if any)
|
// Add the last arg (if any)
|
||||||
if (arg !== "") {
|
if (arg !== "") {
|
||||||
args.push(parseArg(arg));
|
args.push(parseArg(arg, stringOverride));
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
|
Loading…
Reference in New Issue
Block a user