remove slice_until

master
Daniel Kolesa 2017-03-31 03:18:26 +02:00
parent 70ef1ff486
commit 6b17c4594f
6 changed files with 20 additions and 13 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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 */

View File

@ -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':

View File

@ -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 {

View File

@ -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;
}