AK: Avoid returning null StringViews instead of empty views

This was error-prone and most users were just checking the length anyway
This commit is contained in:
Gingeh 2024-11-05 21:53:58 +11:00 committed by Sam Atkins
parent a4b38dda56
commit 57ba720fb1
Notes: github-actions[bot] 2024-11-05 14:02:42 +00:00
2 changed files with 0 additions and 18 deletions

View file

@ -16,9 +16,6 @@ namespace AK {
// Consume a number of characters
StringView GenericLexer::consume(size_t count)
{
if (count == 0)
return {};
size_t start = m_index;
size_t length = min(count, m_input.length() - m_index);
m_index += length;
@ -29,9 +26,6 @@ StringView GenericLexer::consume(size_t count)
// Consume the rest of the input
StringView GenericLexer::consume_all()
{
if (is_eof())
return {};
auto rest = m_input.substring_view(m_index, m_input.length() - m_index);
m_index = m_input.length();
return rest;
@ -48,8 +42,6 @@ StringView GenericLexer::consume_line()
consume_specific('\r');
consume_specific('\n');
if (length == 0)
return {};
return m_input.substring_view(start, length);
}
@ -61,8 +53,6 @@ StringView GenericLexer::consume_until(char stop)
m_index++;
size_t length = m_index - start;
if (length == 0)
return {};
return m_input.substring_view(start, length);
}
@ -74,8 +64,6 @@ StringView GenericLexer::consume_until(char const* stop)
m_index++;
size_t length = m_index - start;
if (length == 0)
return {};
return m_input.substring_view(start, length);
}
@ -87,8 +75,6 @@ StringView GenericLexer::consume_until(StringView stop)
m_index++;
size_t length = m_index - start;
if (length == 0)
return {};
return m_input.substring_view(start, length);
}

View file

@ -184,8 +184,6 @@ public:
++m_index;
size_t length = m_index - start;
if (length == 0)
return {};
return m_input.substring_view(start, length);
}
@ -198,8 +196,6 @@ public:
++m_index;
size_t length = m_index - start;
if (length == 0)
return {};
return m_input.substring_view(start, length);
}