From d2bc399770980e4d00e4f888e3fd4817b8e4b19e Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 3 Jan 2024 00:14:01 +0200 Subject: [PATCH] BAN: Make StringView::split const and fix bug with empties --- BAN/BAN/StringView.cpp | 8 ++++---- BAN/include/BAN/StringView.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/BAN/BAN/StringView.cpp b/BAN/BAN/StringView.cpp index 1aaf07017..fe3069855 100644 --- a/BAN/BAN/StringView.cpp +++ b/BAN/BAN/StringView.cpp @@ -61,7 +61,7 @@ namespace BAN return result; } - ErrorOr> StringView::split(char delim, bool allow_empties) + ErrorOr> StringView::split(char delim, bool allow_empties) const { size_type count = 0; { @@ -92,12 +92,12 @@ namespace BAN start = i + 1; } } - if (start != m_size) + if (start < m_size || (start == m_size && allow_empties)) TRY(result.push_back(this->substring(start))); return result; } - ErrorOr> StringView::split(bool(*comp)(char), bool allow_empties) + ErrorOr> StringView::split(bool(*comp)(char), bool allow_empties) const { size_type count = 0; { @@ -128,7 +128,7 @@ namespace BAN start = i + 1; } } - if (start != m_size) + if (start < m_size || (start == m_size && allow_empties)) TRY(result.push_back(this->substring(start))); return result; } diff --git a/BAN/include/BAN/StringView.h b/BAN/include/BAN/StringView.h index d7c6080ab..68f61fbe4 100644 --- a/BAN/include/BAN/StringView.h +++ b/BAN/include/BAN/StringView.h @@ -30,8 +30,8 @@ namespace BAN StringView substring(size_type, size_type = -1) const; - ErrorOr> split(char, bool = false); - ErrorOr> split(bool(*comp)(char), bool = false); + ErrorOr> split(char, bool = false) const; + ErrorOr> split(bool(*comp)(char), bool = false) const; char back() const; char front() const;