xo-object2: + DString::from_view()
This commit is contained in:
parent
563f6b3ea4
commit
2edfb56530
3 changed files with 50 additions and 0 deletions
|
|
@ -57,6 +57,25 @@ namespace xo {
|
|||
return result;
|
||||
}
|
||||
|
||||
DString *
|
||||
DString::from_view(obj<AAllocator> mm,
|
||||
std::string_view sv)
|
||||
{
|
||||
size_type len = sv.size();
|
||||
size_type cap = len + 1;
|
||||
|
||||
void * mem = mm.alloc(typeseq::id<DString>(),
|
||||
sizeof(DString) + cap);
|
||||
|
||||
DString * result = new (mem) DString();
|
||||
result->capacity_ = cap;
|
||||
result->size_ = len;
|
||||
std::memcpy(result->chars_, sv.data(), len);
|
||||
result->chars_[len] = '\0';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
DString *
|
||||
DString::clone(obj<AAllocator> mm, const DString * src)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue