libluna: Add String::trim
This commit is contained in:
parent
257c2ffd0a
commit
dcc6bbf055
@ -32,6 +32,8 @@ class String
|
|||||||
return view().split_once(delim);
|
return view().split_once(delim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void trim(StringView delim);
|
||||||
|
|
||||||
static Result<String> format(const String& fmt, ...);
|
static Result<String> format(const String& fmt, ...);
|
||||||
static Result<String> format(StringView fmt, ...);
|
static Result<String> format(StringView fmt, ...);
|
||||||
|
|
||||||
|
@ -80,6 +80,25 @@ Result<Vector<String>> String::split(StringView delim) const
|
|||||||
return view().split(delim);
|
return view().split(delim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void String::trim(StringView delim)
|
||||||
|
{
|
||||||
|
isize i = (isize)m_length;
|
||||||
|
|
||||||
|
while (i--)
|
||||||
|
{
|
||||||
|
char c = chars()[i];
|
||||||
|
if (!strchr(delim.chars(), c)) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (m_inline) m_inline_storage[i] = '\0';
|
||||||
|
else
|
||||||
|
m_string[i] = '\0';
|
||||||
|
|
||||||
|
m_length = (usize)i;
|
||||||
|
}
|
||||||
|
|
||||||
const char& String::operator[](usize index) const
|
const char& String::operator[](usize index) const
|
||||||
{
|
{
|
||||||
expect(index < m_length, "index out of range");
|
expect(index < m_length, "index out of range");
|
||||||
|
Loading…
Reference in New Issue
Block a user