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