xo-object2: add DString::from_cstr + utest

This commit is contained in:
Roland Conybeare 2026-01-13 16:47:44 -05:00
commit 6b216a7e84
2 changed files with 36 additions and 0 deletions

View file

@ -4,6 +4,7 @@
**/
#include "DString.hpp"
#include <cstring>
namespace xo {
using xo::facet::typeseq;
@ -31,6 +32,24 @@ namespace xo {
return result;
}
DString *
DString::from_cstr(obj<AAllocator> mm,
const char * cstr)
{
size_type len = std::strlen(cstr);
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_, cstr, cap);
return result;
}
} /*namespace scm*/
} /*namespace xo*/