Skip to content

Commit

Permalink
AK: Avoid returning null StringViews instead of empty views
Browse files Browse the repository at this point in the history
This was error-prone and most users were just checking the length anyway

(cherry picked from commit 57ba720fb184ddf59fb09d3290e07cd425be450e)
  • Loading branch information
Gingeh authored and nico committed Nov 25, 2024
1 parent 9c39630 commit 1e71255
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 18 deletions.
14 changes: 0 additions & 14 deletions AK/GenericLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
4 changes: 0 additions & 4 deletions AK/GenericLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ class GenericLexer {
++m_index;
size_t length = m_index - start;

if (length == 0)
return {};
return m_input.substring_view(start, length);
}

Expand All @@ -204,8 +202,6 @@ class GenericLexer {
++m_index;
size_t length = m_index - start;

if (length == 0)
return {};
return m_input.substring_view(start, length);
}

Expand Down

0 comments on commit 1e71255

Please sign in to comment.