mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:18:12 +00:00
AK: Add more StringView utilities for making substrings.
These two allow making a new substring view starting from, or starting after, an existing substring view. Also make use of one of them in the kernel.
This commit is contained in:
parent
3e326de8fa
commit
1a697f70db
3 changed files with 38 additions and 4 deletions
|
@ -40,6 +40,25 @@ public:
|
|||
Vector<StringView> split_view(char) const;
|
||||
unsigned to_uint(bool& ok) const;
|
||||
|
||||
// Create a new substring view of this string view, starting either at the beginning of
|
||||
// the given substring view, or after its end, and continuing until the end of this string
|
||||
// view (that is, for the remaining part of its length). For example,
|
||||
//
|
||||
// StringView str { "foobar" };
|
||||
// StringView substr = str.substring_view(1, 2); // "oo"
|
||||
// StringView substr_from = str.substring_view_starting_from_substring(subst); // "oobar"
|
||||
// StringView substr_after = str.substring_view_starting_after_substring(subst); // "bar"
|
||||
//
|
||||
// Note that this only works if the string view passed as an argument is indeed a substring
|
||||
// view of this string view, such as one created by substring_view() and split_view(). It
|
||||
// does not work for arbitrary strings; for example declaring substr in the example above as
|
||||
//
|
||||
// StringView substr { "oo" };
|
||||
//
|
||||
// would not work.
|
||||
StringView substring_view_starting_from_substring(const StringView& substring) const;
|
||||
StringView substring_view_starting_after_substring(const StringView& substring) const;
|
||||
|
||||
bool operator==(const char* cstring) const
|
||||
{
|
||||
if (is_null())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue