38#if defined(ONIXS_CMEMDH_CXX17)
39# include <string_view>
44#if defined(ONIXS_CMEMDH_CXX17)
46using StrRef = std::basic_string_view<Char>;
55void throwInvalidIndex(
size_t,
size_t);
65 typedef size_t size_type;
68 typedef const Char* const_iterator;
69 typedef const_iterator iterator;
70 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
71 typedef const_reverse_iterator reverse_iterator;
81 constexpr StrRef(
const Char* chars,
size_t size) noexcept
83 , size_((ONIXS_CMEMDH_ASSERT(size <= (std::numeric_limits<size_type>::max)()),
static_cast<size_type
>(size)))
88 StrRef(
const Char* chars) noexcept
94 constexpr size_type maxLen = (std::numeric_limits<UInt16>::max)();
96 size_ = numericCast<size_type>(strnlen(chars, maxLen));
98 assert(size_ < maxLen);
102 StrRef(
const std::string&
string)
103 : items_(string.c_str())
104 , size_(static_cast<size_type>(string.length()))
106 assert(
string.length() <= (std::numeric_limits<size_type>::max)());
111 bool empty() const noexcept
118 constexpr const Char* data() const noexcept
125 constexpr size_type size() const noexcept
133 length() const noexcept
140 const_iterator begin() const noexcept
148 const_iterator end() const noexcept
151 return (items_ + size_);
156 const_iterator cbegin() const noexcept
163 const_iterator cend() const noexcept
170 const_reverse_iterator rbegin() const noexcept
172 return const_reverse_iterator(end());
177 const_reverse_iterator rend() const noexcept
179 return const_reverse_iterator(begin());
184 const_reverse_iterator crbegin() const noexcept
191 const_reverse_iterator crend() const noexcept
198 const Char& operator[](size_type index)
const noexcept
200 assert(index < size_);
203 return items_[index];
208 const Char& at(size_type index)
const
213 return items_[index];
215 throwInvalidIndex(index, size_);
219 const Char& front() const noexcept
226 const Char& back() const noexcept
229 return (*
this)[size_ - 1];
233 void swap(StrRef& other)
noexcept
235 std::swap(items_, other.items_);
237 std::swap(size_, other.size_);
241 operator std::basic_string<Char>()
const
243 return std::basic_string<Char>(data(), size());
256inline bool operator==(
const StrRef& left,
const StrRef& right)
258 if (left.size() != right.size())
263 assert(right.empty());
268 assert(right.data());
270 return (0 == memcmp(left.data(), right.data(), left.size()));
275inline bool operator!=(
const StrRef& left,
const StrRef& right)
277 return !(left == right);
282inline bool operator<(
const StrRef& left,
const StrRef& right)
284 const int result = memcmp(left.data(), right.data(), left.size() < right.size() ? left.size() : right.size());
286 return (0 != result ? (0 > result) : (left.size() < right.size()));
291inline bool operator>(
const StrRef& left,
const StrRef& right)
293 return (right < left);
297inline std::ostream&
operator<<(std::ostream& stream,
const StrRef& text)
299 stream.write(text.data(), text.size());
309inline bool operator==(
const StrRef& ref,
const std::string& str)
316inline bool operator!=(
const StrRef& ref,
const std::string& str)
323inline bool operator==(
const std::string& str,
const StrRef& ref)
330inline bool operator!=(
const std::string& str,
const StrRef& ref)
337inline bool operator==(
const StrRef& ref,
const Char* str)
344inline bool operator!=(
const StrRef& ref,
const Char* str)
351inline bool operator==(
const Char* str,
const StrRef& ref)
358inline bool operator!=(
const Char* str,
const StrRef& ref)
382 assert(begin <= end);
387template <
size_t Size>
391 return StrRef(value, Size - 1);
394template <
size_t Size>
397 return StrRef(value, Size);
404 return std::string(ref.data(), ref.size());
410 str.append(ref.data(), ref.size());
#define ONIXS_CMEMDH_MESSAGING_NAMESPACE_BEGIN
#define ONIXS_CMEMDH_MESSAGING_NAMESPACE_END
#define ONIXS_CMEMDH_COLDPATH
#define ONIXS_CMEMDH_EXPORTED
#define ONIXS_CMEMDH_NORETURN
#define ONIXS_CMEMDH_NODISCARD
constexpr StrRef constructStrRef(const char(&value)[Size]) noexcept
bool operator!=(const TimeSpan &left, const TimeSpan &right) noexcept
Compares Timespans.
char Char
Character type alias.
bool operator==(const TimeSpan &left, const TimeSpan &right) noexcept
Compares Timespans.
bool operator<(const TimeSpan &left, const TimeSpan &right) noexcept
Compares Timespans.
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.
bool operator>(const TimeSpan &left, const TimeSpan &right) noexcept
Compares Timespans.
void toStr(std::string &, Int8)
Serializes given integer into a string.
std::ostream & operator<<(std::ostream &os, const Timestamp &value)