AWS IoT Device SDK C++ v2
1.33.0
AWS IoT Device SDK C++ v2
|
Go to the documentation of this file.
16 #include <type_traits>
18 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
19 # include <string_view>
31 template <
typename CharT,
typename Traits = std::
char_traits<CharT>>
class basic_string_view
55 constexpr
basic_string_view(
const CharT *s) noexcept : m_size{traits_type::length(s)}, m_data{s} {}
61 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
62 constexpr
basic_string_view(
const std::basic_string_view<CharT, Traits> &other) noexcept
63 : m_size(other.size()), m_data(other.data())
69 m_data = other->data();
70 m_size = other->size();
96 constexpr
size_type max_size() const noexcept {
return (std::numeric_limits<size_type>::max)(); }
98 constexpr
bool empty() const noexcept {
return this->m_size == 0; }
104 assert(pos < m_size);
105 return *(this->m_data + pos);
110 assert(pos < m_size);
111 return *(this->m_data + pos);
117 return *this->m_data;
123 return *(this->m_data + this->m_size - 1);
131 assert(this->m_size >= n);
148 assert(pos <=
size());
149 const size_type copyLen = (std::min)(n, m_size - pos);
150 traits_type::copy(s,
data() + pos, copyLen);
156 assert(pos <=
size());
157 const size_type copyLen = (std::min)(n, m_size - pos);
163 const size_type compareLen = (std::min)(this->m_size, s.m_size);
164 int ret = traits_type::compare(this->m_data, s.m_data, compareLen);
167 ret = _s_compare(this->m_size, s.m_size);
201 return this->
substr(0, other.size()) == other;
206 return !this->
empty() && traits_type::eq(this->
front(), c);
216 return this->m_size >= other.m_size && this->
compare(this->m_size - other.m_size,
npos, other) == 0;
221 return !this->
empty() && traits_type::eq(this->
back(), c);
229 return this->
find(s.m_data, pos, s.m_size);
238 const CharT *r = Traits::find(m_data + pos, m_size - pos, c);
243 return static_cast<size_type>(r - m_data);
263 const CharT *r = _s_search_substr(m_data + pos, m_data + m_size, s, s + n);
265 if (r == m_data + m_size)
269 return static_cast<size_type>(r - m_data);
274 return this->
find(s, pos, traits_type::length(s));
279 if (s.m_size && !s.m_data)
283 return this->
rfind(s.m_data, pos, s.m_size);
302 for (
const CharT *ptr = m_data + pos; ptr != m_data;)
304 if (Traits::eq(*--ptr, c))
306 return static_cast<size_type>(ptr - m_data);
319 pos = (std::min)(pos, m_size);
320 if (n < m_size - pos)
328 const CharT *r = _s_find_end(m_data, m_data + pos, s, s + n);
329 if (n > 0 && r == m_data + pos)
333 return static_cast<size_type>(r - m_data);
338 return this->
rfind(s, pos, traits_type::length(s));
350 if (pos >= m_size || !n || !s)
355 const CharT *r = _s_find_first_of_ce(m_data + pos, m_data + m_size, s, s + n);
357 if (r == m_data + m_size)
362 return static_cast<size_type>(r - m_data);
377 return this->
rfind(c, pos);
382 if (!n || s ==
nullptr)
396 for (
const CharT *ptr = m_data + pos; ptr != m_data;)
398 const CharT *r = Traits::find(s, n, *--ptr);
401 return static_cast<size_type>(ptr - m_data);
410 return this->
find_last_of(s, pos, traits_type::length(s));
415 if (s.m_size && !s.m_data)
424 if (!m_data || pos >= m_size)
429 const CharT *pend = m_data + m_size;
430 for (
const CharT *ptr = m_data + pos; ptr != pend; ++ptr)
432 if (!Traits::eq(*ptr, c))
434 return static_cast<size_type>(ptr - m_data);
443 if (n && s ==
nullptr)
448 if (m_data ==
nullptr || pos >= m_size)
453 const CharT *pend = m_data + m_size;
454 for (
const CharT *ptr = m_data + pos; ptr != pend; ++ptr)
456 if (Traits::find(s, n, *ptr) == 0)
458 return static_cast<size_type>(ptr - m_data);
472 if (s.m_size && !s.m_data)
490 for (
const CharT *ptr = m_data + pos; ptr != m_data;)
492 if (!Traits::eq(*--ptr, c))
494 return static_cast<size_type>(ptr - m_data);
516 for (
const CharT *ptr = m_data + pos; ptr != m_data;)
518 if (Traits::find(s, n, *--ptr) == 0)
520 return static_cast<size_type>(ptr - m_data);
536 if (diff > (std::numeric_limits<int>::max)())
538 return (std::numeric_limits<int>::max)();
541 if (diff < (std::numeric_limits<int>::min)())
543 return (std::numeric_limits<int>::min)();
546 return static_cast<int>(diff);
549 static const CharT *_s_search_substr(
555 const ptrdiff_t length2 = last2 - first2;
561 ptrdiff_t length1 = last1 - first1;
562 if (length1 < length2)
569 length1 = last1 - first1;
570 if (length1 < length2)
575 first1 = Traits::find(first1, length1 - length2 + 1, *first2);
581 if (Traits::compare(first1, first2, length2) == 0)
590 static const CharT *_s_find_end(
596 const CharT *r = last1;
610 if (Traits::eq(*first1, *first2))
617 const CharT *m1 = first1;
618 const CharT *m2 = first2;
631 if (!Traits::eq(*m1, *m2))
640 static const CharT *_s_find_first_of_ce(
646 for (; first1 != last1; ++first1)
648 for (
const CharT *ptr = first2; ptr != last2; ++ptr)
650 if (Traits::eq(*first1, *ptr))
664 template <
class CharT,
class Traits>
669 return (lhs.size() != rhs.size()) ? false : lhs.
compare(rhs) == 0;
672 template <
class CharT,
class Traits>
677 return (lhs.size() != rhs.size()) ? false : lhs.
compare(rhs) == 0;
680 template <
class CharT,
class Traits>
685 return (lhs.size() != rhs.size()) ? false : lhs.
compare(rhs) == 0;
689 template <
class CharT,
class Traits>
694 return (lhs.size() != rhs.size()) ? true : lhs.
compare(rhs) != 0;
697 template <
class CharT,
class Traits>
702 return (lhs.size() != rhs.size()) ? true : lhs.
compare(rhs) != 0;
705 template <
class CharT,
class Traits>
710 return (lhs.size() != rhs.size()) ? true : lhs.
compare(rhs) != 0;
714 template <
class CharT,
class Traits>
722 template <
class CharT,
class Traits>
730 template <
class CharT,
class Traits>
739 template <
class CharT,
class Traits>
747 template <
class CharT,
class Traits>
755 template <
class CharT,
class Traits>
764 template <
class CharT,
class Traits>
772 template <
class CharT,
class Traits>
780 template <
class CharT,
class Traits>
789 template <
class CharT,
class Traits>
797 template <
class CharT,
class Traits>
805 template <
class CharT,
class Traits>
818 inline namespace literals
820 inline namespace string_view_literals
852 template <
class CharT,
class Traits>
struct hash<
Aws::Crt::basic_string_view<CharT, Traits>>
857 template <
class CharT,
class Traits>
858 size_t hash<Aws::Crt::basic_string_view<CharT, Traits>>::operator()(
861 auto str = std::basic_string<CharT, Traits>(val.data(), val.size());
862 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:341
ptrdiff_t difference_type
Definition: StringView.h:46
constexpr bool operator>=(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:790
size_type find_last_not_of(const CharT *s, size_type pos, size_type n) const noexcept
Definition: StringView.h:500
const value_type * const_pointer
Definition: StringView.h:38
constexpr size_type find(const CharT *s, size_type pos=0) const noexcept
Definition: StringView.h:272
constexpr size_type find_last_of(const CharT *s, size_type pos=npos) const noexcept
Definition: StringView.h:408
basic_string_view< char32_t > u32string_view
Definition: StringView.h:815
const value_type & const_reference
Definition: StringView.h:40
constexpr bool ends_with(const CharT *s) const noexcept
Definition: StringView.h:224
size_type rfind(CharT c, size_type pos=npos) const noexcept
Definition: StringView.h:286
void remove_suffix(size_type n) noexcept
Definition: StringView.h:136
int compare(const basic_string_view &s) const noexcept
Definition: StringView.h:161
bool operator==(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:665
constexpr size_type find_last_not_of(const CharT *s, size_type pos=npos) const noexcept
Definition: StringView.h:526
static constexpr size_type npos
Definition: StringView.h:47
const_reference at(size_type pos) const
Definition: StringView.h:108
basic_string_view substr(size_type pos=0, size_type n=npos) const noexcept(false)
Definition: StringView.h:154
constexpr basic_string_view(const CharT *s, size_type count) noexcept
Definition: StringView.h:57
void remove_prefix(size_type n) noexcept
Definition: StringView.h:129
const_reference front() const noexcept
Definition: StringView.h:114
size_type find_first_not_of(basic_string_view s, size_type pos=0) const noexcept
Definition: StringView.h:413
constexpr bool ends_with(const basic_string_view &other) const noexcept
Definition: StringView.h:214
const_reference back() const noexcept
Definition: StringView.h:120
constexpr bool empty() const noexcept
Definition: StringView.h:98
constexpr bool operator>(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:740
Traits traits_type
Definition: StringView.h:35
basic_string_view< wchar_t > wstring_view
Definition: StringView.h:816
constexpr bool starts_with(const CharT *s) const noexcept
Definition: StringView.h:209
bool operator!=(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:690
size_type find_first_not_of(CharT c, size_type pos=0) const noexcept
Definition: StringView.h:422
constexpr bool starts_with(CharT c) const noexcept
Definition: StringView.h:204
size_type find_last_not_of(CharT c, size_type pos=npos) const noexcept
Definition: StringView.h:479
constexpr const_iterator cend() const noexcept
Definition: StringView.h:82
size_t size_type
Definition: StringView.h:45
constexpr size_type find_first_not_of(const CharT *s, size_type pos=0) const noexcept
Definition: StringView.h:465
constexpr bool starts_with(const basic_string_view &other) const noexcept
Definition: StringView.h:199
constexpr int compare(size_type pos1, size_type n1, const CharT *s) const
Definition: StringView.h:189
size_type find_first_not_of(const CharT *s, size_type pos, size_type n) const noexcept
Definition: StringView.h:441
constexpr int compare(size_type pos1, size_type n1, const basic_string_view &s, size_type pos2, size_type n2) const
Definition: StringView.h:177
constexpr const_pointer data() const noexcept
Definition: StringView.h:126
constexpr basic_string_view(const CharT *s) noexcept
Definition: StringView.h:55
constexpr size_type find(const basic_string_view &s, size_type pos=0) const noexcept
Definition: StringView.h:227
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:470
constexpr basic_string_view(const basic_string_view &) noexcept=default
constexpr const_reverse_iterator rend() const noexcept
Definition: StringView.h:86
size_type rfind(basic_string_view s, size_type pos=npos) const noexcept
Definition: StringView.h:277
constexpr bool ends_with(CharT c) const noexcept
Definition: StringView.h:219
constexpr size_type find_first_of(const CharT *s, size_type pos=0) const noexcept
Definition: StringView.h:365
size_type find(const CharT *s, size_type pos, size_type n) const noexcept
Definition: StringView.h:246
basic_string_view< char16_t > u16string_view
Definition: StringView.h:814
constexpr const_reverse_iterator rbegin() const noexcept
Definition: StringView.h:84
Definition: StringView.h:32
constexpr size_type length() const noexcept
Definition: StringView.h:94
Definition: StringView.h:851
constexpr int compare(const CharT *s) const noexcept
Definition: StringView.h:187
constexpr int compare(size_type pos1, size_type n1, const CharT *s, size_type n2) const noexcept(false)
Definition: StringView.h:194
value_type & reference
Definition: StringView.h:39
bool operator<(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:715
size_type find(CharT c, size_type pos=0) const noexcept
Definition: StringView.h:232
Definition: Allocator.h:11
const_reference operator[](size_type pos) const noexcept
Definition: StringView.h:102
constexpr const_iterator begin() const noexcept
Definition: StringView.h:76
const_reverse_iterator reverse_iterator
Definition: StringView.h:44
basic_string_view< char > string_view
Definition: StringView.h:813
size_type find_last_of(const CharT *s, size_type pos, size_type n) const noexcept
Definition: StringView.h:380
constexpr basic_string_view() noexcept
Definition: StringView.h:51
constexpr int compare(size_type pos1, size_type n1, const basic_string_view &s) const
Definition: StringView.h:172
const_iterator iterator
Definition: StringView.h:42
constexpr size_type max_size() const noexcept
Definition: StringView.h:96
void swap(basic_string_view &other) noexcept
Definition: StringView.h:138
constexpr const_reverse_iterator crbegin() const noexcept
Definition: StringView.h:88
constexpr size_type find_first_of(CharT c, size_type pos=0) const noexcept
Definition: StringView.h:346
value_type * pointer
Definition: StringView.h:37
size_type find_first_of(const CharT *s, size_type pos, size_type n) const noexcept
Definition: StringView.h:348
constexpr const_iterator cbegin() const noexcept
Definition: StringView.h:80
const value_type * const_iterator
Definition: StringView.h:41
constexpr size_type rfind(const CharT *s, size_type pos=npos) const noexcept
Definition: StringView.h:336
constexpr size_type find_last_of(CharT c, size_type pos=npos) const noexcept
Definition: StringView.h:375
size_type rfind(const CharT *s, size_type pos, size_type n) const noexcept
Definition: StringView.h:312
CharT value_type
Definition: StringView.h:36
constexpr bool operator<=(const basic_string_view< CharT, Traits > &lhs, const basic_string_view< CharT, Traits > &rhs) noexcept
Definition: StringView.h:765
constexpr size_type find_last_of(basic_string_view s, size_type pos=npos) const noexcept
Definition: StringView.h:370
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: StringView.h:43
constexpr size_type size() const noexcept
Definition: StringView.h:92
constexpr const_iterator end() const noexcept
Definition: StringView.h:78
size_type copy(CharT *s, size_type n, size_type pos=0) const
Definition: StringView.h:146
constexpr const_reverse_iterator crend() const noexcept
Definition: StringView.h:90