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