mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 15:25:07 +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
|
@ -42,6 +42,24 @@ StringView StringView::substring_view(int start, int length) const
|
|||
return { m_characters + start, length };
|
||||
}
|
||||
|
||||
StringView StringView::substring_view_starting_from_substring(const StringView& substring) const
|
||||
{
|
||||
const char* remaining_characters = substring.characters();
|
||||
ASSERT(remaining_characters >= m_characters);
|
||||
ASSERT(remaining_characters <= m_characters + m_length);
|
||||
int remaining_length = m_length - (remaining_characters - m_characters);
|
||||
return { remaining_characters, remaining_length };
|
||||
}
|
||||
|
||||
StringView StringView::substring_view_starting_after_substring(const StringView& substring) const
|
||||
{
|
||||
const char* remaining_characters = substring.characters() + substring.length();
|
||||
ASSERT(remaining_characters >= m_characters);
|
||||
ASSERT(remaining_characters <= m_characters + m_length);
|
||||
int remaining_length = m_length - (remaining_characters - m_characters);
|
||||
return { remaining_characters, remaining_length };
|
||||
}
|
||||
|
||||
unsigned StringView::to_uint(bool& ok) const
|
||||
{
|
||||
unsigned value = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue