From 57ba720fb184ddf59fb09d3290e07cd425be450e Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Tue, 5 Nov 2024 21:53:58 +1100 Subject: [PATCH] AK: Avoid returning null StringViews instead of empty views This was error-prone and most users were just checking the length anyway --- AK/GenericLexer.cpp | 14 -------------- AK/GenericLexer.h | 4 ---- 2 files changed, 18 deletions(-) diff --git a/AK/GenericLexer.cpp b/AK/GenericLexer.cpp index 3df80d37444..669348d0adc 100644 --- a/AK/GenericLexer.cpp +++ b/AK/GenericLexer.cpp @@ -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); } diff --git a/AK/GenericLexer.h b/AK/GenericLexer.h index f6271b3eed3..3f189226fe2 100644 --- a/AK/GenericLexer.h +++ b/AK/GenericLexer.h @@ -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); }