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