Implement OwnedStringView::from_string_literal
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
df9a13cbfb
commit
cf3b2176f0
@ -12,6 +12,8 @@ class OwnedStringView
|
||||
|
||||
Result<OwnedStringView> clone() const;
|
||||
|
||||
static Result<OwnedStringView> from_string_literal(const char* str);
|
||||
|
||||
const char* chars() const
|
||||
{
|
||||
return m_string;
|
||||
|
@ -39,4 +39,11 @@ const char& OwnedStringView::operator[](usize index) const
|
||||
{
|
||||
expect(index < m_length, "index out of range");
|
||||
return m_string[index];
|
||||
}
|
||||
|
||||
Result<OwnedStringView> OwnedStringView::from_string_literal(const char* str)
|
||||
{
|
||||
char* dup = strdup(str);
|
||||
if (!dup) return err(ENOMEM);
|
||||
return OwnedStringView{dup};
|
||||
}
|
Loading…
Reference in New Issue
Block a user