move strref impl to cs_util

master
Daniel Kolesa 2021-03-19 02:28:30 +01:00
parent 08212df80f
commit 5a4cccf194
2 changed files with 45 additions and 43 deletions

View File

@ -286,6 +286,51 @@ char *cs_strman::alloc_buf(std::size_t len) const {
return strp;
};
/* strref */
cs_strref::cs_strref(cs_shared_state &cs, ostd::string_range str):
p_state{&cs}
{
p_str = cs.strman->add(str);
}
cs_strref::cs_strref(cs_state &cs, ostd::string_range str):
p_state{cs.p_state}
{
p_str = p_state->strman->add(str);
}
cs_strref::cs_strref(cs_strref const &ref): p_state{ref.p_state}, p_str{ref.p_str}
{
p_state->strman->ref(p_str);
}
/* this can be used by friends to do quick cs_strref creation */
cs_strref::cs_strref(char const *p, cs_shared_state &cs):
p_state{&cs}
{
p_str = p_state->strman->ref(p);
}
cs_strref::~cs_strref() {
p_state->strman->unref(p_str);
}
cs_strref &cs_strref::operator=(cs_strref const &ref) {
p_str = ref.p_str;
p_state = ref.p_state;
p_state->strman->ref(p_str);
return *this;
}
cs_strref::operator ostd::string_range() const {
return p_state->strman->get(p_str);
}
bool cs_strref::operator==(cs_strref const &s) const {
return p_str == s.p_str;
}
namespace util {
OSTD_EXPORT ostd::string_range parse_string(
cs_state &cs, ostd::string_range str, size_t &nlines

View File

@ -7,49 +7,6 @@
namespace cscript {
cs_strref::cs_strref(cs_shared_state &cs, ostd::string_range str):
p_state{&cs}
{
p_str = cs.strman->add(str);
}
cs_strref::cs_strref(cs_state &cs, ostd::string_range str):
p_state{cs.p_state}
{
p_str = p_state->strman->add(str);
}
cs_strref::cs_strref(cs_strref const &ref): p_state{ref.p_state}, p_str{ref.p_str}
{
p_state->strman->ref(p_str);
}
/* this can be used by friends to do quick cs_strref creation */
cs_strref::cs_strref(char const *p, cs_shared_state &cs):
p_state{&cs}
{
p_str = p_state->strman->ref(p);
}
cs_strref::~cs_strref() {
p_state->strman->unref(p_str);
}
cs_strref &cs_strref::operator=(cs_strref const &ref) {
p_str = ref.p_str;
p_state = ref.p_state;
p_state->strman->ref(p_str);
return *this;
}
cs_strref::operator ostd::string_range() const {
return p_state->strman->get(p_str);
}
bool cs_strref::operator==(cs_strref const &s) const {
return p_str == s.p_str;
}
struct cs_cmd_internal {
static void call(
cs_state &cs, cs_command *c, cs_value_r args, cs_value &ret