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
22053d81ceSMarshall Clow    // 7.9, basic_string_view non-member comparison functions
23053d81ceSMarshall Clow    template<class charT, class traits>
24053d81ceSMarshall Clow    constexpr bool operator==(basic_string_view<charT, traits> x,
25053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
26053d81ceSMarshall Clow    template<class charT, class traits>
27053d81ceSMarshall Clow    constexpr bool operator!=(basic_string_view<charT, traits> x,
28053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
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    // see below, sufficient additional overloads of comparison functions
42053d81ceSMarshall Clow
43053d81ceSMarshall Clow    // 7.10, Inserters and extractors
44053d81ceSMarshall Clow    template<class charT, class traits>
45053d81ceSMarshall Clow      basic_ostream<charT, traits>&
46053d81ceSMarshall Clow        operator<<(basic_ostream<charT, traits>& os,
47053d81ceSMarshall Clow                   basic_string_view<charT, traits> str);
48053d81ceSMarshall Clow
49053d81ceSMarshall Clow    // basic_string_view typedef names
50053d81ceSMarshall Clow    typedef basic_string_view<char> string_view;
51053d81ceSMarshall Clow    typedef basic_string_view<char16_t> u16string_view;
52053d81ceSMarshall Clow    typedef basic_string_view<char32_t> u32string_view;
53053d81ceSMarshall Clow    typedef basic_string_view<wchar_t> wstring_view;
54053d81ceSMarshall Clow
55053d81ceSMarshall Clow    template<class charT, class traits = char_traits<charT>>
56053d81ceSMarshall Clow    class basic_string_view {
57053d81ceSMarshall Clow      public:
58053d81ceSMarshall Clow      // types
59053d81ceSMarshall Clow      typedef traits traits_type;
60053d81ceSMarshall Clow      typedef charT value_type;
61053d81ceSMarshall Clow      typedef charT* pointer;
62053d81ceSMarshall Clow      typedef const charT* const_pointer;
63053d81ceSMarshall Clow      typedef charT& reference;
64053d81ceSMarshall Clow      typedef const charT& const_reference;
65053d81ceSMarshall Clow      typedef implementation-defined const_iterator;
66053d81ceSMarshall Clow      typedef const_iterator iterator;
67053d81ceSMarshall Clow      typedef reverse_iterator<const_iterator> const_reverse_iterator;
68053d81ceSMarshall Clow      typedef const_reverse_iterator reverse_iterator;
69053d81ceSMarshall Clow      typedef size_t size_type;
70053d81ceSMarshall Clow      typedef ptrdiff_t difference_type;
71053d81ceSMarshall Clow      static constexpr size_type npos = size_type(-1);
72053d81ceSMarshall Clow
73053d81ceSMarshall Clow      // 7.3, basic_string_view constructors and assignment operators
74053d81ceSMarshall Clow      constexpr basic_string_view() noexcept;
75053d81ceSMarshall Clow      constexpr basic_string_view(const basic_string_view&) noexcept = default;
76053d81ceSMarshall Clow      basic_string_view& operator=(const basic_string_view&) noexcept = default;
77053d81ceSMarshall Clow      template<class Allocator>
78053d81ceSMarshall Clow      constexpr basic_string_view(const charT* str);
79053d81ceSMarshall Clow      constexpr basic_string_view(const charT* str, size_type len);
80053d81ceSMarshall Clow
81053d81ceSMarshall Clow      // 7.4, basic_string_view iterator support
82053d81ceSMarshall Clow      constexpr const_iterator begin() const noexcept;
83053d81ceSMarshall Clow      constexpr const_iterator end() const noexcept;
84053d81ceSMarshall Clow      constexpr const_iterator cbegin() const noexcept;
85053d81ceSMarshall Clow      constexpr const_iterator cend() const noexcept;
86053d81ceSMarshall Clow      const_reverse_iterator rbegin() const noexcept;
87053d81ceSMarshall Clow      const_reverse_iterator rend() const noexcept;
88053d81ceSMarshall Clow      const_reverse_iterator crbegin() const noexcept;
89053d81ceSMarshall Clow      const_reverse_iterator crend() const noexcept;
90053d81ceSMarshall Clow
91053d81ceSMarshall Clow      // 7.5, basic_string_view capacity
92053d81ceSMarshall Clow      constexpr size_type size() const noexcept;
93053d81ceSMarshall Clow      constexpr size_type length() const noexcept;
94053d81ceSMarshall Clow      constexpr size_type max_size() const noexcept;
95053d81ceSMarshall Clow      constexpr bool empty() const noexcept;
96053d81ceSMarshall Clow
97053d81ceSMarshall Clow      // 7.6, basic_string_view element access
98053d81ceSMarshall Clow      constexpr const_reference operator[](size_type pos) const;
99053d81ceSMarshall Clow      constexpr const_reference at(size_type pos) const;
100053d81ceSMarshall Clow      constexpr const_reference front() const;
101053d81ceSMarshall Clow      constexpr const_reference back() const;
102053d81ceSMarshall Clow      constexpr const_pointer data() const noexcept;
103053d81ceSMarshall Clow
104053d81ceSMarshall Clow      // 7.7, basic_string_view modifiers
105053d81ceSMarshall Clow      constexpr void remove_prefix(size_type n);
106053d81ceSMarshall Clow      constexpr void remove_suffix(size_type n);
107053d81ceSMarshall Clow      constexpr void swap(basic_string_view& s) noexcept;
108053d81ceSMarshall Clow
109053d81ceSMarshall Clow      size_type copy(charT* s, size_type n, size_type pos = 0) const;
110053d81ceSMarshall Clow
111053d81ceSMarshall Clow      constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
112053d81ceSMarshall Clow      constexpr int compare(basic_string_view s) const noexcept;
113053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
114053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1,
115053d81ceSMarshall Clow                            basic_string_view s, size_type pos2, size_type n2) const;
116053d81ceSMarshall Clow      constexpr int compare(const charT* s) const;
117053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
118053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1,
119053d81ceSMarshall Clow                            const charT* s, size_type n2) const;
120053d81ceSMarshall Clow      constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
121053d81ceSMarshall Clow      constexpr size_type find(charT c, size_type pos = 0) const noexcept;
122053d81ceSMarshall Clow      constexpr size_type find(const charT* s, size_type pos, size_type n) const;
123053d81ceSMarshall Clow      constexpr size_type find(const charT* s, size_type pos = 0) const;
124053d81ceSMarshall Clow      constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
125053d81ceSMarshall Clow      constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
126053d81ceSMarshall Clow      constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
127053d81ceSMarshall Clow      constexpr size_type rfind(const charT* s, size_type pos = npos) const;
128053d81ceSMarshall Clow      constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
129053d81ceSMarshall Clow      constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
130053d81ceSMarshall Clow      constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
131053d81ceSMarshall Clow      constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
132053d81ceSMarshall Clow      constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
133053d81ceSMarshall Clow      constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
134053d81ceSMarshall Clow      constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const;
135053d81ceSMarshall Clow      constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;
136053d81ceSMarshall Clow      constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
137053d81ceSMarshall Clow      constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
138053d81ceSMarshall Clow      constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
139053d81ceSMarshall Clow      constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const;
140053d81ceSMarshall Clow      constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
141053d81ceSMarshall Clow      constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
142053d81ceSMarshall Clow      constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
143053d81ceSMarshall Clow      constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
144053d81ceSMarshall Clow
145800259c9SMarshall Clow      constexpr bool starts_with(basic_string_view s) const noexcept; // C++2a
146800259c9SMarshall Clow      constexpr bool starts_with(charT c) const noexcept;             // C++2a
147800259c9SMarshall Clow      constexpr bool starts_with(const charT* s) const;               // C++2a
148800259c9SMarshall Clow      constexpr bool ends_with(basic_string_view s) const noexcept;   // C++2a
149800259c9SMarshall Clow      constexpr bool ends_with(charT c) const noexcept;               // C++2a
150800259c9SMarshall Clow      constexpr bool ends_with(const charT* s) const;                 // C++2a
151800259c9SMarshall Clow
152053d81ceSMarshall Clow     private:
153053d81ceSMarshall Clow      const_pointer data_;  // exposition only
154053d81ceSMarshall Clow      size_type     size_;  // exposition only
155053d81ceSMarshall Clow    };
156053d81ceSMarshall Clow
157053d81ceSMarshall Clow  // 7.11, Hash support
158053d81ceSMarshall Clow  template <class T> struct hash;
159053d81ceSMarshall Clow  template <> struct hash<string_view>;
160053d81ceSMarshall Clow  template <> struct hash<u16string_view>;
161053d81ceSMarshall Clow  template <> struct hash<u32string_view>;
162053d81ceSMarshall Clow  template <> struct hash<wstring_view>;
163053d81ceSMarshall Clow
16459b48302SMarshall Clow  constexpr basic_string_view<char>     operator "" sv( const char *str,     size_t len ) noexcept;
16559b48302SMarshall Clow  constexpr basic_string_view<wchar_t>  operator "" sv( const wchar_t *str,  size_t len ) noexcept;
16659b48302SMarshall Clow  constexpr basic_string_view<char16_t> operator "" sv( const char16_t *str, size_t len ) noexcept;
16759b48302SMarshall Clow  constexpr basic_string_view<char32_t> operator "" sv( const char32_t *str, size_t len ) noexcept;
1688fd58a6bSMarshall Clow
169053d81ceSMarshall Clow}  // namespace std
170053d81ceSMarshall Clow
171053d81ceSMarshall Clow
172053d81ceSMarshall Clow*/
173053d81ceSMarshall Clow
174053d81ceSMarshall Clow#include <__config>
175053d81ceSMarshall Clow#include <__string>
176ca648c97SEric Fiselier#include <algorithm>
177053d81ceSMarshall Clow#include <iterator>
178ca648c97SEric Fiselier#include <limits>
179ca648c97SEric Fiselier#include <stdexcept>
180f56972e2SMarshall Clow#include <version>
181053d81ceSMarshall Clow#include <__debug>
182053d81ceSMarshall Clow
183053d81ceSMarshall Clow#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
184053d81ceSMarshall Clow#pragma GCC system_header
185053d81ceSMarshall Clow#endif
186053d81ceSMarshall Clow
187a016efb1SEric Fiselier_LIBCPP_PUSH_MACROS
188a016efb1SEric Fiselier#include <__undef_macros>
189a016efb1SEric Fiselier
190a016efb1SEric Fiselier
191053d81ceSMarshall Clow_LIBCPP_BEGIN_NAMESPACE_STD
192053d81ceSMarshall Clow
193053d81ceSMarshall Clowtemplate<class _CharT, class _Traits = char_traits<_CharT> >
194e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS basic_string_view {
195053d81ceSMarshall Clowpublic:
196053d81ceSMarshall Clow    // types
197053d81ceSMarshall Clow    typedef _Traits                                    traits_type;
198053d81ceSMarshall Clow    typedef _CharT                                     value_type;
1997d661bb2SMarshall Clow    typedef _CharT*                                    pointer;
200053d81ceSMarshall Clow    typedef const _CharT*                              const_pointer;
2017d661bb2SMarshall Clow    typedef _CharT&                                    reference;
202053d81ceSMarshall Clow    typedef const _CharT&                              const_reference;
203053d81ceSMarshall Clow    typedef const_pointer                              const_iterator; // See [string.view.iterators]
204053d81ceSMarshall Clow    typedef const_iterator                             iterator;
205053d81ceSMarshall Clow    typedef _VSTD::reverse_iterator<const_iterator>    const_reverse_iterator;
206053d81ceSMarshall Clow    typedef const_reverse_iterator                     reverse_iterator;
207053d81ceSMarshall Clow    typedef size_t                                     size_type;
208053d81ceSMarshall Clow    typedef ptrdiff_t                                  difference_type;
209053d81ceSMarshall Clow    static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
210053d81ceSMarshall Clow
2114a6f3c47SMarshall Clow    static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array");
2124a6f3c47SMarshall Clow    static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout");
2134a6f3c47SMarshall Clow    static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial");
2144069c2bcSMarshall Clow    static_assert((is_same<_CharT, typename traits_type::char_type>::value),
2154069c2bcSMarshall Clow                  "traits_type::char_type must be the same type as CharT");
2164069c2bcSMarshall Clow
217053d81ceSMarshall Clow    // [string.view.cons], construct/copy
218053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
219053d81ceSMarshall Clow    basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {}
220053d81ceSMarshall Clow
221053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
222053d81ceSMarshall Clow    basic_string_view(const basic_string_view&) _NOEXCEPT = default;
223053d81ceSMarshall Clow
224cddeb751SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
225053d81ceSMarshall Clow    basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
226053d81ceSMarshall Clow
227053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
228ac2b3e3aSMarshall Clow    basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
229053d81ceSMarshall Clow        : __data(__s), __size(__len)
230053d81ceSMarshall Clow    {
231f67524d4SMarshall Clow#if _LIBCPP_STD_VER > 11
232f67524d4SMarshall Clow    _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
233f67524d4SMarshall Clow#endif
234053d81ceSMarshall Clow    }
235053d81ceSMarshall Clow
236053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
237053d81ceSMarshall Clow    basic_string_view(const _CharT* __s)
238*6bc1236dSEric Fiselier        : __data(__s), __size(std::__char_traits_length_checked<_Traits>(__s)) {}
239053d81ceSMarshall Clow
240053d81ceSMarshall Clow    // [string.view.iterators], iterators
241053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
242053d81ceSMarshall Clow    const_iterator begin()  const _NOEXCEPT { return cbegin(); }
243053d81ceSMarshall Clow
244053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
245053d81ceSMarshall Clow    const_iterator end()    const _NOEXCEPT { return cend(); }
246053d81ceSMarshall Clow
247053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
248053d81ceSMarshall Clow    const_iterator cbegin() const _NOEXCEPT { return __data; }
249053d81ceSMarshall Clow
250053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
251053d81ceSMarshall Clow    const_iterator cend()   const _NOEXCEPT { return __data + __size; }
252053d81ceSMarshall Clow
253cddeb751SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
254053d81ceSMarshall Clow    const_reverse_iterator rbegin()   const _NOEXCEPT { return const_reverse_iterator(cend()); }
255053d81ceSMarshall Clow
256cddeb751SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
257053d81ceSMarshall Clow    const_reverse_iterator rend()     const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
258053d81ceSMarshall Clow
259cddeb751SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
260053d81ceSMarshall Clow    const_reverse_iterator crbegin()  const _NOEXCEPT { return const_reverse_iterator(cend()); }
261053d81ceSMarshall Clow
262cddeb751SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
263053d81ceSMarshall Clow    const_reverse_iterator crend()    const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
264053d81ceSMarshall Clow
265053d81ceSMarshall Clow    // [string.view.capacity], capacity
266053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
267053d81ceSMarshall Clow    size_type size()     const _NOEXCEPT { return __size; }
268053d81ceSMarshall Clow
269053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
270053d81ceSMarshall Clow    size_type length()   const _NOEXCEPT { return __size; }
271053d81ceSMarshall Clow
272053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
273053d81ceSMarshall Clow    size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max(); }
274053d81ceSMarshall Clow
27525a7ba45SMarshall Clow    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
27625a7ba45SMarshall Clow    bool empty()         const _NOEXCEPT { return __size == 0; }
277053d81ceSMarshall Clow
278053d81ceSMarshall Clow    // [string.view.access], element access
279053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
280053d81ceSMarshall Clow    const_reference operator[](size_type __pos) const _NOEXCEPT { return __data[__pos]; }
281053d81ceSMarshall Clow
282053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
283053d81ceSMarshall Clow    const_reference at(size_type __pos) const
284053d81ceSMarshall Clow    {
285053d81ceSMarshall Clow        return __pos >= size()
2860fc8cec7SMarshall Clow            ? (__throw_out_of_range("string_view::at"), __data[0])
287053d81ceSMarshall Clow            : __data[__pos];
288053d81ceSMarshall Clow    }
289053d81ceSMarshall Clow
290053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
2919ea0e473SMarshall Clow    const_reference front() const _NOEXCEPT
292053d81ceSMarshall Clow    {
293053d81ceSMarshall Clow        return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0];
294053d81ceSMarshall Clow    }
295053d81ceSMarshall Clow
296053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
2979ea0e473SMarshall Clow    const_reference back() const _NOEXCEPT
298053d81ceSMarshall Clow    {
299053d81ceSMarshall Clow        return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1];
300053d81ceSMarshall Clow    }
301053d81ceSMarshall Clow
302053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
303053d81ceSMarshall Clow    const_pointer data() const _NOEXCEPT { return __data; }
304053d81ceSMarshall Clow
305053d81ceSMarshall Clow    // [string.view.modifiers], modifiers:
306053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
307053d81ceSMarshall Clow    void remove_prefix(size_type __n) _NOEXCEPT
308053d81ceSMarshall Clow    {
309053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()");
310053d81ceSMarshall Clow        __data += __n;
311053d81ceSMarshall Clow        __size -= __n;
312053d81ceSMarshall Clow    }
313053d81ceSMarshall Clow
314053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
315053d81ceSMarshall Clow    void remove_suffix(size_type __n) _NOEXCEPT
316053d81ceSMarshall Clow    {
317053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()");
318053d81ceSMarshall Clow        __size -= __n;
319053d81ceSMarshall Clow    }
320053d81ceSMarshall Clow
321053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
322053d81ceSMarshall Clow    void swap(basic_string_view& __other) _NOEXCEPT
323053d81ceSMarshall Clow    {
324053d81ceSMarshall Clow        const value_type *__p = __data;
325053d81ceSMarshall Clow        __data = __other.__data;
326053d81ceSMarshall Clow        __other.__data = __p;
327053d81ceSMarshall Clow
328053d81ceSMarshall Clow        size_type __sz = __size;
329053d81ceSMarshall Clow        __size = __other.__size;
330053d81ceSMarshall Clow        __other.__size = __sz;
331053d81ceSMarshall Clow    }
332053d81ceSMarshall Clow
333053d81ceSMarshall Clow    _LIBCPP_INLINE_VISIBILITY
334053d81ceSMarshall Clow    size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const
335053d81ceSMarshall Clow    {
336053d81ceSMarshall Clow        if (__pos > size())
3370fc8cec7SMarshall Clow            __throw_out_of_range("string_view::copy");
338053d81ceSMarshall Clow        size_type __rlen = _VSTD::min(__n, size() - __pos);
3391c7fe126SMarshall Clow        _Traits::copy(__s, data() + __pos, __rlen);
340053d81ceSMarshall Clow        return __rlen;
341053d81ceSMarshall Clow    }
342053d81ceSMarshall Clow
343053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
344053d81ceSMarshall Clow    basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
345053d81ceSMarshall Clow    {
346053d81ceSMarshall Clow        return __pos > size()
3470fc8cec7SMarshall Clow            ? (__throw_out_of_range("string_view::substr"), basic_string_view())
348053d81ceSMarshall Clow            : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos));
349053d81ceSMarshall Clow    }
350053d81ceSMarshall Clow
351053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT
352053d81ceSMarshall Clow    {
353053d81ceSMarshall Clow        size_type __rlen = _VSTD::min( size(), __sv.size());
354053d81ceSMarshall Clow        int __retval = _Traits::compare(data(), __sv.data(), __rlen);
355053d81ceSMarshall Clow        if ( __retval == 0 ) // first __rlen chars matched
356053d81ceSMarshall Clow            __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 );
357053d81ceSMarshall Clow        return __retval;
358053d81ceSMarshall Clow    }
359053d81ceSMarshall Clow
360053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
361053d81ceSMarshall Clow    int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const
362053d81ceSMarshall Clow    {
363053d81ceSMarshall Clow        return substr(__pos1, __n1).compare(__sv);
364053d81ceSMarshall Clow    }
365053d81ceSMarshall Clow
366053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
367053d81ceSMarshall Clow    int compare(                       size_type __pos1, size_type __n1,
3689ffacf3dSEric Fiselier                basic_string_view __sv, size_type __pos2, size_type __n2) const
369053d81ceSMarshall Clow    {
3709ffacf3dSEric Fiselier        return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
371053d81ceSMarshall Clow    }
372053d81ceSMarshall Clow
373053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
374aa849bc2SMarshall Clow    int compare(const _CharT* __s) const _NOEXCEPT
375053d81ceSMarshall Clow    {
376053d81ceSMarshall Clow        return compare(basic_string_view(__s));
377053d81ceSMarshall Clow    }
378053d81ceSMarshall Clow
379053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
380053d81ceSMarshall Clow    int compare(size_type __pos1, size_type __n1, const _CharT* __s) const
381053d81ceSMarshall Clow    {
382053d81ceSMarshall Clow        return substr(__pos1, __n1).compare(basic_string_view(__s));
383053d81ceSMarshall Clow    }
384053d81ceSMarshall Clow
385053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
386053d81ceSMarshall Clow    int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
387053d81ceSMarshall Clow    {
388053d81ceSMarshall Clow        return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
389053d81ceSMarshall Clow    }
390053d81ceSMarshall Clow
391053d81ceSMarshall Clow    // find
392053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
393053d81ceSMarshall Clow    size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
394053d81ceSMarshall Clow    {
395053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
396053d81ceSMarshall Clow        return __str_find<value_type, size_type, traits_type, npos>
397053d81ceSMarshall Clow            (data(), size(), __s.data(), __pos, __s.size());
398053d81ceSMarshall Clow    }
399053d81ceSMarshall Clow
400053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
401053d81ceSMarshall Clow    size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT
402053d81ceSMarshall Clow    {
403053d81ceSMarshall Clow        return __str_find<value_type, size_type, traits_type, npos>
404053d81ceSMarshall Clow            (data(), size(), __c, __pos);
405053d81ceSMarshall Clow    }
406053d81ceSMarshall Clow
407053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
408053d81ceSMarshall Clow    size_type find(const _CharT* __s, size_type __pos, size_type __n) const
409053d81ceSMarshall Clow    {
410053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
411053d81ceSMarshall Clow        return __str_find<value_type, size_type, traits_type, npos>
412053d81ceSMarshall Clow            (data(), size(), __s, __pos, __n);
413053d81ceSMarshall Clow    }
414053d81ceSMarshall Clow
415053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
416053d81ceSMarshall Clow    size_type find(const _CharT* __s, size_type __pos = 0) const
417053d81ceSMarshall Clow    {
418053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr");
419053d81ceSMarshall Clow        return __str_find<value_type, size_type, traits_type, npos>
420053d81ceSMarshall Clow            (data(), size(), __s, __pos, traits_type::length(__s));
421053d81ceSMarshall Clow    }
422053d81ceSMarshall Clow
423053d81ceSMarshall Clow    // rfind
424053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
425053d81ceSMarshall Clow    size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT
426053d81ceSMarshall Clow    {
427053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
428053d81ceSMarshall Clow        return __str_rfind<value_type, size_type, traits_type, npos>
429053d81ceSMarshall Clow            (data(), size(), __s.data(), __pos, __s.size());
430053d81ceSMarshall Clow    }
431053d81ceSMarshall Clow
432053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
433053d81ceSMarshall Clow    size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT
434053d81ceSMarshall Clow    {
435053d81ceSMarshall Clow        return __str_rfind<value_type, size_type, traits_type, npos>
436053d81ceSMarshall Clow            (data(), size(), __c, __pos);
437053d81ceSMarshall Clow    }
438053d81ceSMarshall Clow
439053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
440053d81ceSMarshall Clow    size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const
441053d81ceSMarshall Clow    {
442053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
443053d81ceSMarshall Clow        return __str_rfind<value_type, size_type, traits_type, npos>
444053d81ceSMarshall Clow            (data(), size(), __s, __pos, __n);
445053d81ceSMarshall Clow    }
446053d81ceSMarshall Clow
447053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
448053d81ceSMarshall Clow    size_type rfind(const _CharT* __s, size_type __pos=npos) const
449053d81ceSMarshall Clow    {
450053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr");
451053d81ceSMarshall Clow        return __str_rfind<value_type, size_type, traits_type, npos>
452053d81ceSMarshall Clow            (data(), size(), __s, __pos, traits_type::length(__s));
453053d81ceSMarshall Clow    }
454053d81ceSMarshall Clow
455053d81ceSMarshall Clow    // find_first_of
456053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
457053d81ceSMarshall Clow    size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
458053d81ceSMarshall Clow    {
459053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
460053d81ceSMarshall Clow        return __str_find_first_of<value_type, size_type, traits_type, npos>
461053d81ceSMarshall Clow            (data(), size(), __s.data(), __pos, __s.size());
462053d81ceSMarshall Clow    }
463053d81ceSMarshall Clow
464053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
465053d81ceSMarshall Clow    size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT
466053d81ceSMarshall Clow    { return find(__c, __pos); }
467053d81ceSMarshall Clow
468053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
469053d81ceSMarshall Clow    size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
470053d81ceSMarshall Clow    {
471053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
472053d81ceSMarshall Clow        return __str_find_first_of<value_type, size_type, traits_type, npos>
473053d81ceSMarshall Clow            (data(), size(), __s, __pos, __n);
474053d81ceSMarshall Clow    }
475053d81ceSMarshall Clow
476053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
477053d81ceSMarshall Clow    size_type find_first_of(const _CharT* __s, size_type __pos=0) const
478053d81ceSMarshall Clow    {
479053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr");
480053d81ceSMarshall Clow        return __str_find_first_of<value_type, size_type, traits_type, npos>
481053d81ceSMarshall Clow            (data(), size(), __s, __pos, traits_type::length(__s));
482053d81ceSMarshall Clow    }
483053d81ceSMarshall Clow
484053d81ceSMarshall Clow    // find_last_of
485053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
486053d81ceSMarshall Clow    size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
487053d81ceSMarshall Clow    {
488053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
489053d81ceSMarshall Clow        return __str_find_last_of<value_type, size_type, traits_type, npos>
490053d81ceSMarshall Clow            (data(), size(), __s.data(), __pos, __s.size());
491053d81ceSMarshall Clow    }
492053d81ceSMarshall Clow
493053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
494053d81ceSMarshall Clow    size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT
495053d81ceSMarshall Clow    { return rfind(__c, __pos); }
496053d81ceSMarshall Clow
497053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
498053d81ceSMarshall Clow    size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
499053d81ceSMarshall Clow    {
500053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
501053d81ceSMarshall Clow        return __str_find_last_of<value_type, size_type, traits_type, npos>
502053d81ceSMarshall Clow            (data(), size(), __s, __pos, __n);
503053d81ceSMarshall Clow    }
504053d81ceSMarshall Clow
505053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
506053d81ceSMarshall Clow    size_type find_last_of(const _CharT* __s, size_type __pos=npos) const
507053d81ceSMarshall Clow    {
508053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr");
509053d81ceSMarshall Clow        return __str_find_last_of<value_type, size_type, traits_type, npos>
510053d81ceSMarshall Clow            (data(), size(), __s, __pos, traits_type::length(__s));
511053d81ceSMarshall Clow    }
512053d81ceSMarshall Clow
513053d81ceSMarshall Clow    // find_first_not_of
514053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
515053d81ceSMarshall Clow    size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT
516053d81ceSMarshall Clow    {
517053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
518053d81ceSMarshall Clow        return __str_find_first_not_of<value_type, size_type, traits_type, npos>
519053d81ceSMarshall Clow            (data(), size(), __s.data(), __pos, __s.size());
520053d81ceSMarshall Clow    }
521053d81ceSMarshall Clow
522053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
523053d81ceSMarshall Clow    size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT
524053d81ceSMarshall Clow    {
525053d81ceSMarshall Clow        return __str_find_first_not_of<value_type, size_type, traits_type, npos>
526053d81ceSMarshall Clow            (data(), size(), __c, __pos);
527053d81ceSMarshall Clow    }
528053d81ceSMarshall Clow
529053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
530053d81ceSMarshall Clow    size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
531053d81ceSMarshall Clow    {
532053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
533053d81ceSMarshall Clow        return __str_find_first_not_of<value_type, size_type, traits_type, npos>
534053d81ceSMarshall Clow            (data(), size(), __s, __pos, __n);
535053d81ceSMarshall Clow    }
536053d81ceSMarshall Clow
537053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
538053d81ceSMarshall Clow    size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const
539053d81ceSMarshall Clow    {
540053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
541053d81ceSMarshall Clow        return __str_find_first_not_of<value_type, size_type, traits_type, npos>
542053d81ceSMarshall Clow            (data(), size(), __s, __pos, traits_type::length(__s));
543053d81ceSMarshall Clow    }
544053d81ceSMarshall Clow
545053d81ceSMarshall Clow    // find_last_not_of
546053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
547053d81ceSMarshall Clow    size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
548053d81ceSMarshall Clow    {
549053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
550053d81ceSMarshall Clow        return __str_find_last_not_of<value_type, size_type, traits_type, npos>
551053d81ceSMarshall Clow            (data(), size(), __s.data(), __pos, __s.size());
552053d81ceSMarshall Clow    }
553053d81ceSMarshall Clow
554053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
555053d81ceSMarshall Clow    size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT
556053d81ceSMarshall Clow    {
557053d81ceSMarshall Clow        return __str_find_last_not_of<value_type, size_type, traits_type, npos>
558053d81ceSMarshall Clow            (data(), size(), __c, __pos);
559053d81ceSMarshall Clow    }
560053d81ceSMarshall Clow
561053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
562053d81ceSMarshall Clow    size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
563053d81ceSMarshall Clow    {
564053d81ceSMarshall Clow        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
565053d81ceSMarshall Clow        return __str_find_last_not_of<value_type, size_type, traits_type, npos>
566053d81ceSMarshall Clow            (data(), size(), __s, __pos, __n);
567053d81ceSMarshall Clow    }
568053d81ceSMarshall Clow
569053d81ceSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
570053d81ceSMarshall Clow    size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const
571053d81ceSMarshall Clow    {
572053d81ceSMarshall Clow        _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
573053d81ceSMarshall Clow        return __str_find_last_not_of<value_type, size_type, traits_type, npos>
574053d81ceSMarshall Clow            (data(), size(), __s, __pos, traits_type::length(__s));
575053d81ceSMarshall Clow    }
576053d81ceSMarshall Clow
577800259c9SMarshall Clow#if _LIBCPP_STD_VER > 17
578800259c9SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
579800259c9SMarshall Clow    bool starts_with(basic_string_view __s) const _NOEXCEPT
580800259c9SMarshall Clow    { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; }
581800259c9SMarshall Clow
582800259c9SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
583800259c9SMarshall Clow    bool starts_with(value_type __c) const _NOEXCEPT
584800259c9SMarshall Clow    { return !empty() && _Traits::eq(front(), __c); }
585800259c9SMarshall Clow
586800259c9SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
587800259c9SMarshall Clow    bool starts_with(const value_type* __s) const _NOEXCEPT
588800259c9SMarshall Clow    { return starts_with(basic_string_view(__s)); }
589800259c9SMarshall Clow
590800259c9SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
591800259c9SMarshall Clow    bool ends_with(basic_string_view __s) const _NOEXCEPT
592800259c9SMarshall Clow    { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; }
593800259c9SMarshall Clow
594800259c9SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
595800259c9SMarshall Clow    bool ends_with(value_type __c) const _NOEXCEPT
596800259c9SMarshall Clow    { return !empty() && _Traits::eq(back(), __c); }
597800259c9SMarshall Clow
598800259c9SMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
599800259c9SMarshall Clow    bool ends_with(const value_type* __s) const _NOEXCEPT
600800259c9SMarshall Clow    { return ends_with(basic_string_view(__s)); }
601800259c9SMarshall Clow#endif
602800259c9SMarshall Clow
603053d81ceSMarshall Clowprivate:
604053d81ceSMarshall Clow    const   value_type* __data;
605053d81ceSMarshall Clow    size_type           __size;
606053d81ceSMarshall Clow};
607053d81ceSMarshall Clow
608053d81ceSMarshall Clow
609053d81ceSMarshall Clow// [string.view.comparison]
610053d81ceSMarshall Clow// operator ==
611053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
612053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
613053d81ceSMarshall Clowbool operator==(basic_string_view<_CharT, _Traits> __lhs,
614053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
615053d81ceSMarshall Clow{
616053d81ceSMarshall Clow    if ( __lhs.size() != __rhs.size()) return false;
617053d81ceSMarshall Clow    return __lhs.compare(__rhs) == 0;
618053d81ceSMarshall Clow}
619053d81ceSMarshall Clow
620053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
621053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
622053d81ceSMarshall Clowbool operator==(basic_string_view<_CharT, _Traits> __lhs,
623053d81ceSMarshall Clow                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
624053d81ceSMarshall Clow{
625053d81ceSMarshall Clow    if ( __lhs.size() != __rhs.size()) return false;
626053d81ceSMarshall Clow    return __lhs.compare(__rhs) == 0;
627053d81ceSMarshall Clow}
628053d81ceSMarshall Clow
629053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
630053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
631053d81ceSMarshall Clowbool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
632053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
633053d81ceSMarshall Clow{
634053d81ceSMarshall Clow    if ( __lhs.size() != __rhs.size()) return false;
635053d81ceSMarshall Clow    return __lhs.compare(__rhs) == 0;
636053d81ceSMarshall Clow}
637053d81ceSMarshall Clow
638053d81ceSMarshall Clow
639053d81ceSMarshall Clow// operator !=
640053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
641053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
642053d81ceSMarshall Clowbool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
643053d81ceSMarshall Clow{
644053d81ceSMarshall Clow    if ( __lhs.size() != __rhs.size())
645053d81ceSMarshall Clow        return true;
646053d81ceSMarshall Clow    return __lhs.compare(__rhs) != 0;
647053d81ceSMarshall Clow}
648053d81ceSMarshall Clow
649053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
650053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
651053d81ceSMarshall Clowbool operator!=(basic_string_view<_CharT, _Traits> __lhs,
652053d81ceSMarshall Clow                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
653053d81ceSMarshall Clow{
654053d81ceSMarshall Clow    if ( __lhs.size() != __rhs.size())
655053d81ceSMarshall Clow        return true;
656053d81ceSMarshall Clow    return __lhs.compare(__rhs) != 0;
657053d81ceSMarshall Clow}
658053d81ceSMarshall Clow
659053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
660053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
661053d81ceSMarshall Clowbool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
662053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
663053d81ceSMarshall Clow{
664053d81ceSMarshall Clow    if ( __lhs.size() != __rhs.size())
665053d81ceSMarshall Clow        return true;
666053d81ceSMarshall Clow    return __lhs.compare(__rhs) != 0;
667053d81ceSMarshall Clow}
668053d81ceSMarshall Clow
669053d81ceSMarshall Clow
670053d81ceSMarshall Clow// operator <
671053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
672053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
673053d81ceSMarshall Clowbool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
674053d81ceSMarshall Clow{
675053d81ceSMarshall Clow    return __lhs.compare(__rhs) < 0;
676053d81ceSMarshall Clow}
677053d81ceSMarshall Clow
678053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
679053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
680053d81ceSMarshall Clowbool operator<(basic_string_view<_CharT, _Traits> __lhs,
681053d81ceSMarshall Clow                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
682053d81ceSMarshall Clow{
683053d81ceSMarshall Clow    return __lhs.compare(__rhs) < 0;
684053d81ceSMarshall Clow}
685053d81ceSMarshall Clow
686053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
687053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
688053d81ceSMarshall Clowbool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
689053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
690053d81ceSMarshall Clow{
691053d81ceSMarshall Clow    return __lhs.compare(__rhs) < 0;
692053d81ceSMarshall Clow}
693053d81ceSMarshall Clow
694053d81ceSMarshall Clow
695053d81ceSMarshall Clow// operator >
696053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
697053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
698053d81ceSMarshall Clowbool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
699053d81ceSMarshall Clow{
700053d81ceSMarshall Clow    return __lhs.compare(__rhs) > 0;
701053d81ceSMarshall Clow}
702053d81ceSMarshall Clow
703053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
704053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
705053d81ceSMarshall Clowbool operator>(basic_string_view<_CharT, _Traits> __lhs,
706053d81ceSMarshall Clow                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
707053d81ceSMarshall Clow{
708053d81ceSMarshall Clow    return __lhs.compare(__rhs) > 0;
709053d81ceSMarshall Clow}
710053d81ceSMarshall Clow
711053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
712053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
713053d81ceSMarshall Clowbool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
714053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
715053d81ceSMarshall Clow{
716053d81ceSMarshall Clow    return __lhs.compare(__rhs) > 0;
717053d81ceSMarshall Clow}
718053d81ceSMarshall Clow
719053d81ceSMarshall Clow
720053d81ceSMarshall Clow// operator <=
721053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
722053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
723053d81ceSMarshall Clowbool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
724053d81ceSMarshall Clow{
725053d81ceSMarshall Clow    return __lhs.compare(__rhs) <= 0;
726053d81ceSMarshall Clow}
727053d81ceSMarshall Clow
728053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
729053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
730053d81ceSMarshall Clowbool operator<=(basic_string_view<_CharT, _Traits> __lhs,
731053d81ceSMarshall Clow                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
732053d81ceSMarshall Clow{
733053d81ceSMarshall Clow    return __lhs.compare(__rhs) <= 0;
734053d81ceSMarshall Clow}
735053d81ceSMarshall Clow
736053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
737053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
738053d81ceSMarshall Clowbool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
739053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
740053d81ceSMarshall Clow{
741053d81ceSMarshall Clow    return __lhs.compare(__rhs) <= 0;
742053d81ceSMarshall Clow}
743053d81ceSMarshall Clow
744053d81ceSMarshall Clow
745053d81ceSMarshall Clow// operator >=
746053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
747053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
748053d81ceSMarshall Clowbool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
749053d81ceSMarshall Clow{
750053d81ceSMarshall Clow    return __lhs.compare(__rhs) >= 0;
751053d81ceSMarshall Clow}
752053d81ceSMarshall Clow
753053d81ceSMarshall Clow
754053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
755053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
756053d81ceSMarshall Clowbool operator>=(basic_string_view<_CharT, _Traits> __lhs,
757053d81ceSMarshall Clow                typename common_type<basic_string_view<_CharT, _Traits> >::type __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>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
765053d81ceSMarshall Clow                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
766053d81ceSMarshall Clow{
767053d81ceSMarshall Clow    return __lhs.compare(__rhs) >= 0;
768053d81ceSMarshall Clow}
769053d81ceSMarshall Clow
770053d81ceSMarshall Clowtypedef basic_string_view<char>     string_view;
7717dad0bd6SMarshall Clow#ifndef _LIBCPP_NO_HAS_CHAR8_T
7727dad0bd6SMarshall Clowtypedef basic_string_view<char8_t>  u8string_view;
7737dad0bd6SMarshall Clow#endif
774053d81ceSMarshall Clowtypedef basic_string_view<char16_t> u16string_view;
775053d81ceSMarshall Clowtypedef basic_string_view<char32_t> u32string_view;
776053d81ceSMarshall Clowtypedef basic_string_view<wchar_t>  wstring_view;
777053d81ceSMarshall Clow
778053d81ceSMarshall Clow// [string.view.hash]
77993184302SMarshall Clowtemplate<class _CharT>
78093184302SMarshall Clowstruct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, char_traits<_CharT> > >
78193184302SMarshall Clow    : public unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t>
782053d81ceSMarshall Clow{
783a86710f1SLouis Dionne    _LIBCPP_INLINE_VISIBILITY
78493184302SMarshall Clow    size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT {
785053d81ceSMarshall Clow        return __do_string_hash(__val.data(), __val.data() + __val.size());
786053d81ceSMarshall Clow    }
787a86710f1SLouis Dionne};
788053d81ceSMarshall Clow
7898fd58a6bSMarshall Clow
7908fd58a6bSMarshall Clow#if _LIBCPP_STD_VER > 11
7918fd58a6bSMarshall Clowinline namespace literals
7928fd58a6bSMarshall Clow{
7938fd58a6bSMarshall Clow  inline namespace string_view_literals
7948fd58a6bSMarshall Clow  {
7958fd58a6bSMarshall Clow    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
79659b48302SMarshall Clow    basic_string_view<char> operator "" sv(const char *__str, size_t __len) _NOEXCEPT
7978fd58a6bSMarshall Clow    {
7988fd58a6bSMarshall Clow        return basic_string_view<char> (__str, __len);
7998fd58a6bSMarshall Clow    }
8008fd58a6bSMarshall Clow
8018fd58a6bSMarshall Clow    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
80259b48302SMarshall Clow    basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT
8038fd58a6bSMarshall Clow    {
8048fd58a6bSMarshall Clow        return basic_string_view<wchar_t> (__str, __len);
8058fd58a6bSMarshall Clow    }
8068fd58a6bSMarshall Clow
8077dad0bd6SMarshall Clow#ifndef _LIBCPP_NO_HAS_CHAR8_T
8087dad0bd6SMarshall Clow    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
8097dad0bd6SMarshall Clow    basic_string_view<char8_t> operator "" sv(const char8_t *__str, size_t __len) _NOEXCEPT
8107dad0bd6SMarshall Clow    {
8117dad0bd6SMarshall Clow        return basic_string_view<char8_t> (__str, __len);
8127dad0bd6SMarshall Clow    }
8137dad0bd6SMarshall Clow#endif
8147dad0bd6SMarshall Clow
8158fd58a6bSMarshall Clow    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
81659b48302SMarshall Clow    basic_string_view<char16_t> operator "" sv(const char16_t *__str, size_t __len) _NOEXCEPT
8178fd58a6bSMarshall Clow    {
8188fd58a6bSMarshall Clow        return basic_string_view<char16_t> (__str, __len);
8198fd58a6bSMarshall Clow    }
8208fd58a6bSMarshall Clow
8218fd58a6bSMarshall Clow    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
82259b48302SMarshall Clow    basic_string_view<char32_t> operator "" sv(const char32_t *__str, size_t __len) _NOEXCEPT
8238fd58a6bSMarshall Clow    {
8248fd58a6bSMarshall Clow        return basic_string_view<char32_t> (__str, __len);
8258fd58a6bSMarshall Clow    }
8268fd58a6bSMarshall Clow  }
8278fd58a6bSMarshall Clow}
8288fd58a6bSMarshall Clow#endif
829053d81ceSMarshall Clow_LIBCPP_END_NAMESPACE_STD
830053d81ceSMarshall Clow
831a016efb1SEric Fiselier_LIBCPP_POP_MACROS
832a016efb1SEric Fiselier
833053d81ceSMarshall Clow#endif // _LIBCPP_STRING_VIEW
834