BAN: Make StringView::split const and fix bug with empties
This commit is contained in:
parent
1bd33e76e5
commit
d2bc399770
|
@ -61,7 +61,7 @@ namespace BAN
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<Vector<StringView>> StringView::split(char delim, bool allow_empties)
|
ErrorOr<Vector<StringView>> StringView::split(char delim, bool allow_empties) const
|
||||||
{
|
{
|
||||||
size_type count = 0;
|
size_type count = 0;
|
||||||
{
|
{
|
||||||
|
@ -92,12 +92,12 @@ namespace BAN
|
||||||
start = i + 1;
|
start = i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (start != m_size)
|
if (start < m_size || (start == m_size && allow_empties))
|
||||||
TRY(result.push_back(this->substring(start)));
|
TRY(result.push_back(this->substring(start)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<Vector<StringView>> StringView::split(bool(*comp)(char), bool allow_empties)
|
ErrorOr<Vector<StringView>> StringView::split(bool(*comp)(char), bool allow_empties) const
|
||||||
{
|
{
|
||||||
size_type count = 0;
|
size_type count = 0;
|
||||||
{
|
{
|
||||||
|
@ -128,7 +128,7 @@ namespace BAN
|
||||||
start = i + 1;
|
start = i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (start != m_size)
|
if (start < m_size || (start == m_size && allow_empties))
|
||||||
TRY(result.push_back(this->substring(start)));
|
TRY(result.push_back(this->substring(start)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ namespace BAN
|
||||||
|
|
||||||
StringView substring(size_type, size_type = -1) const;
|
StringView substring(size_type, size_type = -1) const;
|
||||||
|
|
||||||
ErrorOr<Vector<StringView>> split(char, bool = false);
|
ErrorOr<Vector<StringView>> split(char, bool = false) const;
|
||||||
ErrorOr<Vector<StringView>> split(bool(*comp)(char), bool = false);
|
ErrorOr<Vector<StringView>> split(bool(*comp)(char), bool = false) const;
|
||||||
|
|
||||||
char back() const;
|
char back() const;
|
||||||
char front() const;
|
char front() const;
|
||||||
|
|
Loading…
Reference in New Issue