drop the util namespace
parent
4b6c284ea1
commit
4b766a380f
|
@ -886,14 +886,29 @@ private:
|
|||
std::string_view p_quoted_item{};
|
||||
};
|
||||
|
||||
LIBCUBESCRIPT_EXPORT cs_strref value_list_concat(
|
||||
|
||||
LIBCUBESCRIPT_EXPORT char const *cs_parse_string(
|
||||
cs_state &cs, std::string_view str, size_t &nlines
|
||||
);
|
||||
|
||||
inline char const *cs_parse_string(
|
||||
cs_state &cs, std::string_view str
|
||||
) {
|
||||
size_t nlines;
|
||||
return cs_parse_string(cs, str, nlines);
|
||||
}
|
||||
|
||||
LIBCUBESCRIPT_EXPORT char const *cs_parse_word(
|
||||
cs_state &cs, std::string_view str
|
||||
);
|
||||
|
||||
LIBCUBESCRIPT_EXPORT cs_strref cs_concat_values(
|
||||
cs_state &cs, std::span<cs_value> vals,
|
||||
std::string_view sep = std::string_view{}
|
||||
);
|
||||
|
||||
namespace util {
|
||||
template<typename R>
|
||||
inline R escape_string(R writer, std::string_view str) {
|
||||
inline R cs_escape_string(R writer, std::string_view str) {
|
||||
*writer++ = '"';
|
||||
for (auto c: str) {
|
||||
switch (c) {
|
||||
|
@ -910,7 +925,7 @@ namespace util {
|
|||
}
|
||||
|
||||
template<typename R>
|
||||
inline R unescape_string(R writer, std::string_view str) {
|
||||
inline R cs_unescape_string(R writer, std::string_view str) {
|
||||
for (auto it = str.begin(); it != str.end(); ++it) {
|
||||
if (*it == '^') {
|
||||
++it;
|
||||
|
@ -947,21 +962,8 @@ namespace util {
|
|||
return writer;
|
||||
}
|
||||
|
||||
LIBCUBESCRIPT_EXPORT char const *parse_string(
|
||||
cs_state &cs, std::string_view str, size_t &nlines
|
||||
);
|
||||
|
||||
inline char const *parse_string(
|
||||
cs_state &cs, std::string_view str
|
||||
) {
|
||||
size_t nlines;
|
||||
return parse_string(cs, str, nlines);
|
||||
}
|
||||
|
||||
LIBCUBESCRIPT_EXPORT char const *parse_word(cs_state &cs, std::string_view str);
|
||||
|
||||
template<typename R>
|
||||
inline R print_stack(R writer, cs_stack_state const &st) {
|
||||
inline R cs_print_stack(R writer, cs_stack_state const &st) {
|
||||
char buf[32] = {0};
|
||||
auto nd = st.get();
|
||||
while (nd) {
|
||||
|
@ -984,7 +986,6 @@ namespace util {
|
|||
}
|
||||
return writer;
|
||||
}
|
||||
} /* namespace util */
|
||||
|
||||
} /* namespace cscript */
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ std::string_view cs_gen_state::get_str() {
|
|||
|
||||
cs_charbuf cs_gen_state::get_str_dup() {
|
||||
cs_charbuf buf{cs};
|
||||
util::unescape_string(std::back_inserter(buf), get_str());
|
||||
cs_unescape_string(std::back_inserter(buf), get_str());
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ static inline void compileunescapestr(cs_gen_state &gs) {
|
|||
size_t bufs = (gs.code.capacity() - gs.code.size()) * sizeof(uint32_t);
|
||||
auto alloc = cs_allocator<char>{gs.cs};
|
||||
auto *buf = alloc.allocate(bufs + 1);
|
||||
char *wbuf = util::unescape_string(&buf[0], str);
|
||||
char *wbuf = cs_unescape_string(&buf[0], str);
|
||||
memset(
|
||||
&buf[wbuf - buf], 0,
|
||||
sizeof(uint32_t) - (wbuf - buf) % sizeof(uint32_t)
|
||||
|
|
|
@ -203,7 +203,7 @@ LIBCUBESCRIPT_EXPORT std::size_t cs_list_parser::count() {
|
|||
LIBCUBESCRIPT_EXPORT cs_strref cs_list_parser::get_item() const {
|
||||
if (!p_quoted_item.empty() && (p_quoted_item.front() == '"')) {
|
||||
cs_charbuf buf{*p_state};
|
||||
util::unescape_string(std::back_inserter(buf), p_item);
|
||||
cs_unescape_string(std::back_inserter(buf), p_item);
|
||||
return cs_strref{*p_state, buf.str()};
|
||||
}
|
||||
return cs_strref{*p_state, p_item};
|
||||
|
|
|
@ -1093,7 +1093,7 @@ void cs_init_lib_base(cs_state &gcs) {
|
|||
result.set_str(e.what());
|
||||
if (e.get_stack().get()) {
|
||||
cs_charbuf buf{cs};
|
||||
util::print_stack(std::back_inserter(buf), e.get_stack());
|
||||
cs_print_stack(std::back_inserter(buf), e.get_stack());
|
||||
tback.set_str(buf.str());
|
||||
}
|
||||
rc = false;
|
||||
|
|
|
@ -437,7 +437,7 @@ end:
|
|||
for (p.set_input(s); p.parse(); ++n) {
|
||||
auto qi = p.get_quoted_item();
|
||||
if (!qi.empty() && (qi.front() == '"')) {
|
||||
util::unescape_string(std::back_inserter(buf), p.get_raw_item());
|
||||
cs_unescape_string(std::back_inserter(buf), p.get_raw_item());
|
||||
} else {
|
||||
buf.append(p.get_raw_item());
|
||||
}
|
||||
|
|
|
@ -79,13 +79,13 @@ void cs_init_lib_string(cs_state &cs) {
|
|||
|
||||
cs.new_command("escape", "s", [](auto &ccs, auto args, auto &res) {
|
||||
cs_charbuf s{ccs};
|
||||
util::escape_string(std::back_inserter(s), args[0].get_str());
|
||||
cs_escape_string(std::back_inserter(s), args[0].get_str());
|
||||
res.set_str(s.str());
|
||||
});
|
||||
|
||||
cs.new_command("unescape", "s", [](auto &ccs, auto args, auto &res) {
|
||||
cs_charbuf s{ccs};
|
||||
util::unescape_string(std::back_inserter(s), args[0].get_str());
|
||||
cs_unescape_string(std::back_inserter(s), args[0].get_str());
|
||||
res.set_str(s.str());
|
||||
});
|
||||
|
||||
|
|
|
@ -299,7 +299,7 @@ static bool do_call(cs_state &cs, std::string_view line, bool file = false) {
|
|||
);
|
||||
if (e.get_stack().get()) {
|
||||
std::string str;
|
||||
cscript::util::print_stack(std::back_inserter(str), e.get_stack());
|
||||
cscript::cs_print_stack(std::back_inserter(str), e.get_stack());
|
||||
std::printf("%s\n", str.data());
|
||||
}
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue