37 #if defined (ONIXS_ILINK3_CXX17) 38 # include <string_view> 44 #if defined (ONIXS_ILINK3_CXX17) 46 using StrRef = std::basic_string_view<Char>;
55 void 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;
85 , size_((ONIXS_ILINK3_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);
104 StrRef(
const std::string&
string)
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];
212 const Char& at(size_type index)
const 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());
261 bool operator ==(
const StrRef& left,
const StrRef& right)
263 if(left.size() != right.size())
268 assert(right.empty());
273 assert(right.data());
276 left.data(), right.data(), left.size()));
282 bool operator !=(
const StrRef& left,
const StrRef& right)
284 return !(left == right);
290 bool operator <(
const StrRef& left,
const StrRef& right)
297 left.size() < right.size()
304 : (left.size() < right.size()));
310 bool operator >(
const StrRef& left,
const StrRef& right)
312 return (right < left);
319 stream.write(text.data(), text.size());
330 bool operator ==(const
StrRef& ref, const
std::
string& str)
338 bool operator !=(
const StrRef& ref,
const std::string& str)
346 bool operator ==(
const std::string& str,
const StrRef& ref)
354 bool operator !=(
const std::string& str,
const StrRef& ref)
362 bool operator ==(
const StrRef& ref,
const Char* str)
370 bool operator !=(
const StrRef& ref,
const Char* str)
378 bool operator ==(
const Char* str,
const StrRef& ref)
386 bool operator !=(
const Char* str,
const StrRef& ref)
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());
443 str.append(ref.data(), ref.size());
#define ONIXS_ILINK3_CONSTEXPR
#define ONIXS_ILINK3_NULLPTR
#define ONIXS_ILINK3_CONST_OR_CONSTEXPR
std::basic_string_view< Char > StrRef
char Char
Character type alias.
constexpr StrRef constructStrRef(const char(&value)[Size]) noexcept
#define ONIXS_ILINK3_NORETURN
StrRef toStrRef(const Char *cStr) noexcept
Initializes the instance from a zero-terminated/C-like string.
#define ONIXS_ILINK3_LTWT_CLASS
#define ONIXS_ILINK3_MESSAGING_NAMESPACE_END
#define ONIXS_ILINK3_EXPORTED
std::ostream & operator<<(std::ostream &o, SessionStateId::Enum state)
constexpr StrRef strRefFromCharArray(const char(&value)[Size]) noexcept
void toStr(std::string &str, const StrRef &ref)
Appends the text referenced by StrRef to the given std::string instance.
#define ONIXS_ILINK3_COLDPATH
#define ONIXS_ILINK3_MESSAGING_NAMESPACE_BEGIN
#define ONIXS_ILINK3_NODISCARD
#define ONIXS_ILINK3_NOTHROW