forked from OctaForge/libcubescript
fixes
parent
73d1b142d1
commit
5b1baafdb3
|
@ -53,7 +53,7 @@ cs_int cs_parse_int(ostd::string_range input, ostd::string_range *end) {
|
||||||
if (input.size() >= 2) {
|
if (input.size() >= 2) {
|
||||||
ostd::string_range pfx = input.slice(0, 2);
|
ostd::string_range pfx = input.slice(0, 2);
|
||||||
if ((pfx == "0x") || (pfx == "0X")) {
|
if ((pfx == "0x") || (pfx == "0X")) {
|
||||||
input += 2;
|
input = input.slice(2, input.size());
|
||||||
past = input;
|
past = input;
|
||||||
while (!past.empty() && isxdigit(*past)) {
|
while (!past.empty() && isxdigit(*past)) {
|
||||||
ret = ret * 16 + p_hexd_to_int(*past);
|
ret = ret * 16 + p_hexd_to_int(*past);
|
||||||
|
@ -61,7 +61,7 @@ cs_int cs_parse_int(ostd::string_range input, ostd::string_range *end) {
|
||||||
}
|
}
|
||||||
goto done;
|
goto done;
|
||||||
} else if ((pfx == "0b") || (pfx == "0B")) {
|
} else if ((pfx == "0b") || (pfx == "0B")) {
|
||||||
input += 2;
|
input = input.slice(2, input.size());
|
||||||
past = input;
|
past = input;
|
||||||
while (!past.empty() && ((*past == '0') || (*past == '1'))) {
|
while (!past.empty() && ((*past == '0') || (*past == '1'))) {
|
||||||
ret = ret * 2 + (*past - '0');
|
ret = ret * 2 + (*past - '0');
|
||||||
|
@ -164,7 +164,7 @@ cs_float cs_parse_float(ostd::string_range input, ostd::string_range *end) {
|
||||||
if (input.size() >= 2) {
|
if (input.size() >= 2) {
|
||||||
ostd::string_range pfx = input.slice(0, 2);
|
ostd::string_range pfx = input.slice(0, 2);
|
||||||
if ((pfx == "0x") || (pfx == "0X")) {
|
if ((pfx == "0x") || (pfx == "0X")) {
|
||||||
input += 2;
|
input = input.slice(2, input.size());
|
||||||
if (!parse_gen_float<true>(input, end, ret)) {
|
if (!parse_gen_float<true>(input, end, ret)) {
|
||||||
p_set_end(orig, end);
|
p_set_end(orig, end);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -232,7 +232,8 @@ end:
|
||||||
cs, "unfinished string '%s'", slice_until(orig, str)
|
cs, "unfinished string '%s'", slice_until(orig, str)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return str + 1;
|
str.pop_front();
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
OSTD_EXPORT ostd::string_range parse_word(
|
OSTD_EXPORT ostd::string_range parse_word(
|
||||||
|
@ -257,13 +258,15 @@ end:
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '[':
|
case '[':
|
||||||
str = parse_word(cs, str + 1);
|
str.pop_front();
|
||||||
|
str = parse_word(cs, str);
|
||||||
if (str.empty() || (*str != ']')) {
|
if (str.empty() || (*str != ']')) {
|
||||||
throw cs_error(cs, "missing \"]\"");
|
throw cs_error(cs, "missing \"]\"");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '(':
|
case '(':
|
||||||
str = parse_word(cs, str + 1);
|
str.pop_front();
|
||||||
|
str = parse_word(cs, str);
|
||||||
if (str.empty() || (*str != ')')) {
|
if (str.empty() || (*str != ')')) {
|
||||||
throw cs_error(cs, "missing \")\"");
|
throw cs_error(cs, "missing \")\"");
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,7 @@ void cs_init_lib_string(cs_state &cs) {
|
||||||
if (!found.empty()) {
|
if (!found.empty()) {
|
||||||
buf += s.slice(0, &found[0] - &s[0]);
|
buf += s.slice(0, &found[0] - &s[0]);
|
||||||
buf += (i & 1) ? newval2 : newval;
|
buf += (i & 1) ? newval2 : newval;
|
||||||
s = found + oldval.size();
|
s = found.slice(oldval.size(), found.size());
|
||||||
} else {
|
} else {
|
||||||
buf += s;
|
buf += s;
|
||||||
res.set_str(std::move(buf));
|
res.set_str(std::move(buf));
|
||||||
|
|
|
@ -132,7 +132,7 @@ static inline cs_command *get_hint_cmd(cs_state &cs, ostd::string_range buf) {
|
||||||
ostd::string_range nextchars = "([;";
|
ostd::string_range nextchars = "([;";
|
||||||
auto lp = ostd::find_one_of(buf, nextchars);
|
auto lp = ostd::find_one_of(buf, nextchars);
|
||||||
if (!lp.empty()) {
|
if (!lp.empty()) {
|
||||||
cs_command *cmd = get_hint_cmd(cs, buf + 1);
|
cs_command *cmd = get_hint_cmd(cs, buf.slice(1, buf.size()));
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ static bool do_call(cs_state &cs, ostd::string_range line, bool file = false) {
|
||||||
terr.slice(0, &col[0] - &terr[0]),
|
terr.slice(0, &col[0] - &terr[0]),
|
||||||
[](auto c) { return !isdigit(c); }
|
[](auto c) { return !isdigit(c); }
|
||||||
).empty();
|
).empty();
|
||||||
terr = col + 2;
|
terr = col.slice(2, col.size());
|
||||||
}
|
}
|
||||||
if (!file && ((terr == "missing \"]\"") || (terr == "missing \")\""))) {
|
if (!file && ((terr == "missing \"]\"") || (terr == "missing \")\""))) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue