remove set_mstr

master
Daniel Kolesa 2016-09-15 23:09:52 +02:00
parent 1846fee1a0
commit 62d4afccd2
3 changed files with 13 additions and 22 deletions

View File

@ -82,7 +82,6 @@ struct OSTD_EXPORT CsValue {
void set_null(); void set_null();
void set_code(CsBytecode *val); void set_code(CsBytecode *val);
void set_cstr(ostd::ConstCharRange val); void set_cstr(ostd::ConstCharRange val);
void set_mstr(ostd::CharRange val);
void set_ident(CsIdent *val); void set_ident(CsIdent *val);
void set_macro(ostd::ConstCharRange val); void set_macro(ostd::ConstCharRange val);
@ -281,7 +280,7 @@ struct OSTD_EXPORT CsAlias: CsIdent {
void get_cstr(CsValue &v) const; void get_cstr(CsValue &v) const;
void get_cval(CsValue &v) const; void get_cval(CsValue &v) const;
private: private:
CsAlias(ostd::ConstCharRange n, char *a, int flags); CsAlias(ostd::ConstCharRange n, CsString a, int flags);
CsAlias(ostd::ConstCharRange n, CsInt a, int flags); CsAlias(ostd::ConstCharRange n, CsInt a, int flags);
CsAlias(ostd::ConstCharRange n, CsFloat a, int flags); CsAlias(ostd::ConstCharRange n, CsFloat a, int flags);
CsAlias(ostd::ConstCharRange n, int flags); CsAlias(ostd::ConstCharRange n, int flags);

View File

@ -97,16 +97,18 @@ void CsValue::set_float(CsFloat val) {
} }
void CsValue::set_str(CsString val) { void CsValue::set_str(CsString val) {
if (val.size() == 0) { csv_cleanup(p_type, p_stor);
p_type = CsValueType::String;
p_len = val.size();
if (p_len == 0) {
/* ostd zero length strings cannot be disowned */ /* ostd zero length strings cannot be disowned */
char *buf = new char[1]; char *buf = new char[1];
buf[0] = '\0'; buf[0] = '\0';
set_mstr(buf); csv_get<char *>(p_stor) = buf;
return; return;
} }
ostd::CharRange cr = val.iter(); csv_get<char *>(p_stor) = val.data();
val.disown(); val.disown();
set_mstr(cr);
} }
void CsValue::set_null() { void CsValue::set_null() {
@ -127,13 +129,6 @@ void CsValue::set_cstr(ostd::ConstCharRange val) {
csv_get<char const *>(p_stor) = val.data(); csv_get<char const *>(p_stor) = val.data();
} }
void CsValue::set_mstr(ostd::CharRange val) {
csv_cleanup(p_type, p_stor);
p_type = CsValueType::String;
p_len = val.size();
csv_get<char *>(p_stor) = val.data();
}
void CsValue::set_ident(CsIdent *val) { void CsValue::set_ident(CsIdent *val) {
csv_cleanup(p_type, p_stor); csv_cleanup(p_type, p_stor);
p_type = CsValueType::Ident; p_type = CsValueType::Ident;

View File

@ -57,11 +57,11 @@ CsSvar::CsSvar(ostd::ConstCharRange name, CsString v, CsVarCb f, int fl):
p_storage(ostd::move(v)), p_overrideval() p_storage(ostd::move(v)), p_overrideval()
{} {}
CsAlias::CsAlias(ostd::ConstCharRange name, char *a, int fl): CsAlias::CsAlias(ostd::ConstCharRange name, CsString a, int fl):
CsIdent(CsIdentType::Alias, name, fl), CsIdent(CsIdentType::Alias, name, fl),
p_acode(nullptr), p_astack(nullptr) p_acode(nullptr), p_astack(nullptr)
{ {
p_val.set_mstr(a); p_val.set_str(ostd::move(a));
} }
CsAlias::CsAlias(ostd::ConstCharRange name, CsInt a, int fl): CsAlias::CsAlias(ostd::ConstCharRange name, CsInt a, int fl):
CsIdent(CsIdentType::Alias, name, fl), CsIdent(CsIdentType::Alias, name, fl),
@ -1008,7 +1008,7 @@ static inline void cs_loop_conc(
if (n <= 0 || !idv.has_alias()) { if (n <= 0 || !idv.has_alias()) {
return; return;
} }
CsVector<char> s; CsString s;
for (CsInt i = 0; i < n; ++i) { for (CsInt i = 0; i < n; ++i) {
idv.set_int(offset + i * step); idv.set_int(offset + i * step);
idv.push(); idv.push();
@ -1021,16 +1021,13 @@ static inline void cs_loop_conc(
default: default:
break; break;
} }
CsString vstr = ostd::move(v.get_str());
if (space && i) { if (space && i) {
s.push(' '); s += ' ';
} }
s.push_n(vstr.data(), vstr.size()); s += v.get_str();
} }
end: end:
s.push('\0'); res.set_str(ostd::move(s));
ostd::Size len = s.size() - 1;
res.set_mstr(ostd::CharRange(s.disown(), len));
} }
void cs_init_lib_base(CsState &gcs) { void cs_init_lib_base(CsState &gcs) {