18#ifndef AMINO_CORE_STRING_VIEW_H
19#define AMINO_CORE_STRING_VIEW_H
21#include "internal/ConfigMacros.h"
27#ifndef AMINO_REMOVE_TRANSITIVE_HEADERS
45 static inline constexpr bool is_raw_cstring =
46 (std::is_same_v<std::decay_t<R>,
char const*> ||
47 std::is_same_v<std::decay_t<R>,
char*>)&&
48 !std::is_array_v<std::remove_reference_t<R>>;
51 static inline constexpr bool is_sview_convertible_v =
52 !is_raw_cstring<R> && std::is_convertible_v<R, std::string_view>;
55 static inline constexpr bool is_sview_constructible_v =
56 !is_sview_convertible_v<R> &&
57 std::is_constructible_v<std::string_view, R>;
63 using enable_if_implicitly_constructible =
64 std::enable_if_t<is_sview_convertible_v<R>>;
67 using enable_if_explicitly_constructible =
68 std::enable_if_t<is_sview_constructible_v<R>>;
86 template <
typename R, enable_if_explicitly_constructible<R>* =
nullptr>
87 AMINO_INTERNAL_FORCEINLINE
constexpr explicit StringView(R&& r)
96 template <
typename R, enable_if_implicitly_constructible<R>* =
nullptr>
103 AMINO_INTERNAL_FORCEINLINE
constexpr operator std::string_view()
109 constexpr char const*
data() const noexcept {
return m_data; }
114 constexpr size_t size() const noexcept {
return m_size; }
120 constexpr bool empty() const noexcept {
return m_size == 0; }
124 constexpr char const*
cbegin() const noexcept {
return m_data; }
130 constexpr char const*
cend() const noexcept {
return m_data + m_size; }
131 constexpr char const*
end() const noexcept {
return cend(); }
136 constexpr char front() const noexcept {
return deref(0); }
140 constexpr char back() const noexcept {
return deref(m_size - 1); }
144 constexpr char operator[](
size_t idx)
const noexcept {
return deref(idx); }
149 return size() == o.size() && compare(o) == 0;
152 return compare(o) < 0;
155 return compare(o) > 0;
158 return !(*
this == o);
174 AMINO_INTERNAL_FORCEINLINE
constexpr StringView(
175 Private, std::string_view s) noexcept
179 constexpr char deref(
size_t idx)
const noexcept {
182 assert(idx < m_size);
194 constexpr int compare(
StringView o)
const noexcept {
195 size_t size = m_size < o.m_size ? m_size : o.m_size;
196 for (
size_t i = 0; i <
size; ++i) {
197 if (m_data[i] < o.m_data[i])
return -1;
198 if (m_data[i] > o.m_data[i])
return +1;
200 if (m_size < o.m_size)
return -1;
201 if (m_size > o.m_size)
return +1;
208 char const* m_data =
nullptr;
220namespace StringViewLiterals {
221constexpr StringLiteral operator""_asv(
char const* data,
size_t size);
227 char const*,
size_t);
236namespace StringViewLiterals {
String view class (similar to std::string_view).
constexpr bool operator<(StringView o) const noexcept
Comparison operators.
constexpr bool operator>=(StringView o) const noexcept
Comparison operators.
constexpr char const * data() const noexcept
Get the string view data.
constexpr bool empty() const noexcept
Returns whether the string view is empty or not.
constexpr bool operator<=(StringView o) const noexcept
Comparison operators.
constexpr char const * begin() const noexcept
Get an iterator to the beginning of the string view.
constexpr bool operator>(StringView o) const noexcept
Comparison operators.
constexpr char const * end() const noexcept
Get an iterator to the end of the string view.
constexpr char operator[](size_t idx) const noexcept
Get the character at the given index in the string view.
constexpr char const * cbegin() const noexcept
Get an iterator to the beginning of the string view.
AMINO_INTERNAL_FORCEINLINE constexpr StringView(R &&r)
StringView can be explicitly constructed from types from which std::string_view can explicitly be con...
constexpr bool operator!=(StringView o) const noexcept
Comparison operators.
constexpr char front() const noexcept
Get the first character in the string view.
constexpr size_t length() const noexcept
Get the size of the string view.
constexpr bool operator==(StringView o) const noexcept
Comparison operators.
constexpr size_t size() const noexcept
Get the size of the string view.
constexpr char const * cend() const noexcept
Get an iterator to the end of the string view.
constexpr StringView() noexcept=default
Default constructor (empty string view)
constexpr char back() const noexcept
Get the last character in the string view.