From 6b17c4594f42cf3eb76794d7f857710066d576c2 Mon Sep 17 00:00:00 2001 From: q66 Date: Fri, 31 Mar 2017 03:18:26 +0200 Subject: [PATCH] remove slice_until --- src/cs_gen.cc | 8 ++++---- src/cs_util.cc | 10 +++++----- src/cs_util.hh | 6 ++++++ src/cubescript.cc | 2 +- src/lib_str.cc | 2 +- tools/repl.cc | 5 +++-- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/cs_gen.cc b/src/cs_gen.cc index 5bbaf3f2..f18ab368 100644 --- a/src/cs_gen.cc +++ b/src/cs_gen.cc @@ -13,7 +13,7 @@ ostd::string_range cs_gen_state::get_str() { ostd::string_range beg = source; source = util::parse_string(cs, source, nl); current_line += nl - 1; - ostd::string_range ret = ostd::slice_until(beg, source); + ostd::string_range ret = slice_until(beg, source); return ret.slice(1, ret.size() - 1); } @@ -37,7 +37,7 @@ ostd::string_range cs_gen_state::read_macro_name() { for (; isalnum(c) || (c == '_'); c = current()) { next_char(); } - return ostd::slice_until(op, source); + return slice_until(op, source); } char cs_gen_state::skip_until(ostd::string_range chars) { @@ -95,7 +95,7 @@ void cs_gen_state::skip_comments() { ostd::string_range cs_gen_state::get_word() { auto beg = source; source = util::parse_word(cs, source); - return ostd::slice_until(beg, source); + return slice_until(beg, source); } static inline int cs_ret_code(int type, int def = 0) { @@ -499,7 +499,7 @@ static bool compileblockstr(cs_gen_state &gs, ostd::string_range str, bool macro case '\"': { ostd::string_range start = str; str = util::parse_string(gs.cs, str); - ostd::string_range strr = ostd::slice_until(start, str); + ostd::string_range strr = slice_until(start, str); memcpy(&buf[len], strr.data(), strr.size()); len += strr.size(); break; diff --git a/src/cs_util.cc b/src/cs_util.cc index 0863eed5..46d960b8 100644 --- a/src/cs_util.cc +++ b/src/cs_util.cc @@ -229,7 +229,7 @@ end: nlines = nl; if (str.empty() || (*str != '\"')) { throw cs_error( - cs, "unfinished string '%s'", ostd::slice_until(orig, str) + cs, "unfinished string '%s'", slice_until(orig, str) ); } return str + 1; @@ -303,7 +303,7 @@ end: case '"': p_quote = p_input; p_input = parse_string(p_state, p_input); - p_quote = ostd::slice_until(p_quote, p_input); + p_quote = slice_until(p_quote, p_input); p_item = p_quote.slice(1, p_quote.size() - 1); break; case '(': @@ -348,9 +348,9 @@ end: } } endblock: - p_item = ostd::slice_until(p_item, p_input); + p_item = slice_until(p_item, p_input); p_item.pop_back(); - p_quote = ostd::slice_until(p_quote, p_input); + p_quote = slice_until(p_quote, p_input); break; } case ')': @@ -358,7 +358,7 @@ endblock: return false; default: { ostd::string_range e = parse_word(p_state, p_input); - p_quote = p_item = ostd::slice_until(p_input, e); + p_quote = p_item = slice_until(p_input, e); p_input = e; break; } diff --git a/src/cs_util.hh b/src/cs_util.hh index 0a57dc30..12984590 100644 --- a/src/cs_util.hh +++ b/src/cs_util.hh @@ -38,6 +38,12 @@ inline void cs_do_and_cleanup(F1 &&dof, F2 &&clf) { dof(); } +inline ostd::string_range slice_until( + ostd::string_range s1, ostd::string_range s2 +) { + return s1.slice(0, &s2[0] - &s1[0]); +} + } /* namespace cscript */ #endif /* LIBCUBESCRIPT_CS_UTIL_HH */ diff --git a/src/cubescript.cc b/src/cubescript.cc index a877094a..9373c6ee 100644 --- a/src/cubescript.cc +++ b/src/cubescript.cc @@ -982,7 +982,7 @@ cs_command *cs_state::new_command( return nullptr; } if (nargs < MaxArguments) { - fmt = ostd::string_range{&fmt[-int(*fmt) + '0' - 1], &fmt[fmt.size()]} + fmt = ostd::string_range{&fmt[-int(*fmt) + '0' - 1], &fmt[fmt.size()]}; } break; case 'C': diff --git a/src/lib_str.cc b/src/lib_str.cc index 62872163..86e2d2de 100644 --- a/src/lib_str.cc +++ b/src/lib_str.cc @@ -192,7 +192,7 @@ void cs_init_lib_string(cs_state &cs) { } } if (!found.empty()) { - buf += ostd::slice_until(s, found); + buf += s.slice(0, &found[0] - &s[0]); buf += (i & 1) ? newval2 : newval; s = found + oldval.size(); } else { diff --git a/tools/repl.cc b/tools/repl.cc index a1cf1f02..24cff51a 100644 --- a/tools/repl.cc +++ b/tools/repl.cc @@ -143,7 +143,7 @@ static inline cs_command *get_hint_cmd(cs_state &cs, ostd::string_range buf) { ostd::string_range spaces = " \t\r\n"; ostd::string_range s = ostd::find_one_of(buf, spaces); if (!s.empty()) { - buf = ostd::slice_until(buf, s); + buf = buf.slice(0, &s[0] - &buf[0]); } if (!buf.empty()) { auto cmd = cs.get_ident(buf); @@ -207,7 +207,8 @@ static bool do_call(cs_state &cs, ostd::string_range line, bool file = false) { bool is_lnum = false; if (!col.empty()) { is_lnum = ostd::find_if( - ostd::slice_until(terr, col), [](auto c) { return !isdigit(c); } + terr.slice(0, &col[0] - &terr[0]), + [](auto c) { return !isdigit(c); } ).empty(); terr = col + 2; }