summaryrefslogtreecommitdiff
path: root/include/fud_string_view.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/fud_string_view.hpp')
-rw-r--r--include/fud_string_view.hpp34
1 files changed, 25 insertions, 9 deletions
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 <string_view>
@@ -31,6 +31,7 @@ class String;
struct StringView {
template <size_t N>
+ // 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 <size_t N>
- StringView(const char (&input)[N]) : m_length{N - 1}, m_data{reinterpret_cast<const utf8*>(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<const utf8*>(input)}
{
static_assert(N > 0);
}
StringView(size_t strLen, const char* strData) :
- m_length(strLen), // line break
- m_data{reinterpret_cast<const utf8*>(strData)} // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
+ m_length(strLen),
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
+ m_data{reinterpret_cast<const utf8*>(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 <size_t N>
+ // 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<const utf8*>(input)};
}
+ [[nodiscard]] constexpr Span<const utf8> asSpan() const
+ {
+ return Span<const utf8>{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<const char*>(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;
}