From fead91cfb1835d16049c615e1f1c87caa606ff06 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 26 Aug 2024 12:29:59 +0200 Subject: Merging upstream version 1.9.6. Signed-off-by: Daniel Baumann --- views.hh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'views.hh') diff --git a/views.hh b/views.hh index c3c8c89..b6be930 100644 --- a/views.hh +++ b/views.hh @@ -33,21 +33,39 @@ public: view(data_, size_) { } - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): No unsigned char view in C++17 + // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast): No unsigned char view in C++17 UnsignedCharView(const unsigned char* data_, size_t size_) : view(reinterpret_cast(data_), size_) { } - const unsigned char& at(std::string_view::size_type pos) const + using size_type = std::string_view::size_type; + + [[nodiscard]] const unsigned char& at(size_type pos) const { return reinterpret_cast(view.at(pos)); } - size_t size() const + [[nodiscard]] const unsigned char& operator[](size_type pos) const + { + return reinterpret_cast(view[pos]); + } + + [[nodiscard]] const unsigned char* data() const + { + return reinterpret_cast(view.data()); + } + // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast): No unsigned char view in C++17 + + [[nodiscard]] size_t size() const { return view.size(); } + [[nodiscard]] size_t length() const + { + return view.length(); + } + private: std::string_view view; }; -- cgit v1.2.3