libluna: Allow constructing a StringView from a string that might not be null-terminated

This commit is contained in:
apio 2023-05-02 10:49:12 +02:00
parent 1d6a39c924
commit 1444cbb3df
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 8 additions and 1 deletions

View File

@ -43,6 +43,8 @@ class StringView
Result<Vector<String>> split(StringView delim) const;
Result<Vector<String>> split_once(char delim) const;
static StringView from_fixed_size_cstring(const char* string, usize max);
Result<usize> to_uint() const;
Iterator begin() const

View File

@ -120,5 +120,10 @@ Result<usize> StringView::to_uint() const
Result<String> StringView::to_string()
{
return String::from_cstring(m_string);
return String::from_string_view(*this);
}
StringView StringView::from_fixed_size_cstring(const char* string, usize max)
{
return { string, strnlen(string, max) };
}