From 5122d27f8948f329d22ccce773c59e182e1a9f75 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 16 Jan 2023 18:56:51 +0200 Subject: [PATCH] BAN: Add Front() and Back() to StringView --- BAN/BAN/StringView.cpp | 12 ++++++++++++ BAN/include/BAN/StringView.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/BAN/BAN/StringView.cpp b/BAN/BAN/StringView.cpp index 4b311aab..4dd47636 100644 --- a/BAN/BAN/StringView.cpp +++ b/BAN/BAN/StringView.cpp @@ -104,6 +104,18 @@ namespace BAN return result; } + char StringView::Back() const + { + ASSERT(m_size > 0); + return m_data[m_size - 1]; + } + + char StringView::Front() const + { + ASSERT(m_size > 0); + return m_data[0]; + } + StringView::size_type StringView::Count(char ch) const { size_type result = 0; diff --git a/BAN/include/BAN/StringView.h b/BAN/include/BAN/StringView.h index a786c2a7..752581b0 100644 --- a/BAN/include/BAN/StringView.h +++ b/BAN/include/BAN/StringView.h @@ -27,6 +27,9 @@ namespace BAN [[nodiscard]] ErrorOr> Split(char, bool = false); [[nodiscard]] ErrorOr> Split(bool(*comp)(char), bool = false); + char Back() const; + char Front() const; + size_type Count(char) const; bool Empty() const;