37 #if defined(ONIXS_CONFLATEDTCP_HAS_STRING_VIEW) 38 #include <string_view> 44 #if defined(ONIXS_CONFLATEDTCP_HAS_STRING_VIEW) 46 using StrRef = std::basic_string_view<Char>;
55 void throwInvalidIndex(
size_t,
size_t);
85 , size_((ONIXS_CONFLATEDTCP_ASSERT(size <= (
std::numeric_limits<size_type>::max)()), static_cast<size_type>(size)))
98 size_ = numericCast<size_type>(strnlen(chars, maxLen));
100 assert(size_ < maxLen);
105 : items_(string.c_str())
106 , size_(static_cast<size_type>(string.length()))
108 assert(
string.length() <= (std::numeric_limits<size_type>::max)());
155 return (items_ + size_);
176 return const_reverse_iterator(end());
183 return const_reverse_iterator(begin());
204 assert(index < size_);
207 return items_[index];
217 return items_[index];
219 throwInvalidIndex(index, size_);
233 return (*
this)[size_ - 1];
239 std::swap(items_, other.items_);
241 std::swap(size_, other.size_);
245 operator std::basic_string<Char>()
const 247 return std::basic_string<Char>(data(), size());
268 assert(right.
empty());
273 assert(right.
data());
284 return !(left == right);
312 return (right < left);
319 stream.write(text.
data(), text.
size());
411 template <
size_t Size>
418 return StrRef(value, Size - 1);
421 template <
size_t Size>
428 return StrRef(value, Size);
436 return std::string(ref.
data(), ref.
size());
const Char & front() const noexcept
std::reverse_iterator< const_iterator > const_reverse_iterator
bool operator>(const StrRef &left, const StrRef &right)
Compares instances.
const_iterator cend() const noexcept
STL-like cend().
void swap(StrRef &other) noexcept
Swaps the content with the given instance.
constexpr size_type size() const noexcept
bool operator<(const StrRef &left, const StrRef &right)
Compares instances.
#define ONIXS_CONFLATEDTCP_MESSAGING_NAMESPACE_END
std::ostream & operator<<(std::ostream &stream, const StrRef &text)
StrRef serialization operator.
#define ONIXS_CONFLATEDTCP_NOTHROW
#define ONIXS_CONFLATEDTCP_EXPORTED
#define ONIXS_CONFLATEDTCP_CONST_OR_CONSTEXPR
constexpr size_type length() const noexcept
bool operator!=(const Char *str, const StrRef &ref)
Compares StrRef with a zero-terminated/C-like string.
constexpr StrRef strRefFromCharArray(const char(&value)[Size]) noexcept
const_reverse_iterator crbegin() const noexcept
STL-like crbegin().
#define ONIXS_CONFLATEDTCP_NORETURN
StrRef(const Char *chars) noexcept
Explicit initialization.
constexpr StrRef()
Initializes the instance referring to nothing.
#define ONIXS_CONFLATEDTCP_CONSTEXPR
const_reverse_iterator rend() const noexcept
STL-like rend().
StrRef toStrRef(const Char *) noexcept
Initializes the instance from a zero-terminated/C-like string.
const_reverse_iterator crend() const noexcept
STL-like crend().
#define ONIXS_CONFLATEDTCP_NODISCARD
constexpr StrRef constructStrRef(const char(&value)[Size]) noexcept
#define ONIXS_CONFLATEDTCP_COLDPATH
const_iterator end() const noexcept
STL-like end().
StrRef(const std::string &string)
Explicit initialization.
const_iterator cbegin() const noexcept
STL-like cbegin().
void toStr(std::string &str, const StrRef &ref)
Appends the text referenced by StrRef to the given std::string instance.
#define ONIXS_CONFLATEDTCP_LTWT_CLASS
#define ONIXS_CONFLATEDTCP_MESSAGING_NAMESPACE_BEGIN
constexpr const Char * data() const noexcept
const Char & back() const noexcept
const Char & at(size_type index) const
Provides the bound-checked per-item access.
const_reverse_iterator rbegin() const noexcept
STL-like rbegin().
const_iterator begin() const noexcept
STL-like begin().
#define ONIXS_CONFLATEDTCP_NULLPTR
const Char * const_iterator
STL-like iterators.
bool operator==(const Char *str, const StrRef &ref)
Compares StrRef with a zero-terminated/C-like string.
bool empty() const noexcept
char Char
Character type alias.
constexpr StrRef(const Char *chars, size_t size)
Explicit initialization.
const_reverse_iterator reverse_iterator