37#if defined (ONIXS_ICEBOE_CXX17)
38# include <string_view>
44#if defined (ONIXS_ICEBOE_CXX17)
46using StrRef = std::basic_string_view<Char>;
62 typedef size_t size_type;
65 typedef const Char* const_iterator;
66 typedef const_iterator iterator;
67 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
68 typedef const_reverse_iterator reverse_iterator;
82 , size_((ONIXS_ICEBOE_ASSERT(
size <= (std::numeric_limits<size_type>::max)()),
static_cast<size_type
>(
size)))
87 StrRef(
const Char* chars) noexcept
93 constexpr size_type maxLen = (std::numeric_limits<UInt16>::max)();
95 size_ = numericCast<size_type>(strnlen(chars, maxLen));
97 assert(size_ < maxLen);
101 StrRef(
const std::string&
string)
102 : items_(string.c_str())
103 , size_(static_cast<size_type>(string.length()))
105 assert(
string.length() <= (std::numeric_limits<size_type>::max)());
110 constexpr bool empty() const noexcept
118 const Char* data() const noexcept
126 size_type
size() const noexcept
134 size_type length() const noexcept
141 const_iterator begin() const noexcept
149 const_iterator end() const noexcept
152 return (items_ + size_);
157 const_iterator cbegin() const noexcept
164 const_iterator cend() const noexcept
171 const_reverse_iterator rbegin() const noexcept
173 return const_reverse_iterator(end());
178 const_reverse_iterator rend() const noexcept
180 return const_reverse_iterator(begin());
185 const_reverse_iterator crbegin() const noexcept
192 const_reverse_iterator crend() const noexcept
199 const Char& operator [](size_type index)
const noexcept
201 assert(index < size_);
204 return items_[index];
209 const Char& at(size_type index)
const
214 return items_[index];
216 throwInvalidIndex(index, size_);
220 const Char& front() const noexcept
227 const Char& back() const noexcept
230 return (*
this)[size_ - 1];
234 void swap(StrRef& other)
noexcept
236 std::swap(items_, other.items_);
238 std::swap(size_, other.size_);
242 operator std::basic_string<Char>()
const
244 return std::basic_string<Char>(data(),
size());
258bool operator ==(
const StrRef& left,
const StrRef& right)
260 if(left.size() != right.size())
265 assert(right.empty());
270 assert(right.data());
273 left.data(), right.data(), left.size()));
279bool operator !=(
const StrRef& left,
const StrRef& right)
281 return !(left == right);
287bool operator <(
const StrRef& left,
const StrRef& right)
294 left.size() < right.size()
301 : (left.size() < right.size()));
307bool operator >(
const StrRef& left,
const StrRef& right)
309 return (right < left);
314std::ostream& operator <<(std::ostream& stream,
const StrRef& text)
316 stream.write(text.data(), text.size());
327bool operator ==(
const StrRef& ref,
const std::string& str)
335bool operator !=(
const StrRef& ref,
const std::string& str)
343bool operator ==(
const std::string& str,
const StrRef& ref)
351bool operator !=(
const std::string& str,
const StrRef& ref)
359bool operator ==(
const StrRef& ref,
const Char* str)
367bool operator !=(
const StrRef& ref,
const Char* str)
375bool operator ==(
const Char* str,
const StrRef& ref)
383bool operator !=(
const Char* str,
const StrRef& ref)
410template <
size_t Size>
417 return StrRef(value, Size - 1);
420template <
size_t Size>
427 return StrRef(value, Size);
435 return std::string(ref.data(), ref.size());
442 str.append(ref.data(), ref.size());
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE_BEGIN
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE_END
#define ONIXS_ICEBOE_COLDPATH
#define ONIXS_ICEBOE_EXPORTED
#define ONIXS_ICEBOE_NODISCARD
constexpr StrRef constructStrRef(const char(&value)[Size]) noexcept
constexpr std::enable_if<!details::HasMemberTraits< Value >::value, size_t >::type size() noexcept
char Char
Character type alias.
std::string toStr(const FixedPointDecimal< Mantissa, Exponent > &)
Serializes a fixed-point decimal into a string.
std::basic_string_view< Char > StrRef
constexpr StrRef strRefFromCharArray(const char(&value)[Size]) noexcept
StrRef toStrRef(const std::string &str)
Constructs a StrRef instance over th std::string content.