add get_strr to retrieve read-only range without allocs

master
Daniel Kolesa 2016-07-31 00:49:32 +01:00
parent 6922853d66
commit 49e09a117e
2 changed files with 22 additions and 0 deletions

View File

@ -598,6 +598,26 @@ ostd::String Ident::get_str() const {
return cs_get_str(val, get_valtype(), valtype >> 4);
}
static inline ostd::ConstCharRange cs_get_strr(IdentValue const &v, int type, int len) {
switch (type) {
case VAL_STR:
case VAL_MACRO:
case VAL_CSTR:
return ostd::ConstCharRange(v.s, len);
default:
break;
}
return ostd::ConstCharRange();
}
ostd::ConstCharRange TaggedValue::get_strr() const {
return cs_get_strr(*this, get_type(), p_type >> 4);
}
ostd::ConstCharRange Ident::get_strr() const {
return cs_get_strr(val, get_valtype(), valtype >> 4);
}
static inline void cs_get_val(IdentValue const &v, int type, int len, TaggedValue &r) {
switch (type) {
case VAL_STR:

View File

@ -125,6 +125,7 @@ struct OSTD_EXPORT TaggedValue: IdentValue {
}
ostd::String get_str() const;
ostd::ConstCharRange get_strr() const;
int get_int() const;
float get_float() const;
ostd::Uint32 *get_code() const;
@ -275,6 +276,7 @@ struct OSTD_EXPORT Ident {
float get_float() const;
int get_int() const;
ostd::String get_str() const;
ostd::ConstCharRange get_strr() const;
void get_val(TaggedValue &r) const;
void get_cstr(TaggedValue &v) const;
void get_cval(TaggedValue &v) const;