Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===------------------------ string_view ---------------------------------===// |
| 3 | // |
Chandler Carruth | 7642bb1 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_STRING_VIEW |
| 11 | #define _LIBCPP_STRING_VIEW |
| 12 | |
| 13 | /* |
| 14 | string_view synopsis |
| 15 | |
| 16 | namespace std { |
| 17 | |
| 18 | // 7.2, Class template basic_string_view |
| 19 | template<class charT, class traits = char_traits<charT>> |
| 20 | class basic_string_view; |
| 21 | |
Mark de Wever | af59b2d | 2020-11-24 18:08:02 +0100 | [diff] [blame] | 22 | template<class charT, class traits> |
| 23 | inline constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true; // C++20 |
| 24 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 25 | // 7.9, basic_string_view non-member comparison functions |
| 26 | template<class charT, class traits> |
| 27 | constexpr bool operator==(basic_string_view<charT, traits> x, |
| 28 | basic_string_view<charT, traits> y) noexcept; |
| 29 | template<class charT, class traits> |
| 30 | constexpr bool operator!=(basic_string_view<charT, traits> x, |
| 31 | basic_string_view<charT, traits> y) noexcept; |
| 32 | template<class charT, class traits> |
| 33 | constexpr bool operator< (basic_string_view<charT, traits> x, |
| 34 | basic_string_view<charT, traits> y) noexcept; |
| 35 | template<class charT, class traits> |
| 36 | constexpr bool operator> (basic_string_view<charT, traits> x, |
| 37 | basic_string_view<charT, traits> y) noexcept; |
| 38 | template<class charT, class traits> |
| 39 | constexpr bool operator<=(basic_string_view<charT, traits> x, |
| 40 | basic_string_view<charT, traits> y) noexcept; |
| 41 | template<class charT, class traits> |
| 42 | constexpr bool operator>=(basic_string_view<charT, traits> x, |
| 43 | basic_string_view<charT, traits> y) noexcept; |
| 44 | // see below, sufficient additional overloads of comparison functions |
| 45 | |
| 46 | // 7.10, Inserters and extractors |
| 47 | template<class charT, class traits> |
| 48 | basic_ostream<charT, traits>& |
| 49 | operator<<(basic_ostream<charT, traits>& os, |
| 50 | basic_string_view<charT, traits> str); |
| 51 | |
| 52 | // basic_string_view typedef names |
| 53 | typedef basic_string_view<char> string_view; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 54 | typedef basic_string_view<char8_t> u8string_view; // C++20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 55 | typedef basic_string_view<char16_t> u16string_view; |
| 56 | typedef basic_string_view<char32_t> u32string_view; |
| 57 | typedef basic_string_view<wchar_t> wstring_view; |
| 58 | |
| 59 | template<class charT, class traits = char_traits<charT>> |
| 60 | class basic_string_view { |
| 61 | public: |
| 62 | // types |
| 63 | typedef traits traits_type; |
| 64 | typedef charT value_type; |
| 65 | typedef charT* pointer; |
| 66 | typedef const charT* const_pointer; |
| 67 | typedef charT& reference; |
| 68 | typedef const charT& const_reference; |
| 69 | typedef implementation-defined const_iterator; |
| 70 | typedef const_iterator iterator; |
| 71 | typedef reverse_iterator<const_iterator> const_reverse_iterator; |
| 72 | typedef const_reverse_iterator reverse_iterator; |
| 73 | typedef size_t size_type; |
| 74 | typedef ptrdiff_t difference_type; |
| 75 | static constexpr size_type npos = size_type(-1); |
| 76 | |
| 77 | // 7.3, basic_string_view constructors and assignment operators |
| 78 | constexpr basic_string_view() noexcept; |
| 79 | constexpr basic_string_view(const basic_string_view&) noexcept = default; |
| 80 | basic_string_view& operator=(const basic_string_view&) noexcept = default; |
| 81 | template<class Allocator> |
| 82 | constexpr basic_string_view(const charT* str); |
| 83 | constexpr basic_string_view(const charT* str, size_type len); |
| 84 | |
| 85 | // 7.4, basic_string_view iterator support |
| 86 | constexpr const_iterator begin() const noexcept; |
| 87 | constexpr const_iterator end() const noexcept; |
| 88 | constexpr const_iterator cbegin() const noexcept; |
| 89 | constexpr const_iterator cend() const noexcept; |
| 90 | const_reverse_iterator rbegin() const noexcept; |
| 91 | const_reverse_iterator rend() const noexcept; |
| 92 | const_reverse_iterator crbegin() const noexcept; |
| 93 | const_reverse_iterator crend() const noexcept; |
| 94 | |
| 95 | // 7.5, basic_string_view capacity |
| 96 | constexpr size_type size() const noexcept; |
| 97 | constexpr size_type length() const noexcept; |
| 98 | constexpr size_type max_size() const noexcept; |
| 99 | constexpr bool empty() const noexcept; |
| 100 | |
| 101 | // 7.6, basic_string_view element access |
| 102 | constexpr const_reference operator[](size_type pos) const; |
| 103 | constexpr const_reference at(size_type pos) const; |
| 104 | constexpr const_reference front() const; |
| 105 | constexpr const_reference back() const; |
| 106 | constexpr const_pointer data() const noexcept; |
| 107 | |
| 108 | // 7.7, basic_string_view modifiers |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 109 | constexpr void remove_prefix(size_type n); |
| 110 | constexpr void remove_suffix(size_type n); |
| 111 | constexpr void swap(basic_string_view& s) noexcept; |
| 112 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 113 | size_type copy(charT* s, size_type n, size_type pos = 0) const; // constexpr in C++20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 114 | |
| 115 | constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const; |
| 116 | constexpr int compare(basic_string_view s) const noexcept; |
| 117 | constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const; |
| 118 | constexpr int compare(size_type pos1, size_type n1, |
| 119 | basic_string_view s, size_type pos2, size_type n2) const; |
| 120 | constexpr int compare(const charT* s) const; |
| 121 | constexpr int compare(size_type pos1, size_type n1, const charT* s) const; |
| 122 | constexpr int compare(size_type pos1, size_type n1, |
| 123 | const charT* s, size_type n2) const; |
| 124 | constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept; |
| 125 | constexpr size_type find(charT c, size_type pos = 0) const noexcept; |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 126 | constexpr size_type find(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension |
| 127 | constexpr size_type find(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 128 | constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept; |
| 129 | constexpr size_type rfind(charT c, size_type pos = npos) const noexcept; |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 130 | constexpr size_type rfind(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension |
| 131 | constexpr size_type rfind(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 132 | constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept; |
| 133 | constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept; |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 134 | constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension |
| 135 | constexpr size_type find_first_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 136 | constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept; |
| 137 | constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept; |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 138 | constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension |
| 139 | constexpr size_type find_last_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 140 | constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept; |
| 141 | constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept; |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 142 | constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension |
| 143 | constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 144 | constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept; |
| 145 | constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept; |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 146 | constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension |
| 147 | constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 148 | |
Marek Kurdej | 24b4c51 | 2021-01-07 12:29:04 +0100 | [diff] [blame] | 149 | constexpr bool starts_with(basic_string_view s) const noexcept; // C++20 |
| 150 | constexpr bool starts_with(charT c) const noexcept; // C++20 |
| 151 | constexpr bool starts_with(const charT* s) const; // C++20 |
| 152 | constexpr bool ends_with(basic_string_view s) const noexcept; // C++20 |
| 153 | constexpr bool ends_with(charT c) const noexcept; // C++20 |
| 154 | constexpr bool ends_with(const charT* s) const; // C++20 |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 155 | |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 156 | constexpr bool contains(basic_string_view s) const noexcept; // C++2b |
| 157 | constexpr bool contains(charT c) const noexcept; // C++2b |
| 158 | constexpr bool contains(const charT* s) const; // C++2b |
| 159 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 160 | private: |
| 161 | const_pointer data_; // exposition only |
| 162 | size_type size_; // exposition only |
| 163 | }; |
| 164 | |
| 165 | // 7.11, Hash support |
| 166 | template <class T> struct hash; |
| 167 | template <> struct hash<string_view>; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 168 | template <> struct hash<u8string_view>; // C++20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 169 | template <> struct hash<u16string_view>; |
| 170 | template <> struct hash<u32string_view>; |
| 171 | template <> struct hash<wstring_view>; |
| 172 | |
Marshall Clow | abe6daf | 2017-10-24 14:06:00 +0000 | [diff] [blame] | 173 | constexpr basic_string_view<char> operator "" sv( const char *str, size_t len ) noexcept; |
| 174 | constexpr basic_string_view<wchar_t> operator "" sv( const wchar_t *str, size_t len ) noexcept; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 175 | constexpr basic_string_view<char8_t> operator "" sv( const char8_t *str, size_t len ) noexcept; // C++20 |
Marshall Clow | abe6daf | 2017-10-24 14:06:00 +0000 | [diff] [blame] | 176 | constexpr basic_string_view<char16_t> operator "" sv( const char16_t *str, size_t len ) noexcept; |
| 177 | constexpr basic_string_view<char32_t> operator "" sv( const char32_t *str, size_t len ) noexcept; |
Marshall Clow | 27c8a4c | 2017-01-09 18:07:34 +0000 | [diff] [blame] | 178 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 179 | } // namespace std |
| 180 | |
| 181 | |
| 182 | */ |
| 183 | |
| 184 | #include <__config> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame^] | 185 | #include <__debug> |
Mark de Wever | af59b2d | 2020-11-24 18:08:02 +0100 | [diff] [blame] | 186 | #include <__ranges/enable_borrowed_range.h> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 187 | #include <__string> |
Eric Fiselier | 2d357f7 | 2016-12-05 23:53:23 +0000 | [diff] [blame] | 188 | #include <algorithm> |
Arthur O'Dwyer | 7deec12 | 2021-03-24 18:19:12 -0400 | [diff] [blame] | 189 | #include <compare> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame^] | 190 | #include <iosfwd> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 191 | #include <iterator> |
Eric Fiselier | 2d357f7 | 2016-12-05 23:53:23 +0000 | [diff] [blame] | 192 | #include <limits> |
| 193 | #include <stdexcept> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 194 | #include <version> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 195 | |
| 196 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 197 | #pragma GCC system_header |
| 198 | #endif |
| 199 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 200 | _LIBCPP_PUSH_MACROS |
| 201 | #include <__undef_macros> |
| 202 | |
| 203 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 204 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 205 | |
| 206 | template<class _CharT, class _Traits = char_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 207 | class _LIBCPP_TEMPLATE_VIS basic_string_view; |
| 208 | |
| 209 | typedef basic_string_view<char> string_view; |
Arthur O'Dwyer | afa5d5f | 2021-04-18 21:47:08 -0400 | [diff] [blame] | 210 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 211 | typedef basic_string_view<char8_t> u8string_view; |
| 212 | #endif |
| 213 | typedef basic_string_view<char16_t> u16string_view; |
| 214 | typedef basic_string_view<char32_t> u32string_view; |
| 215 | typedef basic_string_view<wchar_t> wstring_view; |
| 216 | |
| 217 | template<class _CharT, class _Traits> |
| 218 | class |
| 219 | _LIBCPP_PREFERRED_NAME(string_view) |
Arthur O'Dwyer | afa5d5f | 2021-04-18 21:47:08 -0400 | [diff] [blame] | 220 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 221 | _LIBCPP_PREFERRED_NAME(u8string_view) |
| 222 | #endif |
| 223 | _LIBCPP_PREFERRED_NAME(u16string_view) |
| 224 | _LIBCPP_PREFERRED_NAME(u32string_view) |
| 225 | _LIBCPP_PREFERRED_NAME(wstring_view) |
| 226 | basic_string_view { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 227 | public: |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 228 | // types |
| 229 | typedef _Traits traits_type; |
| 230 | typedef _CharT value_type; |
Marshall Clow | 7d2c518 | 2017-12-20 16:31:40 +0000 | [diff] [blame] | 231 | typedef _CharT* pointer; |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 232 | typedef const _CharT* const_pointer; |
Marshall Clow | 7d2c518 | 2017-12-20 16:31:40 +0000 | [diff] [blame] | 233 | typedef _CharT& reference; |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 234 | typedef const _CharT& const_reference; |
| 235 | typedef const_pointer const_iterator; // See [string.view.iterators] |
| 236 | typedef const_iterator iterator; |
| 237 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
| 238 | typedef const_reverse_iterator reverse_iterator; |
| 239 | typedef size_t size_type; |
| 240 | typedef ptrdiff_t difference_type; |
| 241 | static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 242 | |
Marshall Clow | 79f3354 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 243 | static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array"); |
| 244 | static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout"); |
| 245 | static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial"); |
Marshall Clow | a3a74e0 | 2017-03-15 18:41:11 +0000 | [diff] [blame] | 246 | static_assert((is_same<_CharT, typename traits_type::char_type>::value), |
| 247 | "traits_type::char_type must be the same type as CharT"); |
| 248 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 249 | // [string.view.cons], construct/copy |
| 250 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 251 | basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {} |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 252 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 253 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 254 | basic_string_view(const basic_string_view&) _NOEXCEPT = default; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 255 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 256 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 257 | basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 258 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 259 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 260 | basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT |
| 261 | : __data(__s), __size(__len) |
| 262 | { |
Marshall Clow | ca1bcdb | 2019-06-04 02:07:11 +0000 | [diff] [blame] | 263 | #if _LIBCPP_STD_VER > 11 |
| 264 | _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr"); |
| 265 | #endif |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 266 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 267 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 268 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 269 | basic_string_view(const _CharT* __s) |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 270 | : __data(__s), __size(_VSTD::__char_traits_length_checked<_Traits>(__s)) {} |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 271 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 272 | // [string.view.iterators], iterators |
| 273 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 274 | const_iterator begin() const _NOEXCEPT { return cbegin(); } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 275 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 276 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 277 | const_iterator end() const _NOEXCEPT { return cend(); } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 278 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 279 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 280 | const_iterator cbegin() const _NOEXCEPT { return __data; } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 281 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 282 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 283 | const_iterator cend() const _NOEXCEPT { return __data + __size; } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 284 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 285 | _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY |
| 286 | const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 287 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 288 | _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY |
| 289 | const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 290 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 291 | _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY |
| 292 | const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 293 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 294 | _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY |
| 295 | const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 296 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 297 | // [string.view.capacity], capacity |
| 298 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 299 | size_type size() const _NOEXCEPT { return __size; } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 300 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 301 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 302 | size_type length() const _NOEXCEPT { return __size; } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 303 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 304 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 305 | size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max(); } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 306 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 307 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 308 | bool empty() const _NOEXCEPT { return __size == 0; } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 309 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 310 | // [string.view.access], element access |
| 311 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
Chris Palmer | 1b114a5 | 2020-10-06 13:01:50 -0400 | [diff] [blame] | 312 | const_reference operator[](size_type __pos) const _NOEXCEPT { |
| 313 | return _LIBCPP_ASSERT(__pos < size(), "string_view[] index out of bounds"), __data[__pos]; |
| 314 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 315 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 316 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 317 | const_reference at(size_type __pos) const |
| 318 | { |
| 319 | return __pos >= size() |
| 320 | ? (__throw_out_of_range("string_view::at"), __data[0]) |
| 321 | : __data[__pos]; |
| 322 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 323 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 324 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 325 | const_reference front() const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 326 | { |
| 327 | return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0]; |
| 328 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 329 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 330 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 331 | const_reference back() const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 332 | { |
| 333 | return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1]; |
| 334 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 335 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 336 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 337 | const_pointer data() const _NOEXCEPT { return __data; } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 338 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 339 | // [string.view.modifiers], modifiers: |
| 340 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 341 | void remove_prefix(size_type __n) _NOEXCEPT |
| 342 | { |
| 343 | _LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()"); |
| 344 | __data += __n; |
| 345 | __size -= __n; |
| 346 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 347 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 348 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 349 | void remove_suffix(size_type __n) _NOEXCEPT |
| 350 | { |
| 351 | _LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()"); |
| 352 | __size -= __n; |
| 353 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 354 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 355 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 356 | void swap(basic_string_view& __other) _NOEXCEPT |
| 357 | { |
| 358 | const value_type *__p = __data; |
| 359 | __data = __other.__data; |
| 360 | __other.__data = __p; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 361 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 362 | size_type __sz = __size; |
| 363 | __size = __other.__size; |
| 364 | __other.__size = __sz; |
| 365 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 366 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 367 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 368 | size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const |
| 369 | { |
| 370 | if (__pos > size()) |
| 371 | __throw_out_of_range("string_view::copy"); |
| 372 | size_type __rlen = _VSTD::min(__n, size() - __pos); |
| 373 | _Traits::copy(__s, data() + __pos, __rlen); |
| 374 | return __rlen; |
| 375 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 376 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 377 | _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY |
| 378 | basic_string_view substr(size_type __pos = 0, size_type __n = npos) const |
| 379 | { |
| 380 | return __pos > size() |
| 381 | ? (__throw_out_of_range("string_view::substr"), basic_string_view()) |
| 382 | : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos)); |
| 383 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 384 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 385 | _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT |
| 386 | { |
| 387 | size_type __rlen = _VSTD::min( size(), __sv.size()); |
| 388 | int __retval = _Traits::compare(data(), __sv.data(), __rlen); |
| 389 | if ( __retval == 0 ) // first __rlen chars matched |
| 390 | __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 ); |
| 391 | return __retval; |
| 392 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 393 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 394 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 395 | int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const |
| 396 | { |
| 397 | return substr(__pos1, __n1).compare(__sv); |
| 398 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 399 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 400 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 401 | int compare( size_type __pos1, size_type __n1, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 402 | basic_string_view __sv, size_type __pos2, size_type __n2) const |
| 403 | { |
| 404 | return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); |
| 405 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 406 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 407 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 408 | int compare(const _CharT* __s) const _NOEXCEPT |
| 409 | { |
| 410 | return compare(basic_string_view(__s)); |
| 411 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 412 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 413 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 414 | int compare(size_type __pos1, size_type __n1, const _CharT* __s) const |
| 415 | { |
| 416 | return substr(__pos1, __n1).compare(basic_string_view(__s)); |
| 417 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 418 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 419 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 420 | int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const |
| 421 | { |
| 422 | return substr(__pos1, __n1).compare(basic_string_view(__s, __n2)); |
| 423 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 424 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 425 | // find |
| 426 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 427 | size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT |
| 428 | { |
| 429 | _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); |
| 430 | return __str_find<value_type, size_type, traits_type, npos> |
| 431 | (data(), size(), __s.data(), __pos, __s.size()); |
| 432 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 433 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 434 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 435 | size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT |
| 436 | { |
| 437 | return __str_find<value_type, size_type, traits_type, npos> |
| 438 | (data(), size(), __c, __pos); |
| 439 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 440 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 441 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 442 | size_type find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 443 | { |
| 444 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr"); |
| 445 | return __str_find<value_type, size_type, traits_type, npos> |
| 446 | (data(), size(), __s, __pos, __n); |
| 447 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 448 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 449 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 450 | size_type find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 451 | { |
| 452 | _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr"); |
| 453 | return __str_find<value_type, size_type, traits_type, npos> |
| 454 | (data(), size(), __s, __pos, traits_type::length(__s)); |
| 455 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 456 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 457 | // rfind |
| 458 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 459 | size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT |
| 460 | { |
| 461 | _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); |
| 462 | return __str_rfind<value_type, size_type, traits_type, npos> |
| 463 | (data(), size(), __s.data(), __pos, __s.size()); |
| 464 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 465 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 466 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 467 | size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT |
| 468 | { |
| 469 | return __str_rfind<value_type, size_type, traits_type, npos> |
| 470 | (data(), size(), __c, __pos); |
| 471 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 472 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 473 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 474 | size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 475 | { |
| 476 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr"); |
| 477 | return __str_rfind<value_type, size_type, traits_type, npos> |
| 478 | (data(), size(), __s, __pos, __n); |
| 479 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 480 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 481 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 482 | size_type rfind(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 483 | { |
| 484 | _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr"); |
| 485 | return __str_rfind<value_type, size_type, traits_type, npos> |
| 486 | (data(), size(), __s, __pos, traits_type::length(__s)); |
| 487 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 488 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 489 | // find_first_of |
| 490 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 491 | size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT |
| 492 | { |
| 493 | _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr"); |
| 494 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
| 495 | (data(), size(), __s.data(), __pos, __s.size()); |
| 496 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 497 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 498 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 499 | size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT |
| 500 | { return find(__c, __pos); } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 501 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 502 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 503 | size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 504 | { |
| 505 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr"); |
| 506 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
| 507 | (data(), size(), __s, __pos, __n); |
| 508 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 509 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 510 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 511 | size_type find_first_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 512 | { |
| 513 | _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr"); |
| 514 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
| 515 | (data(), size(), __s, __pos, traits_type::length(__s)); |
| 516 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 517 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 518 | // find_last_of |
| 519 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 520 | size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT |
| 521 | { |
| 522 | _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr"); |
| 523 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
| 524 | (data(), size(), __s.data(), __pos, __s.size()); |
| 525 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 526 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 527 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 528 | size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT |
| 529 | { return rfind(__c, __pos); } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 530 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 531 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 532 | size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 533 | { |
| 534 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr"); |
| 535 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
| 536 | (data(), size(), __s, __pos, __n); |
| 537 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 538 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 539 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 540 | size_type find_last_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 541 | { |
| 542 | _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr"); |
| 543 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
| 544 | (data(), size(), __s, __pos, traits_type::length(__s)); |
| 545 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 546 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 547 | // find_first_not_of |
| 548 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 549 | size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT |
| 550 | { |
| 551 | _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr"); |
| 552 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
| 553 | (data(), size(), __s.data(), __pos, __s.size()); |
| 554 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 555 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 556 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 557 | size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT |
| 558 | { |
| 559 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
| 560 | (data(), size(), __c, __pos); |
| 561 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 562 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 563 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 564 | size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 565 | { |
| 566 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr"); |
| 567 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
| 568 | (data(), size(), __s, __pos, __n); |
| 569 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 570 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 571 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 572 | size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 573 | { |
| 574 | _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr"); |
| 575 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
| 576 | (data(), size(), __s, __pos, traits_type::length(__s)); |
| 577 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 578 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 579 | // find_last_not_of |
| 580 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 581 | size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT |
| 582 | { |
| 583 | _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr"); |
| 584 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
| 585 | (data(), size(), __s.data(), __pos, __s.size()); |
| 586 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 587 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 588 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 589 | size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT |
| 590 | { |
| 591 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
| 592 | (data(), size(), __c, __pos); |
| 593 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 594 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 595 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 596 | size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 597 | { |
| 598 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr"); |
| 599 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
| 600 | (data(), size(), __s, __pos, __n); |
| 601 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 602 | |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 603 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 604 | size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 605 | { |
| 606 | _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr"); |
| 607 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
| 608 | (data(), size(), __s, __pos, traits_type::length(__s)); |
| 609 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 610 | |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 611 | #if _LIBCPP_STD_VER > 17 |
| 612 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 613 | bool starts_with(basic_string_view __s) const _NOEXCEPT |
| 614 | { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; } |
| 615 | |
| 616 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 617 | bool starts_with(value_type __c) const _NOEXCEPT |
| 618 | { return !empty() && _Traits::eq(front(), __c); } |
| 619 | |
| 620 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 621 | bool starts_with(const value_type* __s) const _NOEXCEPT |
| 622 | { return starts_with(basic_string_view(__s)); } |
| 623 | |
| 624 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 625 | bool ends_with(basic_string_view __s) const _NOEXCEPT |
| 626 | { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; } |
| 627 | |
| 628 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 629 | bool ends_with(value_type __c) const _NOEXCEPT |
| 630 | { return !empty() && _Traits::eq(back(), __c); } |
| 631 | |
| 632 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 633 | bool ends_with(const value_type* __s) const _NOEXCEPT |
| 634 | { return ends_with(basic_string_view(__s)); } |
| 635 | #endif |
| 636 | |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 637 | #if _LIBCPP_STD_VER > 20 |
| 638 | constexpr _LIBCPP_INLINE_VISIBILITY |
| 639 | bool contains(basic_string_view __sv) const noexcept |
| 640 | { return find(__sv) != npos; } |
| 641 | |
| 642 | constexpr _LIBCPP_INLINE_VISIBILITY |
| 643 | bool contains(value_type __c) const noexcept |
| 644 | { return find(__c) != npos; } |
| 645 | |
| 646 | constexpr _LIBCPP_INLINE_VISIBILITY |
| 647 | bool contains(const value_type* __s) const |
| 648 | { return find(__s) != npos; } |
| 649 | #endif |
| 650 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 651 | private: |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 652 | const value_type* __data; |
| 653 | size_type __size; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 654 | }; |
| 655 | |
Mark de Wever | af59b2d | 2020-11-24 18:08:02 +0100 | [diff] [blame] | 656 | #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES) |
| 657 | template <class _CharT, class _Traits> |
| 658 | inline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true; |
| 659 | #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 660 | |
| 661 | // [string.view.comparison] |
| 662 | // operator == |
| 663 | template<class _CharT, class _Traits> |
| 664 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 665 | bool operator==(basic_string_view<_CharT, _Traits> __lhs, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 666 | basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 667 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 668 | if ( __lhs.size() != __rhs.size()) return false; |
| 669 | return __lhs.compare(__rhs) == 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | template<class _CharT, class _Traits> |
| 673 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 674 | bool operator==(basic_string_view<_CharT, _Traits> __lhs, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 675 | typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 676 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 677 | if ( __lhs.size() != __rhs.size()) return false; |
| 678 | return __lhs.compare(__rhs) == 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | template<class _CharT, class _Traits> |
| 682 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 683 | bool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 684 | basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 685 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 686 | if ( __lhs.size() != __rhs.size()) return false; |
| 687 | return __lhs.compare(__rhs) == 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | |
| 691 | // operator != |
| 692 | template<class _CharT, class _Traits> |
| 693 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 694 | bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT |
| 695 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 696 | if ( __lhs.size() != __rhs.size()) |
| 697 | return true; |
| 698 | return __lhs.compare(__rhs) != 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | template<class _CharT, class _Traits> |
| 702 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 703 | bool operator!=(basic_string_view<_CharT, _Traits> __lhs, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 704 | typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 705 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 706 | if ( __lhs.size() != __rhs.size()) |
| 707 | return true; |
| 708 | return __lhs.compare(__rhs) != 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | template<class _CharT, class _Traits> |
| 712 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 713 | bool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 714 | basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 715 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 716 | if ( __lhs.size() != __rhs.size()) |
| 717 | return true; |
| 718 | return __lhs.compare(__rhs) != 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | |
| 722 | // operator < |
| 723 | template<class _CharT, class _Traits> |
| 724 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 725 | bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT |
| 726 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 727 | return __lhs.compare(__rhs) < 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | template<class _CharT, class _Traits> |
| 731 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 732 | bool operator<(basic_string_view<_CharT, _Traits> __lhs, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 733 | typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 734 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 735 | return __lhs.compare(__rhs) < 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | template<class _CharT, class _Traits> |
| 739 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 740 | bool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 741 | basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 742 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 743 | return __lhs.compare(__rhs) < 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | |
| 747 | // operator > |
| 748 | template<class _CharT, class _Traits> |
| 749 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 750 | bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT |
| 751 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 752 | return __lhs.compare(__rhs) > 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | template<class _CharT, class _Traits> |
| 756 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 757 | bool operator>(basic_string_view<_CharT, _Traits> __lhs, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 758 | typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 759 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 760 | return __lhs.compare(__rhs) > 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | template<class _CharT, class _Traits> |
| 764 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 765 | bool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 766 | basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 767 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 768 | return __lhs.compare(__rhs) > 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | |
| 772 | // operator <= |
| 773 | template<class _CharT, class _Traits> |
| 774 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 775 | bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT |
| 776 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 777 | return __lhs.compare(__rhs) <= 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | template<class _CharT, class _Traits> |
| 781 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 782 | bool operator<=(basic_string_view<_CharT, _Traits> __lhs, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 783 | typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 784 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 785 | return __lhs.compare(__rhs) <= 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | template<class _CharT, class _Traits> |
| 789 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 790 | bool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 791 | basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 792 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 793 | return __lhs.compare(__rhs) <= 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | |
| 797 | // operator >= |
| 798 | template<class _CharT, class _Traits> |
| 799 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 800 | bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT |
| 801 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 802 | return __lhs.compare(__rhs) >= 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | |
| 806 | template<class _CharT, class _Traits> |
| 807 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 808 | bool operator>=(basic_string_view<_CharT, _Traits> __lhs, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 809 | typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 810 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 811 | return __lhs.compare(__rhs) >= 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | template<class _CharT, class _Traits> |
| 815 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 816 | bool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 817 | basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 818 | { |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 819 | return __lhs.compare(__rhs) >= 0; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 820 | } |
| 821 | |
Eric Fiselier | 1411692 | 2019-09-25 18:56:54 +0000 | [diff] [blame] | 822 | |
| 823 | template<class _CharT, class _Traits> |
| 824 | basic_ostream<_CharT, _Traits>& |
| 825 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 826 | basic_string_view<_CharT, _Traits> __str); |
| 827 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 828 | // [string.view.hash] |
Marshall Clow | ab313df | 2019-06-27 14:18:32 +0000 | [diff] [blame] | 829 | template<class _CharT> |
| 830 | struct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, char_traits<_CharT> > > |
| 831 | : public unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 832 | { |
Louis Dionne | d83f2e6 | 2018-11-28 15:22:30 +0000 | [diff] [blame] | 833 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ab313df | 2019-06-27 14:18:32 +0000 | [diff] [blame] | 834 | size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT { |
Louis Dionne | d83f2e6 | 2018-11-28 15:22:30 +0000 | [diff] [blame] | 835 | return __do_string_hash(__val.data(), __val.data() + __val.size()); |
| 836 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 837 | }; |
| 838 | |
Marshall Clow | 27c8a4c | 2017-01-09 18:07:34 +0000 | [diff] [blame] | 839 | |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 840 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | 27c8a4c | 2017-01-09 18:07:34 +0000 | [diff] [blame] | 841 | inline namespace literals |
| 842 | { |
| 843 | inline namespace string_view_literals |
| 844 | { |
| 845 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Marshall Clow | abe6daf | 2017-10-24 14:06:00 +0000 | [diff] [blame] | 846 | basic_string_view<char> operator "" sv(const char *__str, size_t __len) _NOEXCEPT |
Marshall Clow | 27c8a4c | 2017-01-09 18:07:34 +0000 | [diff] [blame] | 847 | { |
| 848 | return basic_string_view<char> (__str, __len); |
| 849 | } |
| 850 | |
| 851 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Marshall Clow | abe6daf | 2017-10-24 14:06:00 +0000 | [diff] [blame] | 852 | basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT |
Marshall Clow | 27c8a4c | 2017-01-09 18:07:34 +0000 | [diff] [blame] | 853 | { |
| 854 | return basic_string_view<wchar_t> (__str, __len); |
| 855 | } |
| 856 | |
Arthur O'Dwyer | afa5d5f | 2021-04-18 21:47:08 -0400 | [diff] [blame] | 857 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
Marshall Clow | 8732fed | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 858 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 859 | basic_string_view<char8_t> operator "" sv(const char8_t *__str, size_t __len) _NOEXCEPT |
| 860 | { |
| 861 | return basic_string_view<char8_t> (__str, __len); |
| 862 | } |
| 863 | #endif |
| 864 | |
Marshall Clow | 27c8a4c | 2017-01-09 18:07:34 +0000 | [diff] [blame] | 865 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Marshall Clow | abe6daf | 2017-10-24 14:06:00 +0000 | [diff] [blame] | 866 | basic_string_view<char16_t> operator "" sv(const char16_t *__str, size_t __len) _NOEXCEPT |
Marshall Clow | 27c8a4c | 2017-01-09 18:07:34 +0000 | [diff] [blame] | 867 | { |
| 868 | return basic_string_view<char16_t> (__str, __len); |
| 869 | } |
| 870 | |
| 871 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Marshall Clow | abe6daf | 2017-10-24 14:06:00 +0000 | [diff] [blame] | 872 | basic_string_view<char32_t> operator "" sv(const char32_t *__str, size_t __len) _NOEXCEPT |
Marshall Clow | 27c8a4c | 2017-01-09 18:07:34 +0000 | [diff] [blame] | 873 | { |
| 874 | return basic_string_view<char32_t> (__str, __len); |
| 875 | } |
| 876 | } |
| 877 | } |
| 878 | #endif |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 879 | _LIBCPP_END_NAMESPACE_STD |
| 880 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 881 | _LIBCPP_POP_MACROS |
| 882 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 883 | #endif // _LIBCPP_STRING_VIEW |