xref: /aosp_15_r20/external/libcxx/include/__string (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1*58b9f456SAndroid Build Coastguard Worker// -*- C++ -*-
2*58b9f456SAndroid Build Coastguard Worker//===-------------------------- __string ----------------------------------===//
3*58b9f456SAndroid Build Coastguard Worker//
4*58b9f456SAndroid Build Coastguard Worker//                     The LLVM Compiler Infrastructure
5*58b9f456SAndroid Build Coastguard Worker//
6*58b9f456SAndroid Build Coastguard Worker// This file is distributed under the University of Illinois Open Source
7*58b9f456SAndroid Build Coastguard Worker// License. See LICENSE.TXT for details.
8*58b9f456SAndroid Build Coastguard Worker//
9*58b9f456SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
10*58b9f456SAndroid Build Coastguard Worker
11*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP___STRING
12*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP___STRING
13*58b9f456SAndroid Build Coastguard Worker
14*58b9f456SAndroid Build Coastguard Worker/*
15*58b9f456SAndroid Build Coastguard Worker    string synopsis
16*58b9f456SAndroid Build Coastguard Worker
17*58b9f456SAndroid Build Coastguard Workernamespace std
18*58b9f456SAndroid Build Coastguard Worker{
19*58b9f456SAndroid Build Coastguard Worker
20*58b9f456SAndroid Build Coastguard Workertemplate <class charT>
21*58b9f456SAndroid Build Coastguard Workerstruct char_traits
22*58b9f456SAndroid Build Coastguard Worker{
23*58b9f456SAndroid Build Coastguard Worker    typedef charT     char_type;
24*58b9f456SAndroid Build Coastguard Worker    typedef ...       int_type;
25*58b9f456SAndroid Build Coastguard Worker    typedef streamoff off_type;
26*58b9f456SAndroid Build Coastguard Worker    typedef streampos pos_type;
27*58b9f456SAndroid Build Coastguard Worker    typedef mbstate_t state_type;
28*58b9f456SAndroid Build Coastguard Worker
29*58b9f456SAndroid Build Coastguard Worker    static constexpr void assign(char_type& c1, const char_type& c2) noexcept;
30*58b9f456SAndroid Build Coastguard Worker    static constexpr bool eq(char_type c1, char_type c2) noexcept;
31*58b9f456SAndroid Build Coastguard Worker    static constexpr bool lt(char_type c1, char_type c2) noexcept;
32*58b9f456SAndroid Build Coastguard Worker
33*58b9f456SAndroid Build Coastguard Worker    static constexpr int    compare(const char_type* s1, const char_type* s2, size_t n);
34*58b9f456SAndroid Build Coastguard Worker    static constexpr size_t length(const char_type* s);
35*58b9f456SAndroid Build Coastguard Worker    static constexpr const char_type*
36*58b9f456SAndroid Build Coastguard Worker                            find(const char_type* s, size_t n, const char_type& a);
37*58b9f456SAndroid Build Coastguard Worker    static char_type*       move(char_type* s1, const char_type* s2, size_t n);
38*58b9f456SAndroid Build Coastguard Worker    static char_type*       copy(char_type* s1, const char_type* s2, size_t n);
39*58b9f456SAndroid Build Coastguard Worker    static char_type*       assign(char_type* s, size_t n, char_type a);
40*58b9f456SAndroid Build Coastguard Worker
41*58b9f456SAndroid Build Coastguard Worker    static constexpr int_type  not_eof(int_type c) noexcept;
42*58b9f456SAndroid Build Coastguard Worker    static constexpr char_type to_char_type(int_type c) noexcept;
43*58b9f456SAndroid Build Coastguard Worker    static constexpr int_type  to_int_type(char_type c) noexcept;
44*58b9f456SAndroid Build Coastguard Worker    static constexpr bool      eq_int_type(int_type c1, int_type c2) noexcept;
45*58b9f456SAndroid Build Coastguard Worker    static constexpr int_type  eof() noexcept;
46*58b9f456SAndroid Build Coastguard Worker};
47*58b9f456SAndroid Build Coastguard Worker
48*58b9f456SAndroid Build Coastguard Workertemplate <> struct char_traits<char>;
49*58b9f456SAndroid Build Coastguard Workertemplate <> struct char_traits<wchar_t>;
50*58b9f456SAndroid Build Coastguard Workertemplate <> struct char_traits<char8_t>;  // c++20
51*58b9f456SAndroid Build Coastguard Worker
52*58b9f456SAndroid Build Coastguard Worker}  // std
53*58b9f456SAndroid Build Coastguard Worker
54*58b9f456SAndroid Build Coastguard Worker*/
55*58b9f456SAndroid Build Coastguard Worker
56*58b9f456SAndroid Build Coastguard Worker#include <__config>
57*58b9f456SAndroid Build Coastguard Worker#include <algorithm>  // for search and min
58*58b9f456SAndroid Build Coastguard Worker#include <cstdio>     // For EOF.
59*58b9f456SAndroid Build Coastguard Worker#include <memory>     // for __murmur2_or_cityhash
60*58b9f456SAndroid Build Coastguard Worker
61*58b9f456SAndroid Build Coastguard Worker#include <__debug>
62*58b9f456SAndroid Build Coastguard Worker
63*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
64*58b9f456SAndroid Build Coastguard Worker#pragma GCC system_header
65*58b9f456SAndroid Build Coastguard Worker#endif
66*58b9f456SAndroid Build Coastguard Worker
67*58b9f456SAndroid Build Coastguard Worker_LIBCPP_PUSH_MACROS
68*58b9f456SAndroid Build Coastguard Worker#include <__undef_macros>
69*58b9f456SAndroid Build Coastguard Worker
70*58b9f456SAndroid Build Coastguard Worker
71*58b9f456SAndroid Build Coastguard Worker_LIBCPP_BEGIN_NAMESPACE_STD
72*58b9f456SAndroid Build Coastguard Worker
73*58b9f456SAndroid Build Coastguard Worker// char_traits
74*58b9f456SAndroid Build Coastguard Worker
75*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT>
76*58b9f456SAndroid Build Coastguard Workerstruct char_traits;
77*58b9f456SAndroid Build Coastguard Worker/*
78*58b9f456SAndroid Build Coastguard WorkerThe Standard does not define the base template for char_traits because it is impossible to provide
79*58b9f456SAndroid Build Coastguard Workera correct definition for arbitrary character types. Instead, it requires implementations to provide
80*58b9f456SAndroid Build Coastguard Workerspecializations for predefined character types like `char`, `wchar_t` and others. We provide this as
81*58b9f456SAndroid Build Coastguard Workerexposition-only to document what members a char_traits specialization should provide:
82*58b9f456SAndroid Build Coastguard Worker{
83*58b9f456SAndroid Build Coastguard Worker    using char_type  = _CharT;
84*58b9f456SAndroid Build Coastguard Worker    using int_type   = ...;
85*58b9f456SAndroid Build Coastguard Worker    using off_type   = ...;
86*58b9f456SAndroid Build Coastguard Worker    using pos_type   = ...;
87*58b9f456SAndroid Build Coastguard Worker    using state_type = ...;
88*58b9f456SAndroid Build Coastguard Worker
89*58b9f456SAndroid Build Coastguard Worker    static void assign(char_type&, const char_type&);
90*58b9f456SAndroid Build Coastguard Worker    static bool eq(char_type, char_type);
91*58b9f456SAndroid Build Coastguard Worker    static bool lt(char_type, char_type);
92*58b9f456SAndroid Build Coastguard Worker
93*58b9f456SAndroid Build Coastguard Worker    static int              compare(const char_type*, const char_type*, size_t);
94*58b9f456SAndroid Build Coastguard Worker    static size_t           length(const char_type*);
95*58b9f456SAndroid Build Coastguard Worker    static const char_type* find(const char_type*, size_t, const char_type&);
96*58b9f456SAndroid Build Coastguard Worker    static char_type*       move(char_type*, const char_type*, size_t);
97*58b9f456SAndroid Build Coastguard Worker    static char_type*       copy(char_type*, const char_type*, size_t);
98*58b9f456SAndroid Build Coastguard Worker    static char_type*       assign(char_type*, size_t, char_type);
99*58b9f456SAndroid Build Coastguard Worker
100*58b9f456SAndroid Build Coastguard Worker    static int_type  not_eof(int_type);
101*58b9f456SAndroid Build Coastguard Worker    static char_type to_char_type(int_type);
102*58b9f456SAndroid Build Coastguard Worker    static int_type  to_int_type(char_type);
103*58b9f456SAndroid Build Coastguard Worker    static bool      eq_int_type(int_type, int_type);
104*58b9f456SAndroid Build Coastguard Worker    static int_type  eof();
105*58b9f456SAndroid Build Coastguard Worker};
106*58b9f456SAndroid Build Coastguard Worker*/
107*58b9f456SAndroid Build Coastguard Worker
108*58b9f456SAndroid Build Coastguard Worker// char_traits<char>
109*58b9f456SAndroid Build Coastguard Worker
110*58b9f456SAndroid Build Coastguard Workertemplate <>
111*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS char_traits<char>
112*58b9f456SAndroid Build Coastguard Worker{
113*58b9f456SAndroid Build Coastguard Worker    typedef char      char_type;
114*58b9f456SAndroid Build Coastguard Worker    typedef int       int_type;
115*58b9f456SAndroid Build Coastguard Worker    typedef streamoff off_type;
116*58b9f456SAndroid Build Coastguard Worker    typedef streampos pos_type;
117*58b9f456SAndroid Build Coastguard Worker    typedef mbstate_t state_type;
118*58b9f456SAndroid Build Coastguard Worker
119*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
120*58b9f456SAndroid Build Coastguard Worker    void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
121*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
122*58b9f456SAndroid Build Coastguard Worker            {return __c1 == __c2;}
123*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
124*58b9f456SAndroid Build Coastguard Worker        {return (unsigned char)__c1 < (unsigned char)__c2;}
125*58b9f456SAndroid Build Coastguard Worker
126*58b9f456SAndroid Build Coastguard Worker    static _LIBCPP_CONSTEXPR_AFTER_CXX14
127*58b9f456SAndroid Build Coastguard Worker    int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
128*58b9f456SAndroid Build Coastguard Worker    static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14
129*58b9f456SAndroid Build Coastguard Worker    length(const char_type* __s)  _NOEXCEPT {return __builtin_strlen(__s);}
130*58b9f456SAndroid Build Coastguard Worker    static _LIBCPP_CONSTEXPR_AFTER_CXX14
131*58b9f456SAndroid Build Coastguard Worker    const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
132*58b9f456SAndroid Build Coastguard Worker    static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
133*58b9f456SAndroid Build Coastguard Worker        {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);}
134*58b9f456SAndroid Build Coastguard Worker    static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
135*58b9f456SAndroid Build Coastguard Worker        {
136*58b9f456SAndroid Build Coastguard Worker            _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
137*58b9f456SAndroid Build Coastguard Worker            return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n);
138*58b9f456SAndroid Build Coastguard Worker        }
139*58b9f456SAndroid Build Coastguard Worker    static inline char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
140*58b9f456SAndroid Build Coastguard Worker        {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);}
141*58b9f456SAndroid Build Coastguard Worker
142*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
143*58b9f456SAndroid Build Coastguard Worker        {return eq_int_type(__c, eof()) ? ~eof() : __c;}
144*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
145*58b9f456SAndroid Build Coastguard Worker        {return char_type(__c);}
146*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
147*58b9f456SAndroid Build Coastguard Worker        {return int_type((unsigned char)__c);}
148*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
149*58b9f456SAndroid Build Coastguard Worker        {return __c1 == __c2;}
150*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR int_type  eof() _NOEXCEPT
151*58b9f456SAndroid Build Coastguard Worker        {return int_type(EOF);}
152*58b9f456SAndroid Build Coastguard Worker};
153*58b9f456SAndroid Build Coastguard Worker
154*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_CONSTEXPR_AFTER_CXX14
155*58b9f456SAndroid Build Coastguard Workerint
156*58b9f456SAndroid Build Coastguard Workerchar_traits<char>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
157*58b9f456SAndroid Build Coastguard Worker{
158*58b9f456SAndroid Build Coastguard Worker    if (__n == 0)
159*58b9f456SAndroid Build Coastguard Worker        return 0;
160*58b9f456SAndroid Build Coastguard Worker#if __has_feature(cxx_constexpr_string_builtins)
161*58b9f456SAndroid Build Coastguard Worker    return __builtin_memcmp(__s1, __s2, __n);
162*58b9f456SAndroid Build Coastguard Worker#elif _LIBCPP_STD_VER <= 14
163*58b9f456SAndroid Build Coastguard Worker    return memcmp(__s1, __s2, __n);
164*58b9f456SAndroid Build Coastguard Worker#else
165*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n, ++__s1, ++__s2)
166*58b9f456SAndroid Build Coastguard Worker    {
167*58b9f456SAndroid Build Coastguard Worker        if (lt(*__s1, *__s2))
168*58b9f456SAndroid Build Coastguard Worker            return -1;
169*58b9f456SAndroid Build Coastguard Worker        if (lt(*__s2, *__s1))
170*58b9f456SAndroid Build Coastguard Worker            return 1;
171*58b9f456SAndroid Build Coastguard Worker    }
172*58b9f456SAndroid Build Coastguard Worker    return 0;
173*58b9f456SAndroid Build Coastguard Worker#endif
174*58b9f456SAndroid Build Coastguard Worker}
175*58b9f456SAndroid Build Coastguard Worker
176*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_CONSTEXPR_AFTER_CXX14
177*58b9f456SAndroid Build Coastguard Workerconst char*
178*58b9f456SAndroid Build Coastguard Workerchar_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
179*58b9f456SAndroid Build Coastguard Worker{
180*58b9f456SAndroid Build Coastguard Worker    if (__n == 0)
181*58b9f456SAndroid Build Coastguard Worker        return nullptr;
182*58b9f456SAndroid Build Coastguard Worker#if __has_feature(cxx_constexpr_string_builtins)
183*58b9f456SAndroid Build Coastguard Worker    return __builtin_char_memchr(__s, to_int_type(__a), __n);
184*58b9f456SAndroid Build Coastguard Worker#elif _LIBCPP_STD_VER <= 14
185*58b9f456SAndroid Build Coastguard Worker    return (const char_type*) memchr(__s, to_int_type(__a), __n);
186*58b9f456SAndroid Build Coastguard Worker#else
187*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n)
188*58b9f456SAndroid Build Coastguard Worker    {
189*58b9f456SAndroid Build Coastguard Worker        if (eq(*__s, __a))
190*58b9f456SAndroid Build Coastguard Worker            return __s;
191*58b9f456SAndroid Build Coastguard Worker        ++__s;
192*58b9f456SAndroid Build Coastguard Worker    }
193*58b9f456SAndroid Build Coastguard Worker    return nullptr;
194*58b9f456SAndroid Build Coastguard Worker#endif
195*58b9f456SAndroid Build Coastguard Worker}
196*58b9f456SAndroid Build Coastguard Worker
197*58b9f456SAndroid Build Coastguard Worker
198*58b9f456SAndroid Build Coastguard Worker// char_traits<wchar_t>
199*58b9f456SAndroid Build Coastguard Worker
200*58b9f456SAndroid Build Coastguard Workertemplate <>
201*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
202*58b9f456SAndroid Build Coastguard Worker{
203*58b9f456SAndroid Build Coastguard Worker    typedef wchar_t   char_type;
204*58b9f456SAndroid Build Coastguard Worker    typedef wint_t    int_type;
205*58b9f456SAndroid Build Coastguard Worker    typedef streamoff off_type;
206*58b9f456SAndroid Build Coastguard Worker    typedef streampos pos_type;
207*58b9f456SAndroid Build Coastguard Worker    typedef mbstate_t state_type;
208*58b9f456SAndroid Build Coastguard Worker
209*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
210*58b9f456SAndroid Build Coastguard Worker    void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
211*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
212*58b9f456SAndroid Build Coastguard Worker        {return __c1 == __c2;}
213*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
214*58b9f456SAndroid Build Coastguard Worker        {return __c1 < __c2;}
215*58b9f456SAndroid Build Coastguard Worker
216*58b9f456SAndroid Build Coastguard Worker    static _LIBCPP_CONSTEXPR_AFTER_CXX14
217*58b9f456SAndroid Build Coastguard Worker    int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
218*58b9f456SAndroid Build Coastguard Worker    static _LIBCPP_CONSTEXPR_AFTER_CXX14
219*58b9f456SAndroid Build Coastguard Worker    size_t length(const char_type* __s) _NOEXCEPT;
220*58b9f456SAndroid Build Coastguard Worker    static _LIBCPP_CONSTEXPR_AFTER_CXX14
221*58b9f456SAndroid Build Coastguard Worker    const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
222*58b9f456SAndroid Build Coastguard Worker    static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
223*58b9f456SAndroid Build Coastguard Worker        {return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);}
224*58b9f456SAndroid Build Coastguard Worker    static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
225*58b9f456SAndroid Build Coastguard Worker        {
226*58b9f456SAndroid Build Coastguard Worker            _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
227*58b9f456SAndroid Build Coastguard Worker            return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n);
228*58b9f456SAndroid Build Coastguard Worker        }
229*58b9f456SAndroid Build Coastguard Worker    static inline char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
230*58b9f456SAndroid Build Coastguard Worker        {return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);}
231*58b9f456SAndroid Build Coastguard Worker
232*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
233*58b9f456SAndroid Build Coastguard Worker        {return eq_int_type(__c, eof()) ? ~eof() : __c;}
234*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
235*58b9f456SAndroid Build Coastguard Worker        {return char_type(__c);}
236*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
237*58b9f456SAndroid Build Coastguard Worker        {return int_type(__c);}
238*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
239*58b9f456SAndroid Build Coastguard Worker        {return __c1 == __c2;}
240*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
241*58b9f456SAndroid Build Coastguard Worker        {return int_type(WEOF);}
242*58b9f456SAndroid Build Coastguard Worker};
243*58b9f456SAndroid Build Coastguard Worker
244*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_CONSTEXPR_AFTER_CXX14
245*58b9f456SAndroid Build Coastguard Workerint
246*58b9f456SAndroid Build Coastguard Workerchar_traits<wchar_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
247*58b9f456SAndroid Build Coastguard Worker{
248*58b9f456SAndroid Build Coastguard Worker    if (__n == 0)
249*58b9f456SAndroid Build Coastguard Worker        return 0;
250*58b9f456SAndroid Build Coastguard Worker#if __has_feature(cxx_constexpr_string_builtins)
251*58b9f456SAndroid Build Coastguard Worker    return __builtin_wmemcmp(__s1, __s2, __n);
252*58b9f456SAndroid Build Coastguard Worker#elif _LIBCPP_STD_VER <= 14
253*58b9f456SAndroid Build Coastguard Worker    return wmemcmp(__s1, __s2, __n);
254*58b9f456SAndroid Build Coastguard Worker#else
255*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n, ++__s1, ++__s2)
256*58b9f456SAndroid Build Coastguard Worker    {
257*58b9f456SAndroid Build Coastguard Worker        if (lt(*__s1, *__s2))
258*58b9f456SAndroid Build Coastguard Worker            return -1;
259*58b9f456SAndroid Build Coastguard Worker        if (lt(*__s2, *__s1))
260*58b9f456SAndroid Build Coastguard Worker            return 1;
261*58b9f456SAndroid Build Coastguard Worker    }
262*58b9f456SAndroid Build Coastguard Worker    return 0;
263*58b9f456SAndroid Build Coastguard Worker#endif
264*58b9f456SAndroid Build Coastguard Worker}
265*58b9f456SAndroid Build Coastguard Worker
266*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_CONSTEXPR_AFTER_CXX14
267*58b9f456SAndroid Build Coastguard Workersize_t
268*58b9f456SAndroid Build Coastguard Workerchar_traits<wchar_t>::length(const char_type* __s) _NOEXCEPT
269*58b9f456SAndroid Build Coastguard Worker{
270*58b9f456SAndroid Build Coastguard Worker#if __has_feature(cxx_constexpr_string_builtins)
271*58b9f456SAndroid Build Coastguard Worker    return __builtin_wcslen(__s);
272*58b9f456SAndroid Build Coastguard Worker#elif _LIBCPP_STD_VER <= 14
273*58b9f456SAndroid Build Coastguard Worker    return wcslen(__s);
274*58b9f456SAndroid Build Coastguard Worker#else
275*58b9f456SAndroid Build Coastguard Worker    size_t __len = 0;
276*58b9f456SAndroid Build Coastguard Worker    for (; !eq(*__s, char_type(0)); ++__s)
277*58b9f456SAndroid Build Coastguard Worker        ++__len;
278*58b9f456SAndroid Build Coastguard Worker    return __len;
279*58b9f456SAndroid Build Coastguard Worker#endif
280*58b9f456SAndroid Build Coastguard Worker}
281*58b9f456SAndroid Build Coastguard Worker
282*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_CONSTEXPR_AFTER_CXX14
283*58b9f456SAndroid Build Coastguard Workerconst wchar_t*
284*58b9f456SAndroid Build Coastguard Workerchar_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
285*58b9f456SAndroid Build Coastguard Worker{
286*58b9f456SAndroid Build Coastguard Worker    if (__n == 0)
287*58b9f456SAndroid Build Coastguard Worker        return nullptr;
288*58b9f456SAndroid Build Coastguard Worker#if __has_feature(cxx_constexpr_string_builtins)
289*58b9f456SAndroid Build Coastguard Worker    return __builtin_wmemchr(__s, __a, __n);
290*58b9f456SAndroid Build Coastguard Worker#elif _LIBCPP_STD_VER <= 14
291*58b9f456SAndroid Build Coastguard Worker    return wmemchr(__s, __a, __n);
292*58b9f456SAndroid Build Coastguard Worker#else
293*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n)
294*58b9f456SAndroid Build Coastguard Worker    {
295*58b9f456SAndroid Build Coastguard Worker        if (eq(*__s, __a))
296*58b9f456SAndroid Build Coastguard Worker            return __s;
297*58b9f456SAndroid Build Coastguard Worker        ++__s;
298*58b9f456SAndroid Build Coastguard Worker    }
299*58b9f456SAndroid Build Coastguard Worker    return nullptr;
300*58b9f456SAndroid Build Coastguard Worker#endif
301*58b9f456SAndroid Build Coastguard Worker}
302*58b9f456SAndroid Build Coastguard Worker
303*58b9f456SAndroid Build Coastguard Worker
304*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_HAS_CHAR8_T
305*58b9f456SAndroid Build Coastguard Worker
306*58b9f456SAndroid Build Coastguard Workertemplate <>
307*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
308*58b9f456SAndroid Build Coastguard Worker{
309*58b9f456SAndroid Build Coastguard Worker    typedef char8_t        char_type;
310*58b9f456SAndroid Build Coastguard Worker    typedef unsigned int   int_type;
311*58b9f456SAndroid Build Coastguard Worker    typedef streamoff      off_type;
312*58b9f456SAndroid Build Coastguard Worker    typedef u8streampos    pos_type;
313*58b9f456SAndroid Build Coastguard Worker    typedef mbstate_t      state_type;
314*58b9f456SAndroid Build Coastguard Worker
315*58b9f456SAndroid Build Coastguard Worker    static inline constexpr void assign(char_type& __c1, const char_type& __c2) noexcept
316*58b9f456SAndroid Build Coastguard Worker        {__c1 = __c2;}
317*58b9f456SAndroid Build Coastguard Worker    static inline constexpr bool eq(char_type __c1, char_type __c2) noexcept
318*58b9f456SAndroid Build Coastguard Worker        {return __c1 == __c2;}
319*58b9f456SAndroid Build Coastguard Worker    static inline constexpr bool lt(char_type __c1, char_type __c2) noexcept
320*58b9f456SAndroid Build Coastguard Worker        {return __c1 < __c2;}
321*58b9f456SAndroid Build Coastguard Worker
322*58b9f456SAndroid Build Coastguard Worker    static constexpr
323*58b9f456SAndroid Build Coastguard Worker    int              compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
324*58b9f456SAndroid Build Coastguard Worker
325*58b9f456SAndroid Build Coastguard Worker    static constexpr
326*58b9f456SAndroid Build Coastguard Worker    size_t           length(const char_type* __s) _NOEXCEPT;
327*58b9f456SAndroid Build Coastguard Worker
328*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY static constexpr
329*58b9f456SAndroid Build Coastguard Worker    const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
330*58b9f456SAndroid Build Coastguard Worker
331*58b9f456SAndroid Build Coastguard Worker    static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
332*58b9f456SAndroid Build Coastguard Worker        {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);}
333*58b9f456SAndroid Build Coastguard Worker
334*58b9f456SAndroid Build Coastguard Worker    static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
335*58b9f456SAndroid Build Coastguard Worker       {
336*58b9f456SAndroid Build Coastguard Worker            _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
337*58b9f456SAndroid Build Coastguard Worker            return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n);
338*58b9f456SAndroid Build Coastguard Worker       }
339*58b9f456SAndroid Build Coastguard Worker
340*58b9f456SAndroid Build Coastguard Worker    static char_type*       assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
341*58b9f456SAndroid Build Coastguard Worker        {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);}
342*58b9f456SAndroid Build Coastguard Worker
343*58b9f456SAndroid Build Coastguard Worker    static inline constexpr int_type  not_eof(int_type __c) noexcept
344*58b9f456SAndroid Build Coastguard Worker        {return eq_int_type(__c, eof()) ? ~eof() : __c;}
345*58b9f456SAndroid Build Coastguard Worker    static inline constexpr char_type to_char_type(int_type __c) noexcept
346*58b9f456SAndroid Build Coastguard Worker        {return char_type(__c);}
347*58b9f456SAndroid Build Coastguard Worker    static inline constexpr int_type to_int_type(char_type __c) noexcept
348*58b9f456SAndroid Build Coastguard Worker        {return int_type(__c);}
349*58b9f456SAndroid Build Coastguard Worker    static inline constexpr bool eq_int_type(int_type __c1, int_type __c2) noexcept
350*58b9f456SAndroid Build Coastguard Worker        {return __c1 == __c2;}
351*58b9f456SAndroid Build Coastguard Worker    static inline constexpr int_type eof() noexcept
352*58b9f456SAndroid Build Coastguard Worker        {return int_type(EOF);}
353*58b9f456SAndroid Build Coastguard Worker};
354*58b9f456SAndroid Build Coastguard Worker
355*58b9f456SAndroid Build Coastguard Worker// TODO use '__builtin_strlen' if it ever supports char8_t ??
356*58b9f456SAndroid Build Coastguard Workerinline constexpr
357*58b9f456SAndroid Build Coastguard Workersize_t
358*58b9f456SAndroid Build Coastguard Workerchar_traits<char8_t>::length(const char_type* __s) _NOEXCEPT
359*58b9f456SAndroid Build Coastguard Worker{
360*58b9f456SAndroid Build Coastguard Worker    size_t __len = 0;
361*58b9f456SAndroid Build Coastguard Worker    for (; !eq(*__s, char_type(0)); ++__s)
362*58b9f456SAndroid Build Coastguard Worker        ++__len;
363*58b9f456SAndroid Build Coastguard Worker    return __len;
364*58b9f456SAndroid Build Coastguard Worker}
365*58b9f456SAndroid Build Coastguard Worker
366*58b9f456SAndroid Build Coastguard Workerinline constexpr
367*58b9f456SAndroid Build Coastguard Workerint
368*58b9f456SAndroid Build Coastguard Workerchar_traits<char8_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
369*58b9f456SAndroid Build Coastguard Worker{
370*58b9f456SAndroid Build Coastguard Worker#if __has_feature(cxx_constexpr_string_builtins)
371*58b9f456SAndroid Build Coastguard Worker    return __builtin_memcmp(__s1, __s2, __n);
372*58b9f456SAndroid Build Coastguard Worker#else
373*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n, ++__s1, ++__s2)
374*58b9f456SAndroid Build Coastguard Worker    {
375*58b9f456SAndroid Build Coastguard Worker        if (lt(*__s1, *__s2))
376*58b9f456SAndroid Build Coastguard Worker            return -1;
377*58b9f456SAndroid Build Coastguard Worker        if (lt(*__s2, *__s1))
378*58b9f456SAndroid Build Coastguard Worker            return 1;
379*58b9f456SAndroid Build Coastguard Worker    }
380*58b9f456SAndroid Build Coastguard Worker    return 0;
381*58b9f456SAndroid Build Coastguard Worker#endif
382*58b9f456SAndroid Build Coastguard Worker}
383*58b9f456SAndroid Build Coastguard Worker
384*58b9f456SAndroid Build Coastguard Worker// TODO use '__builtin_char_memchr' if it ever supports char8_t ??
385*58b9f456SAndroid Build Coastguard Workerinline constexpr
386*58b9f456SAndroid Build Coastguard Workerconst char8_t*
387*58b9f456SAndroid Build Coastguard Workerchar_traits<char8_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
388*58b9f456SAndroid Build Coastguard Worker{
389*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n)
390*58b9f456SAndroid Build Coastguard Worker    {
391*58b9f456SAndroid Build Coastguard Worker        if (eq(*__s, __a))
392*58b9f456SAndroid Build Coastguard Worker            return __s;
393*58b9f456SAndroid Build Coastguard Worker        ++__s;
394*58b9f456SAndroid Build Coastguard Worker    }
395*58b9f456SAndroid Build Coastguard Worker    return 0;
396*58b9f456SAndroid Build Coastguard Worker}
397*58b9f456SAndroid Build Coastguard Worker
398*58b9f456SAndroid Build Coastguard Worker#endif // #_LIBCPP_NO_HAS_CHAR8_T
399*58b9f456SAndroid Build Coastguard Worker
400*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
401*58b9f456SAndroid Build Coastguard Worker
402*58b9f456SAndroid Build Coastguard Workertemplate <>
403*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS char_traits<char16_t>
404*58b9f456SAndroid Build Coastguard Worker{
405*58b9f456SAndroid Build Coastguard Worker    typedef char16_t       char_type;
406*58b9f456SAndroid Build Coastguard Worker    typedef uint_least16_t int_type;
407*58b9f456SAndroid Build Coastguard Worker    typedef streamoff      off_type;
408*58b9f456SAndroid Build Coastguard Worker    typedef u16streampos   pos_type;
409*58b9f456SAndroid Build Coastguard Worker    typedef mbstate_t      state_type;
410*58b9f456SAndroid Build Coastguard Worker
411*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
412*58b9f456SAndroid Build Coastguard Worker    void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
413*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
414*58b9f456SAndroid Build Coastguard Worker        {return __c1 == __c2;}
415*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
416*58b9f456SAndroid Build Coastguard Worker        {return __c1 < __c2;}
417*58b9f456SAndroid Build Coastguard Worker
418*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
419*58b9f456SAndroid Build Coastguard Worker    int              compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
420*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
421*58b9f456SAndroid Build Coastguard Worker    size_t           length(const char_type* __s) _NOEXCEPT;
422*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
423*58b9f456SAndroid Build Coastguard Worker    const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
424*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
425*58b9f456SAndroid Build Coastguard Worker    static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
426*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
427*58b9f456SAndroid Build Coastguard Worker    static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
428*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
429*58b9f456SAndroid Build Coastguard Worker    static char_type*       assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT;
430*58b9f456SAndroid Build Coastguard Worker
431*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
432*58b9f456SAndroid Build Coastguard Worker        {return eq_int_type(__c, eof()) ? ~eof() : __c;}
433*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
434*58b9f456SAndroid Build Coastguard Worker        {return char_type(__c);}
435*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
436*58b9f456SAndroid Build Coastguard Worker        {return int_type(__c);}
437*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
438*58b9f456SAndroid Build Coastguard Worker        {return __c1 == __c2;}
439*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
440*58b9f456SAndroid Build Coastguard Worker        {return int_type(0xFFFF);}
441*58b9f456SAndroid Build Coastguard Worker};
442*58b9f456SAndroid Build Coastguard Worker
443*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_CONSTEXPR_AFTER_CXX14
444*58b9f456SAndroid Build Coastguard Workerint
445*58b9f456SAndroid Build Coastguard Workerchar_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
446*58b9f456SAndroid Build Coastguard Worker{
447*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n, ++__s1, ++__s2)
448*58b9f456SAndroid Build Coastguard Worker    {
449*58b9f456SAndroid Build Coastguard Worker        if (lt(*__s1, *__s2))
450*58b9f456SAndroid Build Coastguard Worker            return -1;
451*58b9f456SAndroid Build Coastguard Worker        if (lt(*__s2, *__s1))
452*58b9f456SAndroid Build Coastguard Worker            return 1;
453*58b9f456SAndroid Build Coastguard Worker    }
454*58b9f456SAndroid Build Coastguard Worker    return 0;
455*58b9f456SAndroid Build Coastguard Worker}
456*58b9f456SAndroid Build Coastguard Worker
457*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_CONSTEXPR_AFTER_CXX14
458*58b9f456SAndroid Build Coastguard Workersize_t
459*58b9f456SAndroid Build Coastguard Workerchar_traits<char16_t>::length(const char_type* __s) _NOEXCEPT
460*58b9f456SAndroid Build Coastguard Worker{
461*58b9f456SAndroid Build Coastguard Worker    size_t __len = 0;
462*58b9f456SAndroid Build Coastguard Worker    for (; !eq(*__s, char_type(0)); ++__s)
463*58b9f456SAndroid Build Coastguard Worker        ++__len;
464*58b9f456SAndroid Build Coastguard Worker    return __len;
465*58b9f456SAndroid Build Coastguard Worker}
466*58b9f456SAndroid Build Coastguard Worker
467*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_CONSTEXPR_AFTER_CXX14
468*58b9f456SAndroid Build Coastguard Workerconst char16_t*
469*58b9f456SAndroid Build Coastguard Workerchar_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
470*58b9f456SAndroid Build Coastguard Worker{
471*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n)
472*58b9f456SAndroid Build Coastguard Worker    {
473*58b9f456SAndroid Build Coastguard Worker        if (eq(*__s, __a))
474*58b9f456SAndroid Build Coastguard Worker            return __s;
475*58b9f456SAndroid Build Coastguard Worker        ++__s;
476*58b9f456SAndroid Build Coastguard Worker    }
477*58b9f456SAndroid Build Coastguard Worker    return 0;
478*58b9f456SAndroid Build Coastguard Worker}
479*58b9f456SAndroid Build Coastguard Worker
480*58b9f456SAndroid Build Coastguard Workerinline
481*58b9f456SAndroid Build Coastguard Workerchar16_t*
482*58b9f456SAndroid Build Coastguard Workerchar_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
483*58b9f456SAndroid Build Coastguard Worker{
484*58b9f456SAndroid Build Coastguard Worker    char_type* __r = __s1;
485*58b9f456SAndroid Build Coastguard Worker    if (__s1 < __s2)
486*58b9f456SAndroid Build Coastguard Worker    {
487*58b9f456SAndroid Build Coastguard Worker        for (; __n; --__n, ++__s1, ++__s2)
488*58b9f456SAndroid Build Coastguard Worker            assign(*__s1, *__s2);
489*58b9f456SAndroid Build Coastguard Worker    }
490*58b9f456SAndroid Build Coastguard Worker    else if (__s2 < __s1)
491*58b9f456SAndroid Build Coastguard Worker    {
492*58b9f456SAndroid Build Coastguard Worker        __s1 += __n;
493*58b9f456SAndroid Build Coastguard Worker        __s2 += __n;
494*58b9f456SAndroid Build Coastguard Worker        for (; __n; --__n)
495*58b9f456SAndroid Build Coastguard Worker            assign(*--__s1, *--__s2);
496*58b9f456SAndroid Build Coastguard Worker    }
497*58b9f456SAndroid Build Coastguard Worker    return __r;
498*58b9f456SAndroid Build Coastguard Worker}
499*58b9f456SAndroid Build Coastguard Worker
500*58b9f456SAndroid Build Coastguard Workerinline
501*58b9f456SAndroid Build Coastguard Workerchar16_t*
502*58b9f456SAndroid Build Coastguard Workerchar_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
503*58b9f456SAndroid Build Coastguard Worker{
504*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
505*58b9f456SAndroid Build Coastguard Worker    char_type* __r = __s1;
506*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n, ++__s1, ++__s2)
507*58b9f456SAndroid Build Coastguard Worker        assign(*__s1, *__s2);
508*58b9f456SAndroid Build Coastguard Worker    return __r;
509*58b9f456SAndroid Build Coastguard Worker}
510*58b9f456SAndroid Build Coastguard Worker
511*58b9f456SAndroid Build Coastguard Workerinline
512*58b9f456SAndroid Build Coastguard Workerchar16_t*
513*58b9f456SAndroid Build Coastguard Workerchar_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
514*58b9f456SAndroid Build Coastguard Worker{
515*58b9f456SAndroid Build Coastguard Worker    char_type* __r = __s;
516*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n, ++__s)
517*58b9f456SAndroid Build Coastguard Worker        assign(*__s, __a);
518*58b9f456SAndroid Build Coastguard Worker    return __r;
519*58b9f456SAndroid Build Coastguard Worker}
520*58b9f456SAndroid Build Coastguard Worker
521*58b9f456SAndroid Build Coastguard Workertemplate <>
522*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS char_traits<char32_t>
523*58b9f456SAndroid Build Coastguard Worker{
524*58b9f456SAndroid Build Coastguard Worker    typedef char32_t       char_type;
525*58b9f456SAndroid Build Coastguard Worker    typedef uint_least32_t int_type;
526*58b9f456SAndroid Build Coastguard Worker    typedef streamoff      off_type;
527*58b9f456SAndroid Build Coastguard Worker    typedef u32streampos   pos_type;
528*58b9f456SAndroid Build Coastguard Worker    typedef mbstate_t      state_type;
529*58b9f456SAndroid Build Coastguard Worker
530*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
531*58b9f456SAndroid Build Coastguard Worker    void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
532*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
533*58b9f456SAndroid Build Coastguard Worker        {return __c1 == __c2;}
534*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
535*58b9f456SAndroid Build Coastguard Worker        {return __c1 < __c2;}
536*58b9f456SAndroid Build Coastguard Worker
537*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
538*58b9f456SAndroid Build Coastguard Worker    int              compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
539*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
540*58b9f456SAndroid Build Coastguard Worker    size_t           length(const char_type* __s) _NOEXCEPT;
541*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
542*58b9f456SAndroid Build Coastguard Worker    const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
543*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
544*58b9f456SAndroid Build Coastguard Worker    static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
545*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
546*58b9f456SAndroid Build Coastguard Worker    static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
547*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
548*58b9f456SAndroid Build Coastguard Worker    static char_type*       assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT;
549*58b9f456SAndroid Build Coastguard Worker
550*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR int_type  not_eof(int_type __c) _NOEXCEPT
551*58b9f456SAndroid Build Coastguard Worker        {return eq_int_type(__c, eof()) ? ~eof() : __c;}
552*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
553*58b9f456SAndroid Build Coastguard Worker        {return char_type(__c);}
554*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
555*58b9f456SAndroid Build Coastguard Worker        {return int_type(__c);}
556*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
557*58b9f456SAndroid Build Coastguard Worker        {return __c1 == __c2;}
558*58b9f456SAndroid Build Coastguard Worker    static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
559*58b9f456SAndroid Build Coastguard Worker        {return int_type(0xFFFFFFFF);}
560*58b9f456SAndroid Build Coastguard Worker};
561*58b9f456SAndroid Build Coastguard Worker
562*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_CONSTEXPR_AFTER_CXX14
563*58b9f456SAndroid Build Coastguard Workerint
564*58b9f456SAndroid Build Coastguard Workerchar_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
565*58b9f456SAndroid Build Coastguard Worker{
566*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n, ++__s1, ++__s2)
567*58b9f456SAndroid Build Coastguard Worker    {
568*58b9f456SAndroid Build Coastguard Worker        if (lt(*__s1, *__s2))
569*58b9f456SAndroid Build Coastguard Worker            return -1;
570*58b9f456SAndroid Build Coastguard Worker        if (lt(*__s2, *__s1))
571*58b9f456SAndroid Build Coastguard Worker            return 1;
572*58b9f456SAndroid Build Coastguard Worker    }
573*58b9f456SAndroid Build Coastguard Worker    return 0;
574*58b9f456SAndroid Build Coastguard Worker}
575*58b9f456SAndroid Build Coastguard Worker
576*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_CONSTEXPR_AFTER_CXX14
577*58b9f456SAndroid Build Coastguard Workersize_t
578*58b9f456SAndroid Build Coastguard Workerchar_traits<char32_t>::length(const char_type* __s) _NOEXCEPT
579*58b9f456SAndroid Build Coastguard Worker{
580*58b9f456SAndroid Build Coastguard Worker    size_t __len = 0;
581*58b9f456SAndroid Build Coastguard Worker    for (; !eq(*__s, char_type(0)); ++__s)
582*58b9f456SAndroid Build Coastguard Worker        ++__len;
583*58b9f456SAndroid Build Coastguard Worker    return __len;
584*58b9f456SAndroid Build Coastguard Worker}
585*58b9f456SAndroid Build Coastguard Worker
586*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_CONSTEXPR_AFTER_CXX14
587*58b9f456SAndroid Build Coastguard Workerconst char32_t*
588*58b9f456SAndroid Build Coastguard Workerchar_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
589*58b9f456SAndroid Build Coastguard Worker{
590*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n)
591*58b9f456SAndroid Build Coastguard Worker    {
592*58b9f456SAndroid Build Coastguard Worker        if (eq(*__s, __a))
593*58b9f456SAndroid Build Coastguard Worker            return __s;
594*58b9f456SAndroid Build Coastguard Worker        ++__s;
595*58b9f456SAndroid Build Coastguard Worker    }
596*58b9f456SAndroid Build Coastguard Worker    return 0;
597*58b9f456SAndroid Build Coastguard Worker}
598*58b9f456SAndroid Build Coastguard Worker
599*58b9f456SAndroid Build Coastguard Workerinline
600*58b9f456SAndroid Build Coastguard Workerchar32_t*
601*58b9f456SAndroid Build Coastguard Workerchar_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
602*58b9f456SAndroid Build Coastguard Worker{
603*58b9f456SAndroid Build Coastguard Worker    char_type* __r = __s1;
604*58b9f456SAndroid Build Coastguard Worker    if (__s1 < __s2)
605*58b9f456SAndroid Build Coastguard Worker    {
606*58b9f456SAndroid Build Coastguard Worker        for (; __n; --__n, ++__s1, ++__s2)
607*58b9f456SAndroid Build Coastguard Worker            assign(*__s1, *__s2);
608*58b9f456SAndroid Build Coastguard Worker    }
609*58b9f456SAndroid Build Coastguard Worker    else if (__s2 < __s1)
610*58b9f456SAndroid Build Coastguard Worker    {
611*58b9f456SAndroid Build Coastguard Worker        __s1 += __n;
612*58b9f456SAndroid Build Coastguard Worker        __s2 += __n;
613*58b9f456SAndroid Build Coastguard Worker        for (; __n; --__n)
614*58b9f456SAndroid Build Coastguard Worker            assign(*--__s1, *--__s2);
615*58b9f456SAndroid Build Coastguard Worker    }
616*58b9f456SAndroid Build Coastguard Worker    return __r;
617*58b9f456SAndroid Build Coastguard Worker}
618*58b9f456SAndroid Build Coastguard Worker
619*58b9f456SAndroid Build Coastguard Workerinline
620*58b9f456SAndroid Build Coastguard Workerchar32_t*
621*58b9f456SAndroid Build Coastguard Workerchar_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
622*58b9f456SAndroid Build Coastguard Worker{
623*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
624*58b9f456SAndroid Build Coastguard Worker    char_type* __r = __s1;
625*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n, ++__s1, ++__s2)
626*58b9f456SAndroid Build Coastguard Worker        assign(*__s1, *__s2);
627*58b9f456SAndroid Build Coastguard Worker    return __r;
628*58b9f456SAndroid Build Coastguard Worker}
629*58b9f456SAndroid Build Coastguard Worker
630*58b9f456SAndroid Build Coastguard Workerinline
631*58b9f456SAndroid Build Coastguard Workerchar32_t*
632*58b9f456SAndroid Build Coastguard Workerchar_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
633*58b9f456SAndroid Build Coastguard Worker{
634*58b9f456SAndroid Build Coastguard Worker    char_type* __r = __s;
635*58b9f456SAndroid Build Coastguard Worker    for (; __n; --__n, ++__s)
636*58b9f456SAndroid Build Coastguard Worker        assign(*__s, __a);
637*58b9f456SAndroid Build Coastguard Worker    return __r;
638*58b9f456SAndroid Build Coastguard Worker}
639*58b9f456SAndroid Build Coastguard Worker
640*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
641*58b9f456SAndroid Build Coastguard Worker
642*58b9f456SAndroid Build Coastguard Worker// helper fns for basic_string and string_view
643*58b9f456SAndroid Build Coastguard Worker
644*58b9f456SAndroid Build Coastguard Worker// __str_find
645*58b9f456SAndroid Build Coastguard Workertemplate<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
646*58b9f456SAndroid Build Coastguard Workerinline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
647*58b9f456SAndroid Build Coastguard Worker__str_find(const _CharT *__p, _SizeT __sz,
648*58b9f456SAndroid Build Coastguard Worker             _CharT __c, _SizeT __pos) _NOEXCEPT
649*58b9f456SAndroid Build Coastguard Worker{
650*58b9f456SAndroid Build Coastguard Worker    if (__pos >= __sz)
651*58b9f456SAndroid Build Coastguard Worker        return __npos;
652*58b9f456SAndroid Build Coastguard Worker    const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
653*58b9f456SAndroid Build Coastguard Worker    if (__r == 0)
654*58b9f456SAndroid Build Coastguard Worker        return __npos;
655*58b9f456SAndroid Build Coastguard Worker    return static_cast<_SizeT>(__r - __p);
656*58b9f456SAndroid Build Coastguard Worker}
657*58b9f456SAndroid Build Coastguard Worker
658*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _Traits>
659*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_CONSTEXPR_AFTER_CXX11 const _CharT *
660*58b9f456SAndroid Build Coastguard Worker__search_substring(const _CharT *__first1, const _CharT *__last1,
661*58b9f456SAndroid Build Coastguard Worker                   const _CharT *__first2, const _CharT *__last2) {
662*58b9f456SAndroid Build Coastguard Worker  // Take advantage of knowing source and pattern lengths.
663*58b9f456SAndroid Build Coastguard Worker  // Stop short when source is smaller than pattern.
664*58b9f456SAndroid Build Coastguard Worker  const ptrdiff_t __len2 = __last2 - __first2;
665*58b9f456SAndroid Build Coastguard Worker  if (__len2 == 0)
666*58b9f456SAndroid Build Coastguard Worker    return __first1;
667*58b9f456SAndroid Build Coastguard Worker
668*58b9f456SAndroid Build Coastguard Worker  ptrdiff_t __len1 = __last1 - __first1;
669*58b9f456SAndroid Build Coastguard Worker  if (__len1 < __len2)
670*58b9f456SAndroid Build Coastguard Worker    return __last1;
671*58b9f456SAndroid Build Coastguard Worker
672*58b9f456SAndroid Build Coastguard Worker  // First element of __first2 is loop invariant.
673*58b9f456SAndroid Build Coastguard Worker  _CharT __f2 = *__first2;
674*58b9f456SAndroid Build Coastguard Worker  while (true) {
675*58b9f456SAndroid Build Coastguard Worker    __len1 = __last1 - __first1;
676*58b9f456SAndroid Build Coastguard Worker    // Check whether __first1 still has at least __len2 bytes.
677*58b9f456SAndroid Build Coastguard Worker    if (__len1 < __len2)
678*58b9f456SAndroid Build Coastguard Worker      return __last1;
679*58b9f456SAndroid Build Coastguard Worker
680*58b9f456SAndroid Build Coastguard Worker    // Find __f2 the first byte matching in __first1.
681*58b9f456SAndroid Build Coastguard Worker    __first1 = _Traits::find(__first1, __len1 - __len2 + 1, __f2);
682*58b9f456SAndroid Build Coastguard Worker    if (__first1 == 0)
683*58b9f456SAndroid Build Coastguard Worker      return __last1;
684*58b9f456SAndroid Build Coastguard Worker
685*58b9f456SAndroid Build Coastguard Worker    // It is faster to compare from the first byte of __first1 even if we
686*58b9f456SAndroid Build Coastguard Worker    // already know that it matches the first byte of __first2: this is because
687*58b9f456SAndroid Build Coastguard Worker    // __first2 is most likely aligned, as it is user's "pattern" string, and
688*58b9f456SAndroid Build Coastguard Worker    // __first1 + 1 is most likely not aligned, as the match is in the middle of
689*58b9f456SAndroid Build Coastguard Worker    // the string.
690*58b9f456SAndroid Build Coastguard Worker    if (_Traits::compare(__first1, __first2, __len2) == 0)
691*58b9f456SAndroid Build Coastguard Worker      return __first1;
692*58b9f456SAndroid Build Coastguard Worker
693*58b9f456SAndroid Build Coastguard Worker    ++__first1;
694*58b9f456SAndroid Build Coastguard Worker  }
695*58b9f456SAndroid Build Coastguard Worker}
696*58b9f456SAndroid Build Coastguard Worker
697*58b9f456SAndroid Build Coastguard Workertemplate<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
698*58b9f456SAndroid Build Coastguard Workerinline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
699*58b9f456SAndroid Build Coastguard Worker__str_find(const _CharT *__p, _SizeT __sz,
700*58b9f456SAndroid Build Coastguard Worker       const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
701*58b9f456SAndroid Build Coastguard Worker{
702*58b9f456SAndroid Build Coastguard Worker    if (__pos > __sz)
703*58b9f456SAndroid Build Coastguard Worker        return __npos;
704*58b9f456SAndroid Build Coastguard Worker
705*58b9f456SAndroid Build Coastguard Worker    if (__n == 0) // There is nothing to search, just return __pos.
706*58b9f456SAndroid Build Coastguard Worker        return __pos;
707*58b9f456SAndroid Build Coastguard Worker
708*58b9f456SAndroid Build Coastguard Worker    const _CharT *__r = __search_substring<_CharT, _Traits>(
709*58b9f456SAndroid Build Coastguard Worker        __p + __pos, __p + __sz, __s, __s + __n);
710*58b9f456SAndroid Build Coastguard Worker
711*58b9f456SAndroid Build Coastguard Worker    if (__r == __p + __sz)
712*58b9f456SAndroid Build Coastguard Worker        return __npos;
713*58b9f456SAndroid Build Coastguard Worker    return static_cast<_SizeT>(__r - __p);
714*58b9f456SAndroid Build Coastguard Worker}
715*58b9f456SAndroid Build Coastguard Worker
716*58b9f456SAndroid Build Coastguard Worker
717*58b9f456SAndroid Build Coastguard Worker// __str_rfind
718*58b9f456SAndroid Build Coastguard Worker
719*58b9f456SAndroid Build Coastguard Workertemplate<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
720*58b9f456SAndroid Build Coastguard Workerinline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
721*58b9f456SAndroid Build Coastguard Worker__str_rfind(const _CharT *__p, _SizeT __sz,
722*58b9f456SAndroid Build Coastguard Worker              _CharT __c, _SizeT __pos) _NOEXCEPT
723*58b9f456SAndroid Build Coastguard Worker{
724*58b9f456SAndroid Build Coastguard Worker    if (__sz < 1)
725*58b9f456SAndroid Build Coastguard Worker        return __npos;
726*58b9f456SAndroid Build Coastguard Worker    if (__pos < __sz)
727*58b9f456SAndroid Build Coastguard Worker        ++__pos;
728*58b9f456SAndroid Build Coastguard Worker    else
729*58b9f456SAndroid Build Coastguard Worker        __pos = __sz;
730*58b9f456SAndroid Build Coastguard Worker    for (const _CharT* __ps = __p + __pos; __ps != __p;)
731*58b9f456SAndroid Build Coastguard Worker    {
732*58b9f456SAndroid Build Coastguard Worker        if (_Traits::eq(*--__ps, __c))
733*58b9f456SAndroid Build Coastguard Worker            return static_cast<_SizeT>(__ps - __p);
734*58b9f456SAndroid Build Coastguard Worker    }
735*58b9f456SAndroid Build Coastguard Worker    return __npos;
736*58b9f456SAndroid Build Coastguard Worker}
737*58b9f456SAndroid Build Coastguard Worker
738*58b9f456SAndroid Build Coastguard Workertemplate<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
739*58b9f456SAndroid Build Coastguard Workerinline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
740*58b9f456SAndroid Build Coastguard Worker__str_rfind(const _CharT *__p, _SizeT __sz,
741*58b9f456SAndroid Build Coastguard Worker        const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
742*58b9f456SAndroid Build Coastguard Worker{
743*58b9f456SAndroid Build Coastguard Worker    __pos = _VSTD::min(__pos, __sz);
744*58b9f456SAndroid Build Coastguard Worker    if (__n < __sz - __pos)
745*58b9f456SAndroid Build Coastguard Worker        __pos += __n;
746*58b9f456SAndroid Build Coastguard Worker    else
747*58b9f456SAndroid Build Coastguard Worker        __pos = __sz;
748*58b9f456SAndroid Build Coastguard Worker    const _CharT* __r = _VSTD::__find_end(
749*58b9f456SAndroid Build Coastguard Worker                  __p, __p + __pos, __s, __s + __n, _Traits::eq,
750*58b9f456SAndroid Build Coastguard Worker                        random_access_iterator_tag(), random_access_iterator_tag());
751*58b9f456SAndroid Build Coastguard Worker    if (__n > 0 && __r == __p + __pos)
752*58b9f456SAndroid Build Coastguard Worker        return __npos;
753*58b9f456SAndroid Build Coastguard Worker    return static_cast<_SizeT>(__r - __p);
754*58b9f456SAndroid Build Coastguard Worker}
755*58b9f456SAndroid Build Coastguard Worker
756*58b9f456SAndroid Build Coastguard Worker// __str_find_first_of
757*58b9f456SAndroid Build Coastguard Workertemplate<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
758*58b9f456SAndroid Build Coastguard Workerinline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
759*58b9f456SAndroid Build Coastguard Worker__str_find_first_of(const _CharT *__p, _SizeT __sz,
760*58b9f456SAndroid Build Coastguard Worker                const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
761*58b9f456SAndroid Build Coastguard Worker{
762*58b9f456SAndroid Build Coastguard Worker    if (__pos >= __sz || __n == 0)
763*58b9f456SAndroid Build Coastguard Worker        return __npos;
764*58b9f456SAndroid Build Coastguard Worker    const _CharT* __r = _VSTD::__find_first_of_ce
765*58b9f456SAndroid Build Coastguard Worker        (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
766*58b9f456SAndroid Build Coastguard Worker    if (__r == __p + __sz)
767*58b9f456SAndroid Build Coastguard Worker        return __npos;
768*58b9f456SAndroid Build Coastguard Worker    return static_cast<_SizeT>(__r - __p);
769*58b9f456SAndroid Build Coastguard Worker}
770*58b9f456SAndroid Build Coastguard Worker
771*58b9f456SAndroid Build Coastguard Worker
772*58b9f456SAndroid Build Coastguard Worker// __str_find_last_of
773*58b9f456SAndroid Build Coastguard Workertemplate<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
774*58b9f456SAndroid Build Coastguard Workerinline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
775*58b9f456SAndroid Build Coastguard Worker__str_find_last_of(const _CharT *__p, _SizeT __sz,
776*58b9f456SAndroid Build Coastguard Worker               const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
777*58b9f456SAndroid Build Coastguard Worker    {
778*58b9f456SAndroid Build Coastguard Worker    if (__n != 0)
779*58b9f456SAndroid Build Coastguard Worker    {
780*58b9f456SAndroid Build Coastguard Worker        if (__pos < __sz)
781*58b9f456SAndroid Build Coastguard Worker            ++__pos;
782*58b9f456SAndroid Build Coastguard Worker        else
783*58b9f456SAndroid Build Coastguard Worker            __pos = __sz;
784*58b9f456SAndroid Build Coastguard Worker        for (const _CharT* __ps = __p + __pos; __ps != __p;)
785*58b9f456SAndroid Build Coastguard Worker        {
786*58b9f456SAndroid Build Coastguard Worker            const _CharT* __r = _Traits::find(__s, __n, *--__ps);
787*58b9f456SAndroid Build Coastguard Worker            if (__r)
788*58b9f456SAndroid Build Coastguard Worker                return static_cast<_SizeT>(__ps - __p);
789*58b9f456SAndroid Build Coastguard Worker        }
790*58b9f456SAndroid Build Coastguard Worker    }
791*58b9f456SAndroid Build Coastguard Worker    return __npos;
792*58b9f456SAndroid Build Coastguard Worker}
793*58b9f456SAndroid Build Coastguard Worker
794*58b9f456SAndroid Build Coastguard Worker
795*58b9f456SAndroid Build Coastguard Worker// __str_find_first_not_of
796*58b9f456SAndroid Build Coastguard Workertemplate<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
797*58b9f456SAndroid Build Coastguard Workerinline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
798*58b9f456SAndroid Build Coastguard Worker__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
799*58b9f456SAndroid Build Coastguard Worker                    const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
800*58b9f456SAndroid Build Coastguard Worker{
801*58b9f456SAndroid Build Coastguard Worker    if (__pos < __sz)
802*58b9f456SAndroid Build Coastguard Worker    {
803*58b9f456SAndroid Build Coastguard Worker        const _CharT* __pe = __p + __sz;
804*58b9f456SAndroid Build Coastguard Worker        for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
805*58b9f456SAndroid Build Coastguard Worker            if (_Traits::find(__s, __n, *__ps) == 0)
806*58b9f456SAndroid Build Coastguard Worker                return static_cast<_SizeT>(__ps - __p);
807*58b9f456SAndroid Build Coastguard Worker    }
808*58b9f456SAndroid Build Coastguard Worker    return __npos;
809*58b9f456SAndroid Build Coastguard Worker}
810*58b9f456SAndroid Build Coastguard Worker
811*58b9f456SAndroid Build Coastguard Worker
812*58b9f456SAndroid Build Coastguard Workertemplate<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
813*58b9f456SAndroid Build Coastguard Workerinline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
814*58b9f456SAndroid Build Coastguard Worker__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
815*58b9f456SAndroid Build Coastguard Worker                          _CharT __c, _SizeT __pos) _NOEXCEPT
816*58b9f456SAndroid Build Coastguard Worker{
817*58b9f456SAndroid Build Coastguard Worker    if (__pos < __sz)
818*58b9f456SAndroid Build Coastguard Worker    {
819*58b9f456SAndroid Build Coastguard Worker        const _CharT* __pe = __p + __sz;
820*58b9f456SAndroid Build Coastguard Worker        for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
821*58b9f456SAndroid Build Coastguard Worker            if (!_Traits::eq(*__ps, __c))
822*58b9f456SAndroid Build Coastguard Worker                return static_cast<_SizeT>(__ps - __p);
823*58b9f456SAndroid Build Coastguard Worker    }
824*58b9f456SAndroid Build Coastguard Worker    return __npos;
825*58b9f456SAndroid Build Coastguard Worker}
826*58b9f456SAndroid Build Coastguard Worker
827*58b9f456SAndroid Build Coastguard Worker
828*58b9f456SAndroid Build Coastguard Worker// __str_find_last_not_of
829*58b9f456SAndroid Build Coastguard Workertemplate<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
830*58b9f456SAndroid Build Coastguard Workerinline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
831*58b9f456SAndroid Build Coastguard Worker__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
832*58b9f456SAndroid Build Coastguard Worker                   const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
833*58b9f456SAndroid Build Coastguard Worker{
834*58b9f456SAndroid Build Coastguard Worker    if (__pos < __sz)
835*58b9f456SAndroid Build Coastguard Worker        ++__pos;
836*58b9f456SAndroid Build Coastguard Worker    else
837*58b9f456SAndroid Build Coastguard Worker        __pos = __sz;
838*58b9f456SAndroid Build Coastguard Worker    for (const _CharT* __ps = __p + __pos; __ps != __p;)
839*58b9f456SAndroid Build Coastguard Worker        if (_Traits::find(__s, __n, *--__ps) == 0)
840*58b9f456SAndroid Build Coastguard Worker            return static_cast<_SizeT>(__ps - __p);
841*58b9f456SAndroid Build Coastguard Worker    return __npos;
842*58b9f456SAndroid Build Coastguard Worker}
843*58b9f456SAndroid Build Coastguard Worker
844*58b9f456SAndroid Build Coastguard Worker
845*58b9f456SAndroid Build Coastguard Workertemplate<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
846*58b9f456SAndroid Build Coastguard Workerinline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
847*58b9f456SAndroid Build Coastguard Worker__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
848*58b9f456SAndroid Build Coastguard Worker                         _CharT __c, _SizeT __pos) _NOEXCEPT
849*58b9f456SAndroid Build Coastguard Worker{
850*58b9f456SAndroid Build Coastguard Worker    if (__pos < __sz)
851*58b9f456SAndroid Build Coastguard Worker        ++__pos;
852*58b9f456SAndroid Build Coastguard Worker    else
853*58b9f456SAndroid Build Coastguard Worker        __pos = __sz;
854*58b9f456SAndroid Build Coastguard Worker    for (const _CharT* __ps = __p + __pos; __ps != __p;)
855*58b9f456SAndroid Build Coastguard Worker        if (!_Traits::eq(*--__ps, __c))
856*58b9f456SAndroid Build Coastguard Worker            return static_cast<_SizeT>(__ps - __p);
857*58b9f456SAndroid Build Coastguard Worker    return __npos;
858*58b9f456SAndroid Build Coastguard Worker}
859*58b9f456SAndroid Build Coastguard Worker
860*58b9f456SAndroid Build Coastguard Workertemplate<class _Ptr>
861*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
862*58b9f456SAndroid Build Coastguard Workersize_t __do_string_hash(_Ptr __p, _Ptr __e)
863*58b9f456SAndroid Build Coastguard Worker{
864*58b9f456SAndroid Build Coastguard Worker    typedef typename iterator_traits<_Ptr>::value_type value_type;
865*58b9f456SAndroid Build Coastguard Worker    return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
866*58b9f456SAndroid Build Coastguard Worker}
867*58b9f456SAndroid Build Coastguard Worker
868*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _Iter, class _Traits=char_traits<_CharT> >
869*58b9f456SAndroid Build Coastguard Workerstruct __quoted_output_proxy
870*58b9f456SAndroid Build Coastguard Worker{
871*58b9f456SAndroid Build Coastguard Worker    _Iter  __first;
872*58b9f456SAndroid Build Coastguard Worker    _Iter  __last;
873*58b9f456SAndroid Build Coastguard Worker    _CharT  __delim;
874*58b9f456SAndroid Build Coastguard Worker    _CharT  __escape;
875*58b9f456SAndroid Build Coastguard Worker
876*58b9f456SAndroid Build Coastguard Worker    __quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e)
877*58b9f456SAndroid Build Coastguard Worker    : __first(__f), __last(__l), __delim(__d), __escape(__e) {}
878*58b9f456SAndroid Build Coastguard Worker    //  This would be a nice place for a string_ref
879*58b9f456SAndroid Build Coastguard Worker};
880*58b9f456SAndroid Build Coastguard Worker
881*58b9f456SAndroid Build Coastguard Worker_LIBCPP_END_NAMESPACE_STD
882*58b9f456SAndroid Build Coastguard Worker
883*58b9f456SAndroid Build Coastguard Worker_LIBCPP_POP_MACROS
884*58b9f456SAndroid Build Coastguard Worker
885*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP___STRING
886