1 #ifndef ZSERIO_STRING_VIEW_H_INC 2 #define ZSERIO_STRING_VIEW_H_INC 22 template <
typename CharT,
typename Traits = std::
char_traits<CharT>>
55 m_data(str), m_size(Traits::
length(str))
65 m_data(str), m_size(count)
73 template<
typename ALLOC>
74 constexpr
BasicStringView(
const std::basic_string<CharT, Traits, ALLOC>& str) noexcept :
75 m_data(str.data()), m_size(str.size())
120 return m_data + m_size;
196 throw CppRuntimeException(
"StringView: Position ") << pos <<
" out of range for view size " 219 return m_data[m_size - 1];
259 return std::numeric_limits<size_type>::max();
267 constexpr
bool empty() const noexcept
300 std::swap(m_data, other.m_data);
301 std::swap(m_size, other.m_size);
318 throw CppRuntimeException(
"StringView: Position ") << pos <<
" out of range for view size " <<
321 const size_t rcount = std::min(count,
size() - pos);
322 Traits::copy(dest,
data() + pos, rcount);
339 throw CppRuntimeException(
"StringView: Position ") << pos <<
" out of range for view size " <<
342 const size_t rcount = std::min(count,
size() - pos);
356 const int cmp = Traits::compare(
data(), other.data(), rlen);
361 if (
size() < other.size())
363 else if (
size() > other.size())
459 const_pointer ptr = Traits::find(startPtr, static_cast<size_t>(endPtr - startPtr), str[0]);
463 if (Traits::compare(ptr, str.
data(), str.
size()) == 0)
465 return static_cast<size_t>(ptr -
data());
469 ptr = Traits::find(ptr + 1, static_cast<size_t>(endPtr - ptr - 1), str[0]);
524 for (
size_t p = std::min(static_cast<size_type>(
size() - str.
size()), pos) + 1; p > 0; --p)
526 if (Traits::compare(
data() + p - 1, str.
data(), str.
size()) == 0)
578 if (str.
size() == 0 || pos >=
size())
583 if (Traits::find(str.
data(), str.
size(),
data()[idx]) !=
nullptr)
639 for (
size_type idx = std::min(pos + 1,
size()); idx > 0; --idx)
641 if (Traits::find(str.
data(), str.
size(),
data()[idx - 1]) !=
nullptr)
694 if (str.
size() == 0 || pos >=
size())
699 if (Traits::find(str.
data(), str.
size(),
data()[idx]) ==
nullptr)
755 for (
size_type idx = std::min(pos + 1,
size()); idx > 0; --idx)
757 if (Traits::find(str.
data(), str.
size(),
data()[idx - 1]) ==
nullptr)
806 template<
typename CharT,
class Traits>
816 template<
typename CharT,
class Traits>
819 return lhs.compare(rhs) == 0;
829 template<
typename CharT,
class Traits>
832 return lhs.compare(rhs) != 0;
842 template<
typename CharT,
class Traits>
855 template<
typename CharT,
class Traits>
868 template<
typename CharT,
class Traits>
871 return lhs.compare(rhs) > 0;
881 template<
typename CharT,
class Traits>
884 return lhs.compare(rhs) >= 0;
893 template<
typename CharT,
size_t N>
896 static_assert(N != 0,
"Zero length arrays C++ extension is not supported!");
908 template<
typename CharT,
typename Traits,
typename ALLOC = std::allocator<
char>>
912 return std::basic_string<CharT, Traits, RebindAlloc<ALLOC, CharT>>(stringView.
data(), stringView.
size(),
923 template<
typename CharT,
typename Traits,
typename ALLOC = std::allocator<
char>>
927 return first.append(second.
data(), second.
size());
941 template <
typename ALLOC>
961 inline namespace literals
968 operator"" _sv(
const char* str, std::size_t len) noexcept
977 #endif // ZSERIO_STRING_VIEW_H_INC constexpr BasicStringView() noexcept=default
constexpr BasicStringView< CharT > makeStringView(const CharT(&str)[N])
void swap(BasicStringView &other) noexcept
constexpr size_type length() const noexcept
constexpr size_type size() const noexcept
size_type find_first_of(CharT ch, size_type pos=0) const noexcept
constexpr const_reverse_iterator rend() const noexcept
BasicStringView & operator=(const BasicStringView &) noexcept=default
constexpr const_iterator cend() const noexcept
void remove_prefix(size_type n)
size_type find_last_of(CharT ch, size_type pos=npos) const noexcept
size_type rfind(const CharT *str, size_type pos, size_type count) const
constexpr const_pointer data() const noexcept
constexpr const_reverse_iterator crbegin() const noexcept
std::basic_string< CharT, Traits, RebindAlloc< ALLOC, CharT > > stringViewToString(BasicStringView< CharT, Traits > stringView, const ALLOC &allocator=ALLOC())
const CharT & const_reference
size_type find_last_not_of(BasicStringView str, size_type pos=npos) const noexcept
size_type find(BasicStringView str, size_type pos=0) const noexcept
constexpr const_reference back() const noexcept
constexpr BasicStringView(const std::basic_string< CharT, Traits, ALLOC > &str) noexcept
string< ALLOC > toString(T value, const ALLOC &allocator=ALLOC())
size_type find_last_of(const CharT *str, size_type pos, size_type count) const
std::reverse_iterator< const_iterator > const_reverse_iterator
ptrdiff_t difference_type
int compare(BasicStringView other) const noexcept
constexpr const_reference operator[](const size_type pos) const noexcept
size_type find_first_of(BasicStringView str, size_type pos=0) const noexcept
size_type find_first_not_of(BasicStringView str, size_type pos=0) const noexcept
size_type find_last_not_of(const CharT *str, size_type pos, size_type count) const
size_type find_first_of(const CharT *str, size_type pos, size_type count) const
~BasicStringView()=default
size_type find(const CharT *str, size_type pos=0) const
std::basic_string< CharT, Traits, ALLOC > & operator+=(std::basic_string< CharT, Traits, ALLOC > &first, BasicStringView< CharT, Traits > second)
size_type rfind(BasicStringView str, size_type pos=npos) const noexcept
constexpr bool operator!=(BasicStringView< CharT, Traits > lhs, BasicStringView< CharT, Traits > rhs) noexcept
constexpr const_iterator end() const noexcept
const_pointer const_iterator
size_type rfind(CharT ch, size_type pos=npos) const noexcept
constexpr bool operator>(BasicStringView< CharT, Traits > lhs, BasicStringView< CharT, Traits > rhs) noexcept
int compare(size_type pos1, size_type count1, const CharT *str, size_type count2) const
constexpr bool operator==(BasicStringView< CharT, Traits > lhs, BasicStringView< CharT, Traits > rhs) noexcept
const_reference at(const size_type pos) const
size_type find_last_not_of(CharT ch, size_type pos=npos) const noexcept
size_type rfind(const CharT *str, size_type pos=npos) const
size_type find_first_not_of(CharT ch, size_type pos=0) const noexcept
size_type find_last_of(const CharT *str, size_type pos=npos) const
constexpr bool operator>=(BasicStringView< CharT, Traits > lhs, BasicStringView< CharT, Traits > rhs) noexcept
int compare(size_type pos1, size_type count1, BasicStringView other, size_type pos2, size_type count2) const
constexpr BasicStringView(const const_pointer str, const size_type count) noexcept
size_type find_last_not_of(const CharT *str, size_type pos=npos) const
constexpr const_reverse_iterator crend() const noexcept
const CharT * const_pointer
constexpr const_iterator cbegin() const noexcept
BasicStringView< char, std::char_traits< char >> StringView
size_type find_last_of(BasicStringView str, size_type pos=npos) const noexcept
BasicStringView substr(size_type pos=0, size_type count=npos) const
void append(const char *message)
static constexpr const size_type npos
constexpr const_iterator begin() const noexcept
const_reverse_iterator reverse_iterator
int compare(const CharT *str) const
std::basic_string< char, std::char_traits< char >, RebindAlloc< ALLOC, char >> string
constexpr const_reverse_iterator rbegin() const noexcept
void remove_suffix(size_type n)
constexpr const_reference front() const noexcept
constexpr bool empty() const noexcept
size_type find_first_not_of(const CharT *str, size_type pos, size_type count) const
size_type copy(CharT *dest, size_type count, size_type pos=0) const
size_type find(const CharT *str, size_type pos, size_type count) const
size_type find(CharT ch, size_type pos=0) const noexcept
size_type find_first_of(const CharT *str, size_type pos=0) const
int compare(size_type pos1, size_type count1, BasicStringView other) const
constexpr size_type max_size() const noexcept
size_type find_first_not_of(const CharT *str, size_type pos=0) const
CppRuntimeException & operator<<(CppRuntimeException &exception, const BasicBitBuffer< ALLOC > &bitBuffer)
int compare(size_type pos1, size_type count1, const CharT *str) const