From 5b1baafdb393e523731ef6e6951bdbcf24c31ebc Mon Sep 17 00:00:00 2001 From: q66 Date: Sat, 1 Apr 2017 01:03:22 +0200 Subject: [PATCH] fixes --- src/cs_util.cc | 15 +++++++++------ src/lib_str.cc | 2 +- tools/repl.cc | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cs_util.cc b/src/cs_util.cc index 6500aa95..4128dd13 100644 --- a/src/cs_util.cc +++ b/src/cs_util.cc @@ -53,7 +53,7 @@ cs_int cs_parse_int(ostd::string_range input, ostd::string_range *end) { if (input.size() >= 2) { ostd::string_range pfx = input.slice(0, 2); if ((pfx == "0x") || (pfx == "0X")) { - input += 2; + input = input.slice(2, input.size()); past = input; while (!past.empty() && isxdigit(*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; } else if ((pfx == "0b") || (pfx == "0B")) { - input += 2; + input = input.slice(2, input.size()); past = input; while (!past.empty() && ((*past == '0') || (*past == '1'))) { 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) { ostd::string_range pfx = input.slice(0, 2); if ((pfx == "0x") || (pfx == "0X")) { - input += 2; + input = input.slice(2, input.size()); if (!parse_gen_float(input, end, ret)) { p_set_end(orig, end); return ret; @@ -232,7 +232,8 @@ end: cs, "unfinished string '%s'", slice_until(orig, str) ); } - return str + 1; + str.pop_front(); + return str; } OSTD_EXPORT ostd::string_range parse_word( @@ -257,13 +258,15 @@ end: } break; case '[': - str = parse_word(cs, str + 1); + str.pop_front(); + str = parse_word(cs, str); if (str.empty() || (*str != ']')) { throw cs_error(cs, "missing \"]\""); } break; case '(': - str = parse_word(cs, str + 1); + str.pop_front(); + str = parse_word(cs, str); if (str.empty() || (*str != ')')) { throw cs_error(cs, "missing \")\""); } diff --git a/src/lib_str.cc b/src/lib_str.cc index 86e2d2de..cbd08436 100644 --- a/src/lib_str.cc +++ b/src/lib_str.cc @@ -194,7 +194,7 @@ void cs_init_lib_string(cs_state &cs) { if (!found.empty()) { buf += s.slice(0, &found[0] - &s[0]); buf += (i & 1) ? newval2 : newval; - s = found + oldval.size(); + s = found.slice(oldval.size(), found.size()); } else { buf += s; res.set_str(std::move(buf)); diff --git a/tools/repl.cc b/tools/repl.cc index 24cff51a..dac40dd5 100644 --- a/tools/repl.cc +++ b/tools/repl.cc @@ -132,7 +132,7 @@ static inline cs_command *get_hint_cmd(cs_state &cs, ostd::string_range buf) { ostd::string_range nextchars = "([;"; auto lp = ostd::find_one_of(buf, nextchars); 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) { 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]), [](auto c) { return !isdigit(c); } ).empty(); - terr = col + 2; + terr = col.slice(2, col.size()); } if (!file && ((terr == "missing \"]\"") || (terr == "missing \")\""))) { return true;