AK: Add String::substring(start)
This is a convenience API when you just want the rest of the string starting at some index. We already had substring_view() in the same flavor, so this is a complement to that.
This commit is contained in:
parent
e9280cba13
commit
5d0fda3d39
Notes:
sideshowbarker
2024-07-19 00:55:50 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/5d0fda3d39c
2 changed files with 8 additions and 0 deletions
|
@ -129,6 +129,13 @@ String String::isolated_copy() const
|
||||||
return String(move(*impl));
|
return String(move(*impl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String String::substring(size_t start) const
|
||||||
|
{
|
||||||
|
ASSERT(m_impl);
|
||||||
|
ASSERT(start <= length());
|
||||||
|
return { characters() + start, length() - start };
|
||||||
|
}
|
||||||
|
|
||||||
String String::substring(size_t start, size_t length) const
|
String String::substring(size_t start, size_t length) const
|
||||||
{
|
{
|
||||||
if (!length)
|
if (!length)
|
||||||
|
|
|
@ -134,6 +134,7 @@ public:
|
||||||
|
|
||||||
Vector<String> split_limit(char separator, size_t limit, bool keep_empty = false) const;
|
Vector<String> split_limit(char separator, size_t limit, bool keep_empty = false) const;
|
||||||
Vector<String> split(char separator, bool keep_empty = false) const;
|
Vector<String> split(char separator, bool keep_empty = false) const;
|
||||||
|
String substring(size_t start) const;
|
||||||
String substring(size_t start, size_t length) const;
|
String substring(size_t start, size_t length) const;
|
||||||
|
|
||||||
Vector<StringView> split_view(char separator, bool keep_empty = false) const;
|
Vector<StringView> split_view(char separator, bool keep_empty = false) const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue