AWS IoT Device SDK C++ v2
1.34.0
AWS IoT Device SDK C++ v2
|
Go to the documentation of this file.
17 #include <type_traits>
19 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
20 # include <string_view>
32 template <
typename CharT,
typename Traits = std::
char_traits<CharT>>
class basic_string_view
56 constexpr
basic_string_view(
const CharT *s) noexcept : m_size{traits_type::length(s)}, m_data{s} {}
62 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
63 constexpr
basic_string_view(
const std::basic_string_view<CharT, Traits> &other) noexcept
64 : m_size(other.size()), m_data(other.data())
70 m_data = other->data();
71 m_size = other->size();
97 constexpr
size_type max_size() const noexcept {
return (std::numeric_limits<size_type>::max)(); }
99 constexpr
bool empty() const noexcept {
return this->m_size == 0; }
105 assert(pos < m_size);
106 return *(this->m_data + pos);
111 assert(pos < m_size);
112 return *(this->m_data + pos);
118 return *this->m_data;
124 return *(this->m_data + this->m_size - 1);
132 assert(this->m_size >= n);
149 assert(pos <=
size());
150 const size_type copyLen = (std::min)(n, m_size - pos);
151 traits_type::copy(s,
data() + pos, copyLen);
157 assert(pos <=
size());
158 const size_type copyLen = (std::min)(n, m_size - pos);
164 const size_type compareLen = (std::min)(this->m_size, s.m_size);
165 int ret = traits_type::compare(this->m_data, s.m_data, compareLen);
168 ret = _s_compare(this->m_size, s.m_size);
202 return this->
substr(0, other.size()) == other;
207 return !this->
empty() && traits_type::eq(this->
front(), c);
217 return this->m_size >= other.m_size && this->
compare(this->m_size - other.m_size,
npos, other) == 0;
222 return !this->
empty() && traits_type::eq(this->
back(), c);
230 return this->
find(s.m_data, pos, s.m_size);
239 const CharT *r = Traits::find(m_data + pos, m_size - pos, c);
244 return static_cast<size_type>(r - m_data);
264 const CharT *r = _s_search_substr(m_data + pos, m_data + m_size, s, s + n);
266 if (r == m_data + m_size)
270 return static_cast<size_type>(r - m_data);
275 return this->
find(s, pos, traits_type::length(s));
280 if (s.m_size && !s.m_data)
284 return this->
rfind(s.m_data, pos, s.m_size);
303 for (
const CharT *ptr = m_data + pos; ptr != m_data;)
305 if (Traits::eq(*--ptr, c))
307 return static_cast<size_type>(ptr - m_data);
320 pos = (std::min)(pos, m_size);
321 if (n < m_size - pos)
329 const CharT *r = _s_find_end(m_data, m_data + pos, s, s + n);
330 if (n > 0 && r == m_data + pos)
334 return static_cast<size_type>(r - m_data);
339 return this->
rfind(s, pos, traits_type::length(s));
351 if (pos >= m_size || !n || !s)
356 const CharT *r = _s_find_first_of_ce(m_data + pos, m_data + m_size, s, s + n);
358 if (r == m_data + m_size)
363 return static_cast<size_type>(r - m_data);
378 return this->
rfind(c, pos);
383 if (!n || s ==
nullptr)
397 for (
const CharT *ptr = m_data + pos; ptr != m_data;)
399 const CharT *r = Traits::find(s, n, *--ptr);
402 return static_cast<size_type>(ptr - m_data);
411 return this->
find_last_of(s, pos, traits_type::length(s));
416 if (s.m_size && !s.m_data)
425 if (!m_data || pos >= m_size)
430 const CharT *pend = m_data + m_size;
431 for (
const CharT *ptr = m_data + pos; ptr != pend; ++ptr)
433 if (!Traits::eq(*ptr, c))
435 return static_cast<size_type>(ptr - m_data);
444 if (n && s ==
nullptr)
449 if (m_data ==
nullptr || pos >= m_size)
454 const CharT *pend = m_data + m_size;
455 for (
const CharT *ptr = m_data + pos; ptr != pend; ++ptr)
457 if (Traits::find(s, n, *ptr) == 0)
459 return static_cast<size_type>(ptr - m_data);
473 if (s.m_size && !s.m_data)
491 for (
const CharT *ptr = m_data + pos; ptr != m_data;)
493 if (!Traits::eq(*--ptr, c))
495 return static_cast<size_type>(ptr - m_data);
517 for (
const CharT *ptr = m_data + pos; ptr != m_data;)
519 if (Traits::find(s, n, *--ptr) == 0)
521 return static_cast<size_type>(ptr - m_data);
537 if (diff > (std::numeric_limits<int>::max)())
539 return (std::numeric_limits<int>::max)();
542 if (diff < (std::numeric_limits<int>::min)())
544 return (std::numeric_limits<int>::min)();
547 return static_cast<int>(diff);
550 static const CharT *_s_search_substr(
556 const ptrdiff_t length2 = last2 - first2;
562 ptrdiff_t length1 = last1 - first1;
563 if (length1 < length2)
570 length1 = last1 - first1;
571 if (length1 < length2)
576 first1 = Traits::find(first1, length1 - length2 + 1, *first2);
582 if (Traits::compare(first1, first2, length2) == 0)
591 static const CharT *_s_find_end(
597 const CharT *r = last1;
611 if (Traits::eq(*first1, *first2))
618 const CharT *m1 = first1;
619 const CharT *m2 = first2;
632 if (!Traits::eq(*m1, *m2))
641 static const CharT *_s_find_first_of_ce(
647 for (; first1 != last1; ++first1)
649 for (
const CharT *ptr = first2; ptr != last2; ++ptr)
651 if (Traits::eq(*first1, *ptr))
665 template <
class CharT,
class Traits>
670 return (lhs.size() != rhs.size()) ? false : lhs.
compare(rhs) == 0;
673 template <
class CharT,
class Traits>
678 return (lhs.size() != rhs.size()) ? false : lhs.
compare(rhs) == 0;
681 template <
class CharT,
class Traits>
686 return (lhs.size() != rhs.size()) ? false : lhs.
compare(rhs) == 0;
690 template <
class CharT,
class Traits>
695 return (lhs.size() != rhs.size()) ? true : lhs.
compare(rhs) != 0;
698 template <
class CharT,
class Traits>
703 return (lhs.size() != rhs.size()) ? true : lhs.
compare(rhs) != 0;
706 template <
class CharT,
class Traits>
711 return (lhs.size() != rhs.size()) ? true : lhs.
compare(rhs) != 0;
715 template <
class CharT,
class Traits>
723 template <
class CharT,
class Traits>
731 template <
class CharT,
class Traits>
740 template <
class CharT,
class Traits>
748 template <
class CharT,
class Traits>
756 template <
class CharT,
class Traits>
765 template <
class CharT,
class Traits>
773 template <
class CharT,
class Traits>
781 template <
class CharT,
class Traits>
790 template <
class CharT,
class Traits>
798 template <
class CharT,
class Traits>
806 template <
class CharT,
class Traits>
819 inline namespace literals
821 inline namespace string_view_literals
853 template <
class CharT,
class Traits>
struct hash<
Aws::Crt::basic_string_view<CharT, Traits>>
858 template <
class CharT,
class Traits>
859 size_t hash<Aws::Crt::basic_string_view<CharT, Traits>>::operator()(
862 auto str = std::basic_string<CharT, Traits>(val.data(), val.size());
863 return std::hash<std::basic_string<CharT, Traits>>{}(str);
constexpr size_type find_first_of(basic_string_view s, size_type pos=0) const noexcept
Definition: StringView.h:342
ptrdiff_t difference_type
Definition: StringView.h:47
constexpr bool operator>=(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:791
size_type find_last_not_of(const CharT *s, size_type pos, size_type n) const noexcept
Definition: StringView.h:501
const value_type * const_pointer
Definition: StringView.h:39
constexpr size_type find(const CharT *s, size_type pos=0) const noexcept
Definition: StringView.h:273
constexpr size_type find_last_of(const CharT *s, size_type pos=npos) const noexcept
Definition: StringView.h:409
basic_string_view< char32_t > u32string_view
Definition: StringView.h:816
const value_type & const_reference
Definition: StringView.h:41
constexpr bool ends_with(const CharT *s) const noexcept
Definition: StringView.h:225
size_type rfind(CharT c, size_type pos=npos) const noexcept
Definition: StringView.h:287
void remove_suffix(size_type n) noexcept
Definition: StringView.h:137
int compare(const basic_string_view &s) const noexcept
Definition: StringView.h:162
bool operator==(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:666
constexpr size_type find_last_not_of(const CharT *s, size_type pos=npos) const noexcept
Definition: StringView.h:527
static constexpr size_type npos
Definition: StringView.h:48
const_reference at(size_type pos) const
Definition: StringView.h:109
basic_string_view substr(size_type pos=0, size_type n=npos) const noexcept(false)
Definition: StringView.h:155
constexpr basic_string_view(const CharT *s, size_type count) noexcept
Definition: StringView.h:58
void remove_prefix(size_type n) noexcept
Definition: StringView.h:130
const_reference front() const noexcept
Definition: StringView.h:115
size_type find_first_not_of(basic_string_view s, size_type pos=0) const noexcept
Definition: StringView.h:414
constexpr bool ends_with(const basic_string_view &other) const noexcept
Definition: StringView.h:215
const_reference back() const noexcept
Definition: StringView.h:121
constexpr bool empty() const noexcept
Definition: StringView.h:99
constexpr bool operator>(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:741
Traits traits_type
Definition: StringView.h:36
basic_string_view< wchar_t > wstring_view
Definition: StringView.h:817
constexpr bool starts_with(const CharT *s) const noexcept
Definition: StringView.h:210
bool operator!=(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:691
size_type find_first_not_of(CharT c, size_type pos=0) const noexcept
Definition: StringView.h:423
constexpr bool starts_with(CharT c) const noexcept
Definition: StringView.h:205
size_type find_last_not_of(CharT c, size_type pos=npos) const noexcept
Definition: StringView.h:480
constexpr const_iterator cend() const noexcept
Definition: StringView.h:83
size_t size_type
Definition: StringView.h:46
constexpr size_type find_first_not_of(const CharT *s, size_type pos=0) const noexcept
Definition: StringView.h:466
constexpr bool starts_with(const basic_string_view &other) const noexcept
Definition: StringView.h:200
constexpr int compare(size_type pos1, size_type n1, const CharT *s) const
Definition: StringView.h:190
size_type find_first_not_of(const CharT *s, size_type pos, size_type n) const noexcept
Definition: StringView.h:442
constexpr int compare(size_type pos1, size_type n1, const basic_string_view &s, size_type pos2, size_type n2) const
Definition: StringView.h:178
constexpr const_pointer data() const noexcept
Definition: StringView.h:127
constexpr basic_string_view(const CharT *s) noexcept
Definition: StringView.h:56
constexpr size_type find(const basic_string_view &s, size_type pos=0) const noexcept
Definition: StringView.h:228
basic_string_view & operator=(const basic_string_view &) noexcept=default
size_type find_last_not_of(basic_string_view s, size_type pos=npos) const noexcept
Definition: StringView.h:471
constexpr basic_string_view(const basic_string_view &) noexcept=default
constexpr const_reverse_iterator rend() const noexcept
Definition: StringView.h:87
size_type rfind(basic_string_view s, size_type pos=npos) const noexcept
Definition: StringView.h:278
constexpr bool ends_with(CharT c) const noexcept
Definition: StringView.h:220
constexpr size_type find_first_of(const CharT *s, size_type pos=0) const noexcept
Definition: StringView.h:366
size_type find(const CharT *s, size_type pos, size_type n) const noexcept
Definition: StringView.h:247
basic_string_view< char16_t > u16string_view
Definition: StringView.h:815
constexpr const_reverse_iterator rbegin() const noexcept
Definition: StringView.h:85
Definition: StringView.h:33
constexpr size_type length() const noexcept
Definition: StringView.h:95
Definition: StringView.h:852
constexpr int compare(const CharT *s) const noexcept
Definition: StringView.h:188
constexpr int compare(size_type pos1, size_type n1, const CharT *s, size_type n2) const noexcept(false)
Definition: StringView.h:195
value_type & reference
Definition: StringView.h:40
bool operator<(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:716
size_type find(CharT c, size_type pos=0) const noexcept
Definition: StringView.h:233
Definition: Allocator.h:11
const_reference operator[](size_type pos) const noexcept
Definition: StringView.h:103
constexpr const_iterator begin() const noexcept
Definition: StringView.h:77
const_reverse_iterator reverse_iterator
Definition: StringView.h:45
basic_string_view< char > string_view
Definition: StringView.h:814
size_type find_last_of(const CharT *s, size_type pos, size_type n) const noexcept
Definition: StringView.h:381
constexpr basic_string_view() noexcept
Definition: StringView.h:52
constexpr int compare(size_type pos1, size_type n1, const basic_string_view &s) const
Definition: StringView.h:173
const_iterator iterator
Definition: StringView.h:43
constexpr size_type max_size() const noexcept
Definition: StringView.h:97
void swap(basic_string_view &other) noexcept
Definition: StringView.h:139
constexpr const_reverse_iterator crbegin() const noexcept
Definition: StringView.h:89
constexpr size_type find_first_of(CharT c, size_type pos=0) const noexcept
Definition: StringView.h:347
value_type * pointer
Definition: StringView.h:38
size_type find_first_of(const CharT *s, size_type pos, size_type n) const noexcept
Definition: StringView.h:349
constexpr const_iterator cbegin() const noexcept
Definition: StringView.h:81
const value_type * const_iterator
Definition: StringView.h:42
constexpr size_type rfind(const CharT *s, size_type pos=npos) const noexcept
Definition: StringView.h:337
constexpr size_type find_last_of(CharT c, size_type pos=npos) const noexcept
Definition: StringView.h:376
size_type rfind(const CharT *s, size_type pos, size_type n) const noexcept
Definition: StringView.h:313
CharT value_type
Definition: StringView.h:37
constexpr bool operator<=(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:766
constexpr size_type find_last_of(basic_string_view s, size_type pos=npos) const noexcept
Definition: StringView.h:371
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: StringView.h:44
constexpr size_type size() const noexcept
Definition: StringView.h:93
constexpr const_iterator end() const noexcept
Definition: StringView.h:79
size_type copy(CharT *s, size_type n, size_type pos=0) const
Definition: StringView.h:147
constexpr const_reverse_iterator crend() const noexcept
Definition: StringView.h:91