1 #ifndef ZSERIO_STRING_VIEW_H_INC
2 #define ZSERIO_STRING_VIEW_H_INC
22 template <
typename CharT,
typename Traits = std::
char_traits<CharT>>
56 m_size(Traits::
length(str))
75 template <
typename ALLOC>
76 constexpr
BasicStringView(
const std::basic_string<CharT, Traits, ALLOC>& str) noexcept :
123 return m_data + m_size;
200 << pos <<
" out of range for view size " <<
size() <<
"!";
222 return m_data[m_size - 1];
262 return std::numeric_limits<size_type>::max();
270 constexpr
bool empty() const noexcept
303 std::swap(m_data, other.m_data);
304 std::swap(m_size, other.m_size);
322 << pos <<
" out of range for view size " <<
size() <<
"!";
324 const size_t rcount = std::min(count,
size() - pos);
325 Traits::copy(dest,
data() + pos, rcount);
343 << pos <<
" out of range for view size " <<
size() <<
"!";
345 const size_t rcount = std::min(count,
size() - pos);
359 const int cmp = Traits::compare(
data(), other.data(), rlen);
366 if (
size() < other.size())
370 else if (
size() > other.size())
474 const_pointer ptr = Traits::find(startPtr,
static_cast<size_t>(endPtr - startPtr), str[0]);
478 if (Traits::compare(ptr, str.
data(), str.
size()) == 0)
480 return static_cast<size_t>(ptr -
data());
484 ptr = Traits::find(ptr + 1,
static_cast<size_t>(endPtr - ptr - 1), str[0]);
536 if (str.size() >
size())
541 for (
size_t p = std::min(
static_cast<size_type>(
size() - str.size()), pos) + 1; p > 0; --p)
543 if (Traits::compare(
data() + p - 1, str.data(), str.size()) == 0)
597 if (str.
size() == 0 || pos >=
size())
604 if (Traits::find(str.
data(), str.
size(),
data()[idx]) !=
nullptr)
659 if (str.empty() ||
empty())
664 for (
size_type idx = std::min(pos + 1,
size()); idx > 0; --idx)
666 if (Traits::find(str.data(), str.size(),
data()[idx - 1]) !=
nullptr)
721 if (str.
size() == 0 || pos >=
size())
728 if (Traits::find(str.
data(), str.
size(),
data()[idx]) ==
nullptr)
783 if (str.empty() ||
empty())
788 for (
size_type idx = std::min(pos + 1,
size()); idx > 0; --idx)
790 if (Traits::find(str.data(), str.size(),
data()[idx - 1]) ==
nullptr)
841 template <
typename CharT,
class Traits>
851 template <
typename CharT,
class Traits>
854 return lhs.compare(rhs) == 0;
864 template <
typename CharT,
class Traits>
867 return lhs.compare(rhs) != 0;
877 template <
typename CharT,
class Traits>
880 return lhs.compare(rhs) < 0;
890 template <
typename CharT,
class Traits>
893 return lhs.compare(rhs) <= 0;
903 template <
typename CharT,
class Traits>
906 return lhs.compare(rhs) > 0;
916 template <
typename CharT,
class Traits>
919 return lhs.compare(rhs) >= 0;
928 template <
typename CharT,
size_t N>
931 static_assert(N != 0,
"Zero length arrays C++ extension is not supported!");
943 template <
typename CharT,
typename Traits,
typename ALLOC = std::allocator<
char>>
947 return std::basic_string<CharT, Traits, RebindAlloc<ALLOC, CharT>>(
948 stringView.
data(), stringView.
size(), allocator);
958 template <
typename CharT,
typename Traits,
typename ALLOC = std::allocator<
char>>
962 return first.append(second.
data(), second.
size());
976 template <
typename ALLOC>
996 inline namespace literals
ptrdiff_t difference_type
size_type rfind(const CharT *str, size_type pos=npos) const
static constexpr const size_type npos
size_type find_last_of(BasicStringView str, size_type pos=npos) const noexcept
size_type rfind(BasicStringView str, size_type pos=npos) const noexcept
constexpr const_reverse_iterator rend() const noexcept
constexpr BasicStringView(const const_pointer str, const size_type count) noexcept
constexpr const_reverse_iterator crbegin() const noexcept
size_type find_last_of(const CharT *str, size_type pos, size_type count) const
constexpr const_reference front() const noexcept
constexpr size_type max_size() const noexcept
constexpr const_iterator cbegin() const noexcept
const CharT & const_reference
void remove_suffix(size_type n)
size_type rfind(const CharT *str, size_type pos, size_type count) const
BasicStringView(BasicStringView &&) noexcept=default
const CharT * const_pointer
constexpr const_reverse_iterator crend() const noexcept
size_type rfind(CharT character, size_type pos=npos) const noexcept
int compare(const CharT *str) const
size_type find(const CharT *str, size_type pos=0) const
size_type find(BasicStringView str, size_type pos=0) const noexcept
int compare(size_type pos1, size_type count1, BasicStringView other, size_type pos2, size_type count2) const
size_type find(CharT character, size_type pos=0) const noexcept
constexpr BasicStringView(const std::basic_string< CharT, Traits, ALLOC > &str) noexcept
constexpr BasicStringView() noexcept=default
size_type find_first_not_of(const CharT *str, size_type pos=0) const
constexpr const_iterator cend() const noexcept
const_pointer const_iterator
BasicStringView substr(size_type pos=0, size_type count=npos) const
constexpr const_reference operator[](const size_type pos) const noexcept
const_reverse_iterator reverse_iterator
BasicStringView(const BasicStringView &) noexcept=default
size_type find_last_of(CharT character, size_type pos=npos) const noexcept
constexpr const_iterator end() const noexcept
int compare(BasicStringView other) const noexcept
void swap(BasicStringView &other) noexcept
size_type find_last_of(const CharT *str, size_type pos=npos) const
size_type find_first_of(const CharT *str, size_type pos=0) const
std::reverse_iterator< const_iterator > const_reverse_iterator
constexpr size_type size() const noexcept
size_type find_last_not_of(BasicStringView str, size_type pos=npos) const noexcept
constexpr size_type length() const noexcept
int compare(size_type pos1, size_type count1, BasicStringView other) const
size_type copy(CharT *dest, size_type count, size_type pos=0) const
constexpr const_iterator begin() const noexcept
constexpr bool empty() const noexcept
constexpr const_reference back() const noexcept
size_type find_first_of(const CharT *str, size_type pos, size_type count) const
size_type find_first_not_of(BasicStringView str, size_type pos=0) const noexcept
size_type find(const CharT *str, size_type pos, size_type count) const
size_type find_last_not_of(const CharT *str, size_type pos=npos) const
int compare(size_type pos1, size_type count1, const CharT *str, size_type count2) const
constexpr const_pointer data() const noexcept
size_type find_first_not_of(CharT character, size_type pos=0) const noexcept
~BasicStringView()=default
int compare(size_type pos1, size_type count1, const CharT *str) const
size_type find_last_not_of(CharT character, size_type pos=npos) const noexcept
size_type find_first_not_of(const CharT *str, size_type pos, size_type count) const
BasicStringView & operator=(const BasicStringView &) noexcept=default
size_type find_last_not_of(const CharT *str, size_type pos, size_type count) const
constexpr const_reverse_iterator rbegin() const noexcept
void remove_prefix(size_type n)
size_type find_first_of(BasicStringView str, size_type pos=0) const noexcept
const_reference at(const size_type pos) const
size_type find_first_of(CharT character, size_type pos=0) const noexcept
void append(const char *message)
constexpr bool operator!=(BasicStringView< CharT, Traits > lhs, BasicStringView< CharT, Traits > rhs) noexcept
constexpr bool operator>=(BasicStringView< CharT, Traits > lhs, BasicStringView< CharT, Traits > rhs) noexcept
constexpr bool operator>(BasicStringView< CharT, Traits > lhs, BasicStringView< CharT, Traits > rhs) noexcept
std::basic_string< CharT, Traits, ALLOC > & operator+=(std::basic_string< CharT, Traits, ALLOC > &first, BasicStringView< CharT, Traits > second)
constexpr bool operator<(BasicStringView< CharT, Traits > lhs, BasicStringView< CharT, Traits > rhs) noexcept
BasicStringView< char, std::char_traits< char > > StringView
std::basic_string< char, std::char_traits< char >, RebindAlloc< ALLOC, char > > string
CppRuntimeException & operator<<(CppRuntimeException &exception, const BasicBitBuffer< ALLOC > &bitBuffer)
constexpr BasicStringView< CharT > makeStringView(const CharT(&str)[N])
constexpr bool operator==(BasicStringView< CharT, Traits > lhs, BasicStringView< CharT, Traits > rhs) noexcept
string< ALLOC > toString(T value, const ALLOC &allocator=ALLOC())
std::basic_string< CharT, Traits, RebindAlloc< ALLOC, CharT > > stringViewToString(BasicStringView< CharT, Traits > stringView, const ALLOC &allocator=ALLOC())
constexpr bool operator<=(BasicStringView< CharT, Traits > lhs, BasicStringView< CharT, Traits > rhs) noexcept