remove slice_until

master
Daniel Kolesa 2017-06-15 20:44:09 +02:00
parent 3744dec1f0
commit d01349886a
3 changed files with 10 additions and 16 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 = slice_until(beg, source);
ostd::string_range ret = beg.slice(0, &source[0] - &beg[0]);
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 slice_until(op, source);
return op.slice(0, &source[0] - &op[0]);
}
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 slice_until(beg, source);
return beg.slice(0, &source[0] - &beg[0]);
}
static inline int cs_ret_code(int type, int def = 0) {
@ -497,9 +497,9 @@ static bool compileblockstr(cs_gen_state &gs, ostd::string_range str, bool macro
str.pop_front();
break;
case '\"': {
ostd::string_range start = str;
auto start = str;
str = util::parse_string(gs.cs, str);
ostd::string_range strr = slice_until(start, str);
auto strr = start.slice(0, &str[0] - &start[0]);
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'", slice_until(orig, str)
cs, "unfinished string '%s'", orig.slice(0, &str[0] - &orig[0])
);
}
str.pop_front();
@ -306,7 +306,7 @@ end:
case '"':
p_quote = p_input;
p_input = parse_string(p_state, p_input);
p_quote = slice_until(p_quote, p_input);
p_quote = p_quote.slice(0, &p_input[0] - &p_quote[0]);
p_item = p_quote.slice(1, p_quote.size() - 1);
break;
case '(':
@ -351,9 +351,9 @@ end:
}
}
endblock:
p_item = slice_until(p_item, p_input);
p_item = p_item.slice(0, &p_input[0] - &p_item[0]);
p_item.pop_back();
p_quote = slice_until(p_quote, p_input);
p_quote = p_quote.slice(0, &p_input[0] - &p_quote[0]);
break;
}
case ')':
@ -361,7 +361,7 @@ endblock:
return false;
default: {
ostd::string_range e = parse_word(p_state, p_input);
p_quote = p_item = slice_until(p_input, e);
p_quote = p_item = p_input.slice(0, &e[0] - &p_input[0]);
p_input = e;
break;
}

View File

@ -38,12 +38,6 @@ 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 */