AK: Avoid returning null StringViews instead of empty views

This was error-prone and most users were just checking the length anyway

(cherry picked from commit 57ba720fb184ddf59fb09d3290e07cd425be450e)
This commit is contained in:
Gingeh 2024-11-05 21:53:58 +11:00 committed by Nico Weber
parent be681da6a7
commit a630c67a32
2 changed files with 0 additions and 18 deletions

View file

@ -19,9 +19,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;
@ -32,9 +29,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;
@ -51,8 +45,6 @@ StringView GenericLexer::consume_line()
consume_specific('\r');
consume_specific('\n');
if (length == 0)
return {};
return m_input.substring_view(start, length);
}
@ -64,8 +56,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);
}
@ -77,8 +67,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);
}
@ -90,8 +78,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

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