mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 15:10:19 +00:00
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:
parent
a4b38dda56
commit
57ba720fb1
Notes:
github-actions[bot]
2024-11-05 14:02:42 +00:00
Author: https://github.com/Gingeh Commit: https://github.com/LadybirdBrowser/ladybird/commit/57ba720fb18 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2172 Reviewed-by: https://github.com/AtkinsSJ ✅
2 changed files with 0 additions and 18 deletions
|
@ -16,9 +16,6 @@ namespace AK {
|
||||||
// Consume a number of characters
|
// Consume a number of characters
|
||||||
StringView GenericLexer::consume(size_t count)
|
StringView GenericLexer::consume(size_t count)
|
||||||
{
|
{
|
||||||
if (count == 0)
|
|
||||||
return {};
|
|
||||||
|
|
||||||
size_t start = m_index;
|
size_t start = m_index;
|
||||||
size_t length = min(count, m_input.length() - m_index);
|
size_t length = min(count, m_input.length() - m_index);
|
||||||
m_index += length;
|
m_index += length;
|
||||||
|
@ -29,9 +26,6 @@ StringView GenericLexer::consume(size_t count)
|
||||||
// Consume the rest of the input
|
// Consume the rest of the input
|
||||||
StringView GenericLexer::consume_all()
|
StringView GenericLexer::consume_all()
|
||||||
{
|
{
|
||||||
if (is_eof())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
auto rest = m_input.substring_view(m_index, m_input.length() - m_index);
|
auto rest = m_input.substring_view(m_index, m_input.length() - m_index);
|
||||||
m_index = m_input.length();
|
m_index = m_input.length();
|
||||||
return rest;
|
return rest;
|
||||||
|
@ -48,8 +42,6 @@ StringView GenericLexer::consume_line()
|
||||||
consume_specific('\r');
|
consume_specific('\r');
|
||||||
consume_specific('\n');
|
consume_specific('\n');
|
||||||
|
|
||||||
if (length == 0)
|
|
||||||
return {};
|
|
||||||
return m_input.substring_view(start, length);
|
return m_input.substring_view(start, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +53,6 @@ StringView GenericLexer::consume_until(char stop)
|
||||||
m_index++;
|
m_index++;
|
||||||
size_t length = m_index - start;
|
size_t length = m_index - start;
|
||||||
|
|
||||||
if (length == 0)
|
|
||||||
return {};
|
|
||||||
return m_input.substring_view(start, length);
|
return m_input.substring_view(start, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,8 +64,6 @@ StringView GenericLexer::consume_until(char const* stop)
|
||||||
m_index++;
|
m_index++;
|
||||||
size_t length = m_index - start;
|
size_t length = m_index - start;
|
||||||
|
|
||||||
if (length == 0)
|
|
||||||
return {};
|
|
||||||
return m_input.substring_view(start, length);
|
return m_input.substring_view(start, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,8 +75,6 @@ StringView GenericLexer::consume_until(StringView stop)
|
||||||
m_index++;
|
m_index++;
|
||||||
size_t length = m_index - start;
|
size_t length = m_index - start;
|
||||||
|
|
||||||
if (length == 0)
|
|
||||||
return {};
|
|
||||||
return m_input.substring_view(start, length);
|
return m_input.substring_view(start, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -184,8 +184,6 @@ public:
|
||||||
++m_index;
|
++m_index;
|
||||||
size_t length = m_index - start;
|
size_t length = m_index - start;
|
||||||
|
|
||||||
if (length == 0)
|
|
||||||
return {};
|
|
||||||
return m_input.substring_view(start, length);
|
return m_input.substring_view(start, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,8 +196,6 @@ public:
|
||||||
++m_index;
|
++m_index;
|
||||||
size_t length = m_index - start;
|
size_t length = m_index - start;
|
||||||
|
|
||||||
if (length == 0)
|
|
||||||
return {};
|
|
||||||
return m_input.substring_view(start, length);
|
return m_input.substring_view(start, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue