From b1869bced4e894184d129bd919ef04cf96284367 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 25 Jun 2024 09:40:37 +0300 Subject: [PATCH] BAN: Implement StringView::starts_with() --- BAN/include/BAN/StringView.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/BAN/include/BAN/StringView.h b/BAN/include/BAN/StringView.h index 1b6486ef..1612ec30 100644 --- a/BAN/include/BAN/StringView.h +++ b/BAN/include/BAN/StringView.h @@ -165,6 +165,21 @@ namespace BAN return {}; } + constexpr bool starts_with(BAN::StringView target) const + { + if (target.size() > m_size) + return false; + for (size_type i = 0; i < m_size - target.size(); i++) + { + bool valid = true; + for (size_type j = 0; j < target.size() && valid; j++) + valid = (m_data[i + j] == target[j]); + if (valid) + return true; + } + return false; + } + constexpr bool contains(char ch) const { for (size_type i = 0; i < m_size; i++)