From d5a174a6d4f8be5e7cffe7c2adbb8db23b578f56 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Thu, 2 Jan 2025 18:49:56 -0600 Subject: Fixing errors in Vector. --- include/fud_string_view.hpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'include/fud_string_view.hpp') diff --git a/include/fud_string_view.hpp b/include/fud_string_view.hpp index 327bf20..c3bc0a1 100644 --- a/include/fud_string_view.hpp +++ b/include/fud_string_view.hpp @@ -18,10 +18,10 @@ #ifndef FUD_STRING_VIEW_HPP #define FUD_STRING_VIEW_HPP +#include "fud_assert.hpp" +#include "fud_config.hpp" #include "fud_status.hpp" #include "fud_utf8.hpp" -#include "fud_config.hpp" -#include "fud_assert.hpp" #include @@ -31,6 +31,7 @@ class String; struct StringView { template + // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) consteval StringView(const utf8 (&input)[N]) : m_length{N - 1}, m_data{input} { static_assert(N > 0); @@ -52,28 +53,42 @@ struct StringView { } template - StringView(const char (&input)[N]) : m_length{N - 1}, m_data{reinterpret_cast(input)} + // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) + StringView(const char (&input)[N]) : + m_length{N - 1}, + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + m_data{reinterpret_cast(input)} { static_assert(N > 0); } StringView(size_t strLen, const char* strData) : - m_length(strLen), // line break - m_data{reinterpret_cast(strData)} // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) + m_length(strLen), + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + m_data{reinterpret_cast(strData)} { } - StringView(std::string_view rhs) noexcept : StringView(rhs.length(), rhs.data()) {} + StringView(std::string_view rhs) noexcept : StringView(rhs.length(), rhs.data()) + { + } explicit StringView(const String& fudString) noexcept; template + // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) constexpr static StringView makeFromCString(const char (&input)[N]) { static_assert(N > 0); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) return StringView{N - 1, reinterpret_cast(input)}; } + [[nodiscard]] constexpr Span asSpan() const + { + return Span{m_data, m_length}; + } + [[nodiscard]] constexpr size_t length() const { return m_length; @@ -84,8 +99,9 @@ struct StringView { return m_data; } - [[nodiscard]] inline const char* c_str() const + [[nodiscard]] const char* c_str() const { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) return reinterpret_cast(m_data); } @@ -98,12 +114,12 @@ struct StringView { return m_data[index]; } - constexpr const utf8* begin() const noexcept + [[nodiscard]] constexpr const utf8* begin() const noexcept { return m_data; } - constexpr const utf8* end() const noexcept + [[nodiscard]] constexpr const utf8* end() const noexcept { return m_data + m_length; } -- cgit v1.2.3