1053d81ceSMarshall Clow// -*- C++ -*-
2053d81ceSMarshall Clow//===------------------------ string_view ---------------------------------===//
3053d81ceSMarshall Clow//
42946cd70SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
52946cd70SChandler Carruth// See https://llvm.org/LICENSE.txt for license information.
62946cd70SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7053d81ceSMarshall Clow//
8053d81ceSMarshall Clow//===----------------------------------------------------------------------===//
9053d81ceSMarshall Clow
10053d81ceSMarshall Clow#ifndef _LIBCPP_STRING_VIEW
11053d81ceSMarshall Clow#define _LIBCPP_STRING_VIEW
12053d81ceSMarshall Clow
13053d81ceSMarshall Clow/*
14053d81ceSMarshall Clowstring_view synopsis
15053d81ceSMarshall Clow
16053d81ceSMarshall Clownamespace std {
17053d81ceSMarshall Clow
18053d81ceSMarshall Clow    // 7.2, Class template basic_string_view
19053d81ceSMarshall Clow    template<class charT, class traits = char_traits<charT>>
20053d81ceSMarshall Clow        class basic_string_view;
21053d81ceSMarshall Clow
2201ace074SMark de Wever    template<class charT, class traits>
23*462f8f06SChristopher Di Bella    inline constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true;
24*462f8f06SChristopher Di Bella
25*462f8f06SChristopher Di Bella    template<class charT, class traits>
2601ace074SMark de Wever    inline constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true;  // C++20
2701ace074SMark de Wever
28053d81ceSMarshall Clow    // 7.9, basic_string_view non-member comparison functions
29053d81ceSMarshall Clow    template<class charT, class traits>
30053d81ceSMarshall Clow    constexpr bool operator==(basic_string_view<charT, traits> x,
31053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
32053d81ceSMarshall Clow    template<class charT, class traits>
33053d81ceSMarshall Clow    constexpr bool operator!=(basic_string_view<charT, traits> x,
34053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
35053d81ceSMarshall Clow    template<class charT, class traits>
36053d81ceSMarshall Clow    constexpr bool operator< (basic_string_view<charT, traits> x,
37053d81ceSMarshall Clow                                 basic_string_view<charT, traits> y) noexcept;
38053d81ceSMarshall Clow    template<class charT, class traits>
39053d81ceSMarshall Clow    constexpr bool operator> (basic_string_view<charT, traits> x,
40053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
41053d81ceSMarshall Clow    template<class charT, class traits>
42053d81ceSMarshall Clow    constexpr bool operator<=(basic_string_view<charT, traits> x,
43053d81ceSMarshall Clow                                 basic_string_view<charT, traits> y) noexcept;
44053d81ceSMarshall Clow    template<class charT, class traits>
45053d81ceSMarshall Clow    constexpr bool operator>=(basic_string_view<charT, traits> x,
46053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
47053d81ceSMarshall Clow    // see below, sufficient additional overloads of comparison functions
48053d81ceSMarshall Clow
49053d81ceSMarshall Clow    // 7.10, Inserters and extractors
50053d81ceSMarshall Clow    template<class charT, class traits>
51053d81ceSMarshall Clow      basic_ostream<charT, traits>&
52053d81ceSMarshall Clow        operator<<(basic_ostream<charT, traits>& os,
53053d81ceSMarshall Clow                   basic_string_view<charT, traits> str);
54053d81ceSMarshall Clow
55053d81ceSMarshall Clow    // basic_string_view typedef names
56053d81ceSMarshall Clow    typedef basic_string_view<char> string_view;
5728f82becSMarek Kurdej    typedef basic_string_view<char8_t> u8string_view; // C++20
58053d81ceSMarshall Clow    typedef basic_string_view<char16_t> u16string_view;
59053d81ceSMarshall Clow    typedef basic_string_view<char32_t> u32string_view;
60053d81ceSMarshall Clow    typedef basic_string_view<wchar_t> wstring_view;
61053d81ceSMarshall Clow
62053d81ceSMarshall Clow    template<class charT, class traits = char_traits<charT>>
63053d81ceSMarshall Clow    class basic_string_view {
64053d81ceSMarshall Clow      public:
65053d81ceSMarshall Clow      // types
66053d81ceSMarshall Clow      typedef traits traits_type;
67053d81ceSMarshall Clow      typedef charT value_type;
68053d81ceSMarshall Clow      typedef charT* pointer;
69053d81ceSMarshall Clow      typedef const charT* const_pointer;
70053d81ceSMarshall Clow      typedef charT& reference;
71053d81ceSMarshall Clow      typedef const charT& const_reference;
72053d81ceSMarshall Clow      typedef implementation-defined const_iterator;
73053d81ceSMarshall Clow      typedef const_iterator iterator;
74053d81ceSMarshall Clow      typedef reverse_iterator<const_iterator> const_reverse_iterator;
75053d81ceSMarshall Clow      typedef const_reverse_iterator reverse_iterator;
76053d81ceSMarshall Clow      typedef size_t size_type;
77053d81ceSMarshall Clow      typedef ptrdiff_t difference_type;
78053d81ceSMarshall Clow      static constexpr size_type npos = size_type(-1);
79053d81ceSMarshall Clow
80053d81ceSMarshall Clow      // 7.3, basic_string_view constructors and assignment operators
81053d81ceSMarshall Clow      constexpr basic_string_view() noexcept;
82053d81ceSMarshall Clow      constexpr basic_string_view(const basic_string_view&) noexcept = default;
83053d81ceSMarshall Clow      basic_string_view& operator=(const basic_string_view&) noexcept = default;
84053d81ceSMarshall Clow      template<class Allocator>
85053d81ceSMarshall Clow      constexpr basic_string_view(const charT* str);
86053d81ceSMarshall Clow      constexpr basic_string_view(const charT* str, size_type len);
87053d81ceSMarshall Clow
88053d81ceSMarshall Clow      // 7.4, basic_string_view iterator support
89053d81ceSMarshall Clow      constexpr const_iterator begin() const noexcept;
90053d81ceSMarshall Clow      constexpr const_iterator end() const noexcept;
91053d81ceSMarshall Clow      constexpr const_iterator cbegin() const noexcept;
92053d81ceSMarshall Clow      constexpr const_iterator cend() const noexcept;
93053d81ceSMarshall Clow      const_reverse_iterator rbegin() const noexcept;
94053d81ceSMarshall Clow      const_reverse_iterator rend() const noexcept;
95053d81ceSMarshall Clow      const_reverse_iterator crbegin() const noexcept;
96053d81ceSMarshall Clow      const_reverse_iterator crend() const noexcept;
97053d81ceSMarshall Clow
98053d81ceSMarshall Clow      // 7.5, basic_string_view capacity
99053d81ceSMarshall Clow      constexpr size_type size() const noexcept;
100053d81ceSMarshall Clow      constexpr size_type length() const noexcept;
101053d81ceSMarshall Clow      constexpr size_type max_size() const noexcept;
102053d81ceSMarshall Clow      constexpr bool empty() const noexcept;
103053d81ceSMarshall Clow
104053d81ceSMarshall Clow      // 7.6, basic_string_view element access
105053d81ceSMarshall Clow      constexpr const_reference operator[](size_type pos) const;
106053d81ceSMarshall Clow      constexpr const_reference at(size_type pos) const;
107053d81ceSMarshall Clow      constexpr const_reference front() const;
108053d81ceSMarshall Clow      constexpr const_reference back() const;
109053d81ceSMarshall Clow      constexpr const_pointer data() const noexcept;
110053d81ceSMarshall Clow
111053d81ceSMarshall Clow      // 7.7, basic_string_view modifiers
112053d81ceSMarshall Clow      constexpr void remove_prefix(size_type n);
113053d81ceSMarshall Clow      constexpr void remove_suffix(size_type n);
114053d81ceSMarshall Clow      constexpr void swap(basic_string_view& s) noexcept;
115053d81ceSMarshall Clow
11606e2b737SArthur O'Dwyer      size_type copy(charT* s, size_type n, size_type pos = 0) const;  // constexpr in C++20
117053d81ceSMarshall Clow
118053d81ceSMarshall Clow      constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
119053d81ceSMarshall Clow      constexpr int compare(basic_string_view s) const noexcept;
120053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
121053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1,
122053d81ceSMarshall Clow                            basic_string_view s, size_type pos2, size_type n2) const;
123053d81ceSMarshall Clow      constexpr int compare(const charT* s) const;
124053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
125053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1,
126053d81ceSMarshall Clow                            const charT* s, size_type n2) const;
127053d81ceSMarshall Clow      constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
128053d81ceSMarshall Clow      constexpr size_type find(charT c, size_type pos = 0) const noexcept;
129dea74b28Szoecarver      constexpr size_type find(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
130dea74b28Szoecarver      constexpr size_type find(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
131053d81ceSMarshall Clow      constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
132053d81ceSMarshall Clow      constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
133dea74b28Szoecarver      constexpr size_type rfind(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
134dea74b28Szoecarver      constexpr size_type rfind(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
135053d81ceSMarshall Clow      constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
136053d81ceSMarshall Clow      constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
137dea74b28Szoecarver      constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
138dea74b28Szoecarver      constexpr size_type find_first_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
139053d81ceSMarshall Clow      constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
140053d81ceSMarshall Clow      constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
141dea74b28Szoecarver      constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
142dea74b28Szoecarver      constexpr size_type find_last_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
143053d81ceSMarshall Clow      constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
144053d81ceSMarshall Clow      constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
145dea74b28Szoecarver      constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
146dea74b28Szoecarver      constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
147053d81ceSMarshall Clow      constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
148053d81ceSMarshall Clow      constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
149dea74b28Szoecarver      constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
150dea74b28Szoecarver      constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
151053d81ceSMarshall Clow
152044b892cSMarek Kurdej      constexpr bool starts_with(basic_string_view s) const noexcept; // C++20
153044b892cSMarek Kurdej      constexpr bool starts_with(charT c) const noexcept;             // C++20
154044b892cSMarek Kurdej      constexpr bool starts_with(const charT* s) const;               // C++20
155044b892cSMarek Kurdej      constexpr bool ends_with(basic_string_view s) const noexcept;   // C++20
156044b892cSMarek Kurdej      constexpr bool ends_with(charT c) const noexcept;               // C++20
157044b892cSMarek Kurdej      constexpr bool ends_with(const charT* s) const;                 // C++20
158800259c9SMarshall Clow
1596ac9cb2aSWim Leflere      constexpr bool contains(basic_string_view s) const noexcept; // C++2b
1606ac9cb2aSWim Leflere      constexpr bool contains(charT c) const noexcept;             // C++2b
1616ac9cb2aSWim Leflere      constexpr bool contains(const charT* s) const;               // C++2b
1626ac9cb2aSWim Leflere
163053d81ceSMarshall Clow     private:
164053d81ceSMarshall Clow      const_pointer data_;  // exposition only
165053d81ceSMarshall Clow      size_type     size_;  // exposition only
166053d81ceSMarshall Clow    };
167053d81ceSMarshall Clow
168053d81ceSMarshall Clow  // 7.11, Hash support
169053d81ceSMarshall Clow  template <class T> struct hash;
170053d81ceSMarshall Clow  template <> struct hash<string_view>;
17128f82becSMarek Kurdej  template <> struct hash<u8string_view>; // C++20
172053d81ceSMarshall Clow  template <> struct hash<u16string_view>;
173053d81ceSMarshall Clow  template <> struct hash<u32string_view>;
174053d81ceSMarshall Clow  template <> struct hash<wstring_view>;
175053d81ceSMarshall Clow
17659b48302SMarshall Clow  constexpr basic_string_view<char>     operator "" sv( const char *str,     size_t len ) noexcept;
17759b48302SMarshall Clow  constexpr basic_string_view<wchar_t>  operator "" sv( const wchar_t *str,  size_t len ) noexcept;
17828f82becSMarek Kurdej  constexpr basic_string_view<char8_t>  operator "" sv( const char8_t *str,  size_t len ) noexcept; // C++20
17959b48302SMarshall Clow  constexpr basic_string_view<char16_t> operator "" sv( const char16_t *str, size_t len ) noexcept;
18059b48302SMarshall Clow  constexpr basic_string_view<char32_t> operator "" sv( const char32_t *str, size_t len ) noexcept;
1818fd58a6bSMarshall Clow
182053d81ceSMarshall Clow}  // namespace std
183053d81ceSMarshall Clow
184053d81ceSMarshall Clow
185053d81ceSMarshall Clow*/
186053d81ceSMarshall Clow
187053d81ceSMarshall Clow#include <__config>
188bfbd73f8SArthur O'Dwyer#include <__debug>
18901ace074SMark de Wever#include <__ranges/enable_borrowed_range.h>
190*462f8f06SChristopher Di Bella#include <__ranges/enable_view.h>
191053d81ceSMarshall Clow#include <__string>
192ca648c97SEric Fiselier#include <algorithm>
1932d0f1fa4SArthur O'Dwyer#include <compare>
194bfbd73f8SArthur O'Dwyer#include <iosfwd>
195053d81ceSMarshall Clow#include <iterator>
196ca648c97SEric Fiselier#include <limits>
197ca648c97SEric Fiselier#include <stdexcept>
198f56972e2SMarshall Clow#include <version>
199053d81ceSMarshall Clow
200053d81ceSMarshall Clow#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
201053d81ceSMarshall Clow#pragma GCC system_header
202053d81ceSMarshall Clow#endif
203053d81ceSMarshall Clow
204a016efb1SEric Fiselier_LIBCPP_PUSH_MACROS
205a016efb1SEric Fiselier#include <__undef_macros>
206a016efb1SEric Fiselier
207a016efb1SEric Fiselier
208053d81ceSMarshall Clow_LIBCPP_BEGIN_NAMESPACE_STD
209053d81ceSMarshall Clow
210053d81ceSMarshall Clowtemplate<class _CharT, class _Traits = char_traits<_CharT> >
2112a2c228cSRichard Smith    class _LIBCPP_TEMPLATE_VIS basic_string_view;
2122a2c228cSRichard Smith
2132a2c228cSRichard Smithtypedef basic_string_view<char>     string_view;
2145c40c994SArthur O'Dwyer#ifndef _LIBCPP_HAS_NO_CHAR8_T
2152a2c228cSRichard Smithtypedef basic_string_view<char8_t>  u8string_view;
2162a2c228cSRichard Smith#endif
2172a2c228cSRichard Smithtypedef basic_string_view<char16_t> u16string_view;
2182a2c228cSRichard Smithtypedef basic_string_view<char32_t> u32string_view;
2192a2c228cSRichard Smithtypedef basic_string_view<wchar_t>  wstring_view;
2202a2c228cSRichard Smith
2212a2c228cSRichard Smithtemplate<class _CharT, class _Traits>
2222a2c228cSRichard Smithclass
2232a2c228cSRichard Smith    _LIBCPP_PREFERRED_NAME(string_view)
2245c40c994SArthur O'Dwyer#ifndef _LIBCPP_HAS_NO_CHAR8_T
2252a2c228cSRichard Smith    _LIBCPP_PREFERRED_NAME(u8string_view)
2262a2c228cSRichard Smith#endif
2272a2c228cSRichard Smith    _LIBCPP_PREFERRED_NAME(u16string_view)
2282a2c228cSRichard Smith    _LIBCPP_PREFERRED_NAME(u32string_view)
2292a2c228cSRichard Smith    _LIBCPP_PREFERRED_NAME(wstring_view)
2302a2c228cSRichard Smith    basic_string_view {
231053d81ceSMarshall Clowpublic:
232053d81ceSMarshall Clow    // types
233053d81ceSMarshall Clow    typedef _Traits                                    traits_type;
234053d81ceSMarshall Clow    typedef _CharT                                     value_type;
2357d661bb2SMarshall Clow    typedef _CharT*                                    pointer;
236053d81ceSMarshall Clow    typedef const _CharT*                              const_pointer;
2377d661bb2SMarshall Clow    typedef _CharT&                                    reference;
238053d81ceSMarshall Clow    typedef const _CharT&                              const_reference;
239053d81ceSMarshall Clow    typedef const_pointer                              const_iterator; // See [string.view.iterators]
240053d81ceSMarshall Clow    typedef const_iterator                             iterator;
241053d81ceSMarshall Clow    typedef _VSTD::reverse_iterator<const_iterator>    const_reverse_iterator;
242053d81ceSMarshall Clow    typedef const_reverse_iterator                     reverse_iterator;
243053d81ceSMarshall Clow    typedef size_t                                     size_type;
244053d81ceSMarshall Clow    typedef ptrdiff_t                                  difference_type;
245053d81ceSMarshall Clow    static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
246053d81ceSMarshall Clow
2474a6f3c47SMarshall Clow    static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array");
2484a6f3c47SMarshall Clow    static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout");
2494a6f3c47SMarshall Clow    static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial");
2504069c2bcSMarshall Clow    static_assert((is_same<_CharT, typename traits_type::char_type>::value),
2514069c2bcSMarshall Clow                  "traits_type::char_type must be the same type as CharT");
2524069c2bcSMarshall Clow
253053d81ceSMarshall Clow    // [string.view.cons], construct/copy
254053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
255053d81ceSMarshall Clow    basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {}
256053d81ceSMarshall Clow
257053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
258053d81ceSMarshall Clow    basic_string_view(const basic_string_view&) _NOEXCEPT = default;
259053d81ceSMarshall Clow
260cddeb751SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
261053d81ceSMarshall Clow    basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
262053d81ceSMarshall Clow
263053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
264ac2b3e3aSMarshall Clow    basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
265053d81ceSMarshall Clow        : __data(__s), __size(__len)
266053d81ceSMarshall Clow    {
267f67524d4SMarshall Clow#if _LIBCPP_STD_VER > 11
268f67524d4SMarshall Clow    _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
269f67524d4SMarshall Clow#endif
270053d81ceSMarshall Clow    }
271053d81ceSMarshall Clow
272053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
273053d81ceSMarshall Clow    basic_string_view(const _CharT* __s)
274d586f92cSArthur O'Dwyer        : __data(__s), __size(_VSTD::__char_traits_length_checked<_Traits>(__s)) {}
275053d81ceSMarshall Clow
276053d81ceSMarshall Clow    // [string.view.iterators], iterators
277053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
278053d81ceSMarshall Clow    const_iterator begin()  const _NOEXCEPT { return cbegin(); }
279053d81ceSMarshall Clow
280053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
281053d81ceSMarshall Clow    const_iterator end()    const _NOEXCEPT { return cend(); }
282053d81ceSMarshall Clow
283053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
284053d81ceSMarshall Clow    const_iterator cbegin() const _NOEXCEPT { return __data; }
285053d81ceSMarshall Clow
286053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
287053d81ceSMarshall Clow    const_iterator cend()   const _NOEXCEPT { return __data + __size; }
288053d81ceSMarshall Clow
289cddeb751SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
290053d81ceSMarshall Clow    const_reverse_iterator rbegin()   const _NOEXCEPT { return const_reverse_iterator(cend()); }
291053d81ceSMarshall Clow
292cddeb751SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
293053d81ceSMarshall Clow    const_reverse_iterator rend()     const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
294053d81ceSMarshall Clow
295cddeb751SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
296053d81ceSMarshall Clow    const_reverse_iterator crbegin()  const _NOEXCEPT { return const_reverse_iterator(cend()); }
297053d81ceSMarshall Clow
298cddeb751SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
299053d81ceSMarshall Clow    const_reverse_iterator crend()    const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
300053d81ceSMarshall Clow
301053d81ceSMarshall Clow    // [string.view.capacity], capacity
302053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
303053d81ceSMarshall Clow    size_type size()     const _NOEXCEPT { return __size; }
304053d81ceSMarshall Clow
305053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
306053d81ceSMarshall Clow    size_type length()   const _NOEXCEPT { return __size; }
307053d81ceSMarshall Clow
308053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
309053d81ceSMarshall Clow    size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max(); }
310053d81ceSMarshall Clow
31125a7ba45SMarshall Clow    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
31225a7ba45SMarshall Clow    bool empty()         const _NOEXCEPT { return __size == 0; }
313053d81ceSMarshall Clow
314053d81ceSMarshall Clow    // [string.view.access], element access
315053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3169eff07a7SChris Palmer    const_reference operator[](size_type __pos) const _NOEXCEPT {
3179eff07a7SChris Palmer      return _LIBCPP_ASSERT(__pos < size(), "string_view[] index out of bounds"), __data[__pos];
3189eff07a7SChris Palmer    }
319053d81ceSMarshall Clow
320053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
321053d81ceSMarshall Clow    const_reference at(size_type __pos) const
322053d81ceSMarshall Clow    {
323053d81ceSMarshall Clow        return __pos >= size()
3240fc8cec7SMarshall Clow            ? (__throw_out_of_range("string_view::at"), __data[0])
325053d81ceSMarshall Clow            : __data[__pos];
326053d81ceSMarshall Clow    }
327053d81ceSMarshall Clow
328053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3299ea0e473SMarshall Clow    const_reference front() const _NOEXCEPT
330053d81ceSMarshall Clow    {
331053d81ceSMarshall Clow        return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0];
332053d81ceSMarshall Clow    }
333053d81ceSMarshall Clow
334053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3359ea0e473SMarshall Clow    const_reference back() const _NOEXCEPT
336053d81ceSMarshall Clow    {
337053d81ceSMarshall Clow        return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1];
338053d81ceSMarshall Clow    }
339053d81ceSMarshall Clow
340053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
341053d81ceSMarshall Clow    const_pointer data() const _NOEXCEPT { return __data; }
342053d81ceSMarshall Clow
343053d81ceSMarshall Clow    // [string.view.modifiers], modifiers:
344053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
345053d81ceSMarshall Clow    void remove_prefix(size_type __n) _NOEXCEPT
346053d81ceSMarshall Clow    {
347053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()");
348053d81ceSMarshall Clow        __data += __n;
349053d81ceSMarshall Clow        __size -= __n;
350053d81ceSMarshall Clow    }
351053d81ceSMarshall Clow
352053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
353053d81ceSMarshall Clow    void remove_suffix(size_type __n) _NOEXCEPT
354053d81ceSMarshall Clow    {
355053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()");
356053d81ceSMarshall Clow        __size -= __n;
357053d81ceSMarshall Clow    }
358053d81ceSMarshall Clow
359053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
360053d81ceSMarshall Clow    void swap(basic_string_view& __other) _NOEXCEPT
361053d81ceSMarshall Clow    {
362053d81ceSMarshall Clow        const value_type *__p = __data;
363053d81ceSMarshall Clow        __data = __other.__data;
364053d81ceSMarshall Clow        __other.__data = __p;
365053d81ceSMarshall Clow
366053d81ceSMarshall Clow        size_type __sz = __size;
367053d81ceSMarshall Clow        __size = __other.__size;
368053d81ceSMarshall Clow        __other.__size = __sz;
369053d81ceSMarshall Clow    }
370053d81ceSMarshall Clow
37106e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
372053d81ceSMarshall Clow    size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const
373053d81ceSMarshall Clow    {
374053d81ceSMarshall Clow        if (__pos > size())
3750fc8cec7SMarshall Clow            __throw_out_of_range("string_view::copy");
376053d81ceSMarshall Clow        size_type __rlen = _VSTD::min(__n, size() - __pos);
3771c7fe126SMarshall Clow        _Traits::copy(__s, data() + __pos, __rlen);
378053d81ceSMarshall Clow        return __rlen;
379053d81ceSMarshall Clow    }
380053d81ceSMarshall Clow
381053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
382053d81ceSMarshall Clow    basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
383053d81ceSMarshall Clow    {
384053d81ceSMarshall Clow        return __pos > size()
3850fc8cec7SMarshall Clow            ? (__throw_out_of_range("string_view::substr"), basic_string_view())
386053d81ceSMarshall Clow            : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos));
387053d81ceSMarshall Clow    }
388053d81ceSMarshall Clow
389053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT
390053d81ceSMarshall Clow    {
391053d81ceSMarshall Clow        size_type __rlen = _VSTD::min( size(), __sv.size());
392053d81ceSMarshall Clow        int __retval = _Traits::compare(data(), __sv.data(), __rlen);
393053d81ceSMarshall Clow        if ( __retval == 0 ) // first __rlen chars matched
394053d81ceSMarshall Clow            __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 );
395053d81ceSMarshall Clow        return __retval;
396053d81ceSMarshall Clow    }
397053d81ceSMarshall Clow
398053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
399053d81ceSMarshall Clow    int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const
400053d81ceSMarshall Clow    {
401053d81ceSMarshall Clow        return substr(__pos1, __n1).compare(__sv);
402053d81ceSMarshall Clow    }
403053d81ceSMarshall Clow
404053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
405053d81ceSMarshall Clow    int compare(                       size_type __pos1, size_type __n1,
4069ffacf3dSEric Fiselier                basic_string_view __sv, size_type __pos2, size_type __n2) const
407053d81ceSMarshall Clow    {
4089ffacf3dSEric Fiselier        return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
409053d81ceSMarshall Clow    }
410053d81ceSMarshall Clow
411053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
412aa849bc2SMarshall Clow    int compare(const _CharT* __s) const _NOEXCEPT
413053d81ceSMarshall Clow    {
414053d81ceSMarshall Clow        return compare(basic_string_view(__s));
415053d81ceSMarshall Clow    }
416053d81ceSMarshall Clow
417053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
418053d81ceSMarshall Clow    int compare(size_type __pos1, size_type __n1, const _CharT* __s) const
419053d81ceSMarshall Clow    {
420053d81ceSMarshall Clow        return substr(__pos1, __n1).compare(basic_string_view(__s));
421053d81ceSMarshall Clow    }
422053d81ceSMarshall Clow
423053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
424053d81ceSMarshall Clow    int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
425053d81ceSMarshall Clow    {
426053d81ceSMarshall Clow        return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
427053d81ceSMarshall Clow    }
428053d81ceSMarshall Clow
429053d81ceSMarshall Clow    // find
430053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
431053d81ceSMarshall Clow    size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
432053d81ceSMarshall Clow    {
433053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
434053d81ceSMarshall Clow        return __str_find<value_type, size_type, traits_type, npos>
435053d81ceSMarshall Clow            (data(), size(), __s.data(), __pos, __s.size());
436053d81ceSMarshall Clow    }
437053d81ceSMarshall Clow
438053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
439053d81ceSMarshall Clow    size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT
440053d81ceSMarshall Clow    {
441053d81ceSMarshall Clow        return __str_find<value_type, size_type, traits_type, npos>
442053d81ceSMarshall Clow            (data(), size(), __c, __pos);
443053d81ceSMarshall Clow    }
444053d81ceSMarshall Clow
445053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
446dea74b28Szoecarver    size_type find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
447053d81ceSMarshall Clow    {
448053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
449053d81ceSMarshall Clow        return __str_find<value_type, size_type, traits_type, npos>
450053d81ceSMarshall Clow            (data(), size(), __s, __pos, __n);
451053d81ceSMarshall Clow    }
452053d81ceSMarshall Clow
453053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
454dea74b28Szoecarver    size_type find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT
455053d81ceSMarshall Clow    {
456053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr");
457053d81ceSMarshall Clow        return __str_find<value_type, size_type, traits_type, npos>
458053d81ceSMarshall Clow            (data(), size(), __s, __pos, traits_type::length(__s));
459053d81ceSMarshall Clow    }
460053d81ceSMarshall Clow
461053d81ceSMarshall Clow    // rfind
462053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
463053d81ceSMarshall Clow    size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT
464053d81ceSMarshall Clow    {
465053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
466053d81ceSMarshall Clow        return __str_rfind<value_type, size_type, traits_type, npos>
467053d81ceSMarshall Clow            (data(), size(), __s.data(), __pos, __s.size());
468053d81ceSMarshall Clow    }
469053d81ceSMarshall Clow
470053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
471053d81ceSMarshall Clow    size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT
472053d81ceSMarshall Clow    {
473053d81ceSMarshall Clow        return __str_rfind<value_type, size_type, traits_type, npos>
474053d81ceSMarshall Clow            (data(), size(), __c, __pos);
475053d81ceSMarshall Clow    }
476053d81ceSMarshall Clow
477053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
478dea74b28Szoecarver    size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
479053d81ceSMarshall Clow    {
480053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
481053d81ceSMarshall Clow        return __str_rfind<value_type, size_type, traits_type, npos>
482053d81ceSMarshall Clow            (data(), size(), __s, __pos, __n);
483053d81ceSMarshall Clow    }
484053d81ceSMarshall Clow
485053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
486dea74b28Szoecarver    size_type rfind(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
487053d81ceSMarshall Clow    {
488053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr");
489053d81ceSMarshall Clow        return __str_rfind<value_type, size_type, traits_type, npos>
490053d81ceSMarshall Clow            (data(), size(), __s, __pos, traits_type::length(__s));
491053d81ceSMarshall Clow    }
492053d81ceSMarshall Clow
493053d81ceSMarshall Clow    // find_first_of
494053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
495053d81ceSMarshall Clow    size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
496053d81ceSMarshall Clow    {
497053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
498053d81ceSMarshall Clow        return __str_find_first_of<value_type, size_type, traits_type, npos>
499053d81ceSMarshall Clow            (data(), size(), __s.data(), __pos, __s.size());
500053d81ceSMarshall Clow    }
501053d81ceSMarshall Clow
502053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
503053d81ceSMarshall Clow    size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT
504053d81ceSMarshall Clow    { return find(__c, __pos); }
505053d81ceSMarshall Clow
506053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
507dea74b28Szoecarver    size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
508053d81ceSMarshall Clow    {
509053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
510053d81ceSMarshall Clow        return __str_find_first_of<value_type, size_type, traits_type, npos>
511053d81ceSMarshall Clow            (data(), size(), __s, __pos, __n);
512053d81ceSMarshall Clow    }
513053d81ceSMarshall Clow
514053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
515dea74b28Szoecarver    size_type find_first_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT
516053d81ceSMarshall Clow    {
517053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr");
518053d81ceSMarshall Clow        return __str_find_first_of<value_type, size_type, traits_type, npos>
519053d81ceSMarshall Clow            (data(), size(), __s, __pos, traits_type::length(__s));
520053d81ceSMarshall Clow    }
521053d81ceSMarshall Clow
522053d81ceSMarshall Clow    // find_last_of
523053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
524053d81ceSMarshall Clow    size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
525053d81ceSMarshall Clow    {
526053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
527053d81ceSMarshall Clow        return __str_find_last_of<value_type, size_type, traits_type, npos>
528053d81ceSMarshall Clow            (data(), size(), __s.data(), __pos, __s.size());
529053d81ceSMarshall Clow    }
530053d81ceSMarshall Clow
531053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
532053d81ceSMarshall Clow    size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT
533053d81ceSMarshall Clow    { return rfind(__c, __pos); }
534053d81ceSMarshall Clow
535053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
536dea74b28Szoecarver    size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
537053d81ceSMarshall Clow    {
538053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
539053d81ceSMarshall Clow        return __str_find_last_of<value_type, size_type, traits_type, npos>
540053d81ceSMarshall Clow            (data(), size(), __s, __pos, __n);
541053d81ceSMarshall Clow    }
542053d81ceSMarshall Clow
543053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
544dea74b28Szoecarver    size_type find_last_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
545053d81ceSMarshall Clow    {
546053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr");
547053d81ceSMarshall Clow        return __str_find_last_of<value_type, size_type, traits_type, npos>
548053d81ceSMarshall Clow            (data(), size(), __s, __pos, traits_type::length(__s));
549053d81ceSMarshall Clow    }
550053d81ceSMarshall Clow
551053d81ceSMarshall Clow    // find_first_not_of
552053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
553053d81ceSMarshall Clow    size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT
554053d81ceSMarshall Clow    {
555053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
556053d81ceSMarshall Clow        return __str_find_first_not_of<value_type, size_type, traits_type, npos>
557053d81ceSMarshall Clow            (data(), size(), __s.data(), __pos, __s.size());
558053d81ceSMarshall Clow    }
559053d81ceSMarshall Clow
560053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
561053d81ceSMarshall Clow    size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT
562053d81ceSMarshall Clow    {
563053d81ceSMarshall Clow        return __str_find_first_not_of<value_type, size_type, traits_type, npos>
564053d81ceSMarshall Clow            (data(), size(), __c, __pos);
565053d81ceSMarshall Clow    }
566053d81ceSMarshall Clow
567053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
568dea74b28Szoecarver    size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
569053d81ceSMarshall Clow    {
570053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
571053d81ceSMarshall Clow        return __str_find_first_not_of<value_type, size_type, traits_type, npos>
572053d81ceSMarshall Clow            (data(), size(), __s, __pos, __n);
573053d81ceSMarshall Clow    }
574053d81ceSMarshall Clow
575053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
576dea74b28Szoecarver    size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT
577053d81ceSMarshall Clow    {
578053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
579053d81ceSMarshall Clow        return __str_find_first_not_of<value_type, size_type, traits_type, npos>
580053d81ceSMarshall Clow            (data(), size(), __s, __pos, traits_type::length(__s));
581053d81ceSMarshall Clow    }
582053d81ceSMarshall Clow
583053d81ceSMarshall Clow    // find_last_not_of
584053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
585053d81ceSMarshall Clow    size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
586053d81ceSMarshall Clow    {
587053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
588053d81ceSMarshall Clow        return __str_find_last_not_of<value_type, size_type, traits_type, npos>
589053d81ceSMarshall Clow            (data(), size(), __s.data(), __pos, __s.size());
590053d81ceSMarshall Clow    }
591053d81ceSMarshall Clow
592053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
593053d81ceSMarshall Clow    size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT
594053d81ceSMarshall Clow    {
595053d81ceSMarshall Clow        return __str_find_last_not_of<value_type, size_type, traits_type, npos>
596053d81ceSMarshall Clow            (data(), size(), __c, __pos);
597053d81ceSMarshall Clow    }
598053d81ceSMarshall Clow
599053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
600dea74b28Szoecarver    size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
601053d81ceSMarshall Clow    {
602053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
603053d81ceSMarshall Clow        return __str_find_last_not_of<value_type, size_type, traits_type, npos>
604053d81ceSMarshall Clow            (data(), size(), __s, __pos, __n);
605053d81ceSMarshall Clow    }
606053d81ceSMarshall Clow
607053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
608dea74b28Szoecarver    size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
609053d81ceSMarshall Clow    {
610053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
611053d81ceSMarshall Clow        return __str_find_last_not_of<value_type, size_type, traits_type, npos>
612053d81ceSMarshall Clow            (data(), size(), __s, __pos, traits_type::length(__s));
613053d81ceSMarshall Clow    }
614053d81ceSMarshall Clow
615800259c9SMarshall Clow#if _LIBCPP_STD_VER > 17
616800259c9SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
617800259c9SMarshall Clow    bool starts_with(basic_string_view __s) const _NOEXCEPT
618800259c9SMarshall Clow    { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; }
619800259c9SMarshall Clow
620800259c9SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
621800259c9SMarshall Clow    bool starts_with(value_type __c) const _NOEXCEPT
622800259c9SMarshall Clow    { return !empty() && _Traits::eq(front(), __c); }
623800259c9SMarshall Clow
624800259c9SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
625800259c9SMarshall Clow    bool starts_with(const value_type* __s) const _NOEXCEPT
626800259c9SMarshall Clow    { return starts_with(basic_string_view(__s)); }
627800259c9SMarshall Clow
628800259c9SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
629800259c9SMarshall Clow    bool ends_with(basic_string_view __s) const _NOEXCEPT
630800259c9SMarshall Clow    { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; }
631800259c9SMarshall Clow
632800259c9SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
633800259c9SMarshall Clow    bool ends_with(value_type __c) const _NOEXCEPT
634800259c9SMarshall Clow    { return !empty() && _Traits::eq(back(), __c); }
635800259c9SMarshall Clow
636800259c9SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
637800259c9SMarshall Clow    bool ends_with(const value_type* __s) const _NOEXCEPT
638800259c9SMarshall Clow    { return ends_with(basic_string_view(__s)); }
639800259c9SMarshall Clow#endif
640800259c9SMarshall Clow
6416ac9cb2aSWim Leflere#if _LIBCPP_STD_VER > 20
6426ac9cb2aSWim Leflere    constexpr _LIBCPP_INLINE_VISIBILITY
6436ac9cb2aSWim Leflere    bool contains(basic_string_view __sv) const noexcept
6446ac9cb2aSWim Leflere    { return find(__sv) != npos; }
6456ac9cb2aSWim Leflere
6466ac9cb2aSWim Leflere    constexpr _LIBCPP_INLINE_VISIBILITY
6476ac9cb2aSWim Leflere    bool contains(value_type __c) const noexcept
6486ac9cb2aSWim Leflere    { return find(__c) != npos; }
6496ac9cb2aSWim Leflere
6506ac9cb2aSWim Leflere    constexpr _LIBCPP_INLINE_VISIBILITY
6516ac9cb2aSWim Leflere    bool contains(const value_type* __s) const
6526ac9cb2aSWim Leflere    { return find(__s) != npos; }
6536ac9cb2aSWim Leflere#endif
6546ac9cb2aSWim Leflere
655053d81ceSMarshall Clowprivate:
656053d81ceSMarshall Clow    const   value_type* __data;
657053d81ceSMarshall Clow    size_type           __size;
658053d81ceSMarshall Clow};
659053d81ceSMarshall Clow
66001ace074SMark de Wever#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
66101ace074SMark de Wevertemplate <class _CharT, class _Traits>
662*462f8f06SChristopher Di Bellainline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true;
663*462f8f06SChristopher Di Bella
664*462f8f06SChristopher Di Bellatemplate <class _CharT, class _Traits>
66501ace074SMark de Weverinline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true;
66601ace074SMark de Wever#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
667053d81ceSMarshall Clow
668053d81ceSMarshall Clow// [string.view.comparison]
669053d81ceSMarshall Clow// operator ==
670053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
671053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
672053d81ceSMarshall Clowbool operator==(basic_string_view<_CharT, _Traits> __lhs,
673053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
674053d81ceSMarshall Clow{
675053d81ceSMarshall Clow    if ( __lhs.size() != __rhs.size()) return false;
676053d81ceSMarshall Clow    return __lhs.compare(__rhs) == 0;
677053d81ceSMarshall Clow}
678053d81ceSMarshall Clow
679053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
680053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
681053d81ceSMarshall Clowbool operator==(basic_string_view<_CharT, _Traits> __lhs,
682053d81ceSMarshall Clow                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
683053d81ceSMarshall Clow{
684053d81ceSMarshall Clow    if ( __lhs.size() != __rhs.size()) return false;
685053d81ceSMarshall Clow    return __lhs.compare(__rhs) == 0;
686053d81ceSMarshall Clow}
687053d81ceSMarshall Clow
688053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
689053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
690053d81ceSMarshall Clowbool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
691053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
692053d81ceSMarshall Clow{
693053d81ceSMarshall Clow    if ( __lhs.size() != __rhs.size()) return false;
694053d81ceSMarshall Clow    return __lhs.compare(__rhs) == 0;
695053d81ceSMarshall Clow}
696053d81ceSMarshall Clow
697053d81ceSMarshall Clow
698053d81ceSMarshall Clow// operator !=
699053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
700053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
701053d81ceSMarshall Clowbool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
702053d81ceSMarshall Clow{
703053d81ceSMarshall Clow    if ( __lhs.size() != __rhs.size())
704053d81ceSMarshall Clow        return true;
705053d81ceSMarshall Clow    return __lhs.compare(__rhs) != 0;
706053d81ceSMarshall Clow}
707053d81ceSMarshall Clow
708053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
709053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
710053d81ceSMarshall Clowbool operator!=(basic_string_view<_CharT, _Traits> __lhs,
711053d81ceSMarshall Clow                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
712053d81ceSMarshall Clow{
713053d81ceSMarshall Clow    if ( __lhs.size() != __rhs.size())
714053d81ceSMarshall Clow        return true;
715053d81ceSMarshall Clow    return __lhs.compare(__rhs) != 0;
716053d81ceSMarshall Clow}
717053d81ceSMarshall Clow
718053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
719053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
720053d81ceSMarshall Clowbool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
721053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
722053d81ceSMarshall Clow{
723053d81ceSMarshall Clow    if ( __lhs.size() != __rhs.size())
724053d81ceSMarshall Clow        return true;
725053d81ceSMarshall Clow    return __lhs.compare(__rhs) != 0;
726053d81ceSMarshall Clow}
727053d81ceSMarshall Clow
728053d81ceSMarshall Clow
729053d81ceSMarshall Clow// operator <
730053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
731053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
732053d81ceSMarshall Clowbool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
733053d81ceSMarshall Clow{
734053d81ceSMarshall Clow    return __lhs.compare(__rhs) < 0;
735053d81ceSMarshall Clow}
736053d81ceSMarshall Clow
737053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
738053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
739053d81ceSMarshall Clowbool operator<(basic_string_view<_CharT, _Traits> __lhs,
740053d81ceSMarshall Clow                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
741053d81ceSMarshall Clow{
742053d81ceSMarshall Clow    return __lhs.compare(__rhs) < 0;
743053d81ceSMarshall Clow}
744053d81ceSMarshall Clow
745053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
746053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
747053d81ceSMarshall Clowbool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
748053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
749053d81ceSMarshall Clow{
750053d81ceSMarshall Clow    return __lhs.compare(__rhs) < 0;
751053d81ceSMarshall Clow}
752053d81ceSMarshall Clow
753053d81ceSMarshall Clow
754053d81ceSMarshall Clow// operator >
755053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
756053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
757053d81ceSMarshall Clowbool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
758053d81ceSMarshall Clow{
759053d81ceSMarshall Clow    return __lhs.compare(__rhs) > 0;
760053d81ceSMarshall Clow}
761053d81ceSMarshall Clow
762053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
763053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
764053d81ceSMarshall Clowbool operator>(basic_string_view<_CharT, _Traits> __lhs,
765053d81ceSMarshall Clow                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
766053d81ceSMarshall Clow{
767053d81ceSMarshall Clow    return __lhs.compare(__rhs) > 0;
768053d81ceSMarshall Clow}
769053d81ceSMarshall Clow
770053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
771053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
772053d81ceSMarshall Clowbool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
773053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
774053d81ceSMarshall Clow{
775053d81ceSMarshall Clow    return __lhs.compare(__rhs) > 0;
776053d81ceSMarshall Clow}
777053d81ceSMarshall Clow
778053d81ceSMarshall Clow
779053d81ceSMarshall Clow// operator <=
780053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
781053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
782053d81ceSMarshall Clowbool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
783053d81ceSMarshall Clow{
784053d81ceSMarshall Clow    return __lhs.compare(__rhs) <= 0;
785053d81ceSMarshall Clow}
786053d81ceSMarshall Clow
787053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
788053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
789053d81ceSMarshall Clowbool operator<=(basic_string_view<_CharT, _Traits> __lhs,
790053d81ceSMarshall Clow                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
791053d81ceSMarshall Clow{
792053d81ceSMarshall Clow    return __lhs.compare(__rhs) <= 0;
793053d81ceSMarshall Clow}
794053d81ceSMarshall Clow
795053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
796053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
797053d81ceSMarshall Clowbool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
798053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
799053d81ceSMarshall Clow{
800053d81ceSMarshall Clow    return __lhs.compare(__rhs) <= 0;
801053d81ceSMarshall Clow}
802053d81ceSMarshall Clow
803053d81ceSMarshall Clow
804053d81ceSMarshall Clow// operator >=
805053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
806053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
807053d81ceSMarshall Clowbool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
808053d81ceSMarshall Clow{
809053d81ceSMarshall Clow    return __lhs.compare(__rhs) >= 0;
810053d81ceSMarshall Clow}
811053d81ceSMarshall Clow
812053d81ceSMarshall Clow
813053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
814053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
815053d81ceSMarshall Clowbool operator>=(basic_string_view<_CharT, _Traits> __lhs,
816053d81ceSMarshall Clow                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
817053d81ceSMarshall Clow{
818053d81ceSMarshall Clow    return __lhs.compare(__rhs) >= 0;
819053d81ceSMarshall Clow}
820053d81ceSMarshall Clow
821053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
822053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
823053d81ceSMarshall Clowbool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
824053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
825053d81ceSMarshall Clow{
826053d81ceSMarshall Clow    return __lhs.compare(__rhs) >= 0;
827053d81ceSMarshall Clow}
828053d81ceSMarshall Clow
829af4a29afSEric Fiselier
830af4a29afSEric Fiseliertemplate<class _CharT, class _Traits>
831af4a29afSEric Fiselierbasic_ostream<_CharT, _Traits>&
832af4a29afSEric Fiselieroperator<<(basic_ostream<_CharT, _Traits>& __os,
833af4a29afSEric Fiselier           basic_string_view<_CharT, _Traits> __str);
834af4a29afSEric Fiselier
835053d81ceSMarshall Clow// [string.view.hash]
83693184302SMarshall Clowtemplate<class _CharT>
83793184302SMarshall Clowstruct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, char_traits<_CharT> > >
83893184302SMarshall Clow    : public unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t>
839053d81ceSMarshall Clow{
840a86710f1SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
84193184302SMarshall Clow    size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT {
842053d81ceSMarshall Clow        return __do_string_hash(__val.data(), __val.data() + __val.size());
843053d81ceSMarshall Clow    }
844a86710f1SLouis Dionne};
845053d81ceSMarshall Clow
8468fd58a6bSMarshall Clow
8478fd58a6bSMarshall Clow#if _LIBCPP_STD_VER > 11
8488fd58a6bSMarshall Clowinline namespace literals
8498fd58a6bSMarshall Clow{
8508fd58a6bSMarshall Clow  inline namespace string_view_literals
8518fd58a6bSMarshall Clow  {
8528fd58a6bSMarshall Clow    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
85359b48302SMarshall Clow    basic_string_view<char> operator "" sv(const char *__str, size_t __len) _NOEXCEPT
8548fd58a6bSMarshall Clow    {
8558fd58a6bSMarshall Clow        return basic_string_view<char> (__str, __len);
8568fd58a6bSMarshall Clow    }
8578fd58a6bSMarshall Clow
8588fd58a6bSMarshall Clow    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
85959b48302SMarshall Clow    basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT
8608fd58a6bSMarshall Clow    {
8618fd58a6bSMarshall Clow        return basic_string_view<wchar_t> (__str, __len);
8628fd58a6bSMarshall Clow    }
8638fd58a6bSMarshall Clow
8645c40c994SArthur O'Dwyer#ifndef _LIBCPP_HAS_NO_CHAR8_T
8657dad0bd6SMarshall Clow    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
8667dad0bd6SMarshall Clow    basic_string_view<char8_t> operator "" sv(const char8_t *__str, size_t __len) _NOEXCEPT
8677dad0bd6SMarshall Clow    {
8687dad0bd6SMarshall Clow        return basic_string_view<char8_t> (__str, __len);
8697dad0bd6SMarshall Clow    }
8707dad0bd6SMarshall Clow#endif
8717dad0bd6SMarshall Clow
8728fd58a6bSMarshall Clow    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
87359b48302SMarshall Clow    basic_string_view<char16_t> operator "" sv(const char16_t *__str, size_t __len) _NOEXCEPT
8748fd58a6bSMarshall Clow    {
8758fd58a6bSMarshall Clow        return basic_string_view<char16_t> (__str, __len);
8768fd58a6bSMarshall Clow    }
8778fd58a6bSMarshall Clow
8788fd58a6bSMarshall Clow    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
87959b48302SMarshall Clow    basic_string_view<char32_t> operator "" sv(const char32_t *__str, size_t __len) _NOEXCEPT
8808fd58a6bSMarshall Clow    {
8818fd58a6bSMarshall Clow        return basic_string_view<char32_t> (__str, __len);
8828fd58a6bSMarshall Clow    }
8838fd58a6bSMarshall Clow  }
8848fd58a6bSMarshall Clow}
8858fd58a6bSMarshall Clow#endif
886053d81ceSMarshall Clow_LIBCPP_END_NAMESPACE_STD
887053d81ceSMarshall Clow
888a016efb1SEric Fiselier_LIBCPP_POP_MACROS
889a016efb1SEric Fiselier
890053d81ceSMarshall Clow#endif // _LIBCPP_STRING_VIEW
891