2 //===-------------------------- __string ----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP___STRING
12 #define _LIBCPP___STRING
20 template <class charT>
23 typedef charT char_type;
25 typedef streamoff off_type;
26 typedef streampos pos_type;
27 typedef mbstate_t state_type;
29 static constexpr void assign(char_type& c1, const char_type& c2) noexcept;
30 static constexpr bool eq(char_type c1, char_type c2) noexcept;
31 static constexpr bool lt(char_type c1, char_type c2) noexcept;
33 static constexpr int compare(const char_type* s1, const char_type* s2, size_t n);
34 static constexpr size_t length(const char_type* s);
35 static constexpr const char_type*
36 find(const char_type* s, size_t n, const char_type& a);
37 static char_type* move(char_type* s1, const char_type* s2, size_t n);
38 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
39 static char_type* assign(char_type* s, size_t n, char_type a);
41 static constexpr int_type not_eof(int_type c) noexcept;
42 static constexpr char_type to_char_type(int_type c) noexcept;
43 static constexpr int_type to_int_type(char_type c) noexcept;
44 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
45 static constexpr int_type eof() noexcept;
48 template <> struct char_traits<char>;
49 template <> struct char_traits<wchar_t>;
56 #include <algorithm> // for search and min
57 #include <cstdio> // For EOF.
58 #include <memory> // for __murmur2_or_cityhash
60 #include <__undef_min_max>
64 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
65 #pragma GCC system_header
68 _LIBCPP_BEGIN_NAMESPACE_STD
72 template <class _CharT>
73 struct _LIBCPP_TEMPLATE_VIS char_traits
75 typedef _CharT char_type;
77 typedef streamoff off_type;
78 typedef streampos pos_type;
79 typedef mbstate_t state_type;
81 static inline void _LIBCPP_CONSTEXPR_AFTER_CXX14
82 assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
83 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
84 {return __c1 == __c2;}
85 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
88 static _LIBCPP_CONSTEXPR_AFTER_CXX14
89 int compare(const char_type* __s1, const char_type* __s2, size_t __n);
90 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
91 size_t length(const char_type* __s);
92 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
93 const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
94 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
95 _LIBCPP_INLINE_VISIBILITY
96 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
97 _LIBCPP_INLINE_VISIBILITY
98 static char_type* assign(char_type* __s, size_t __n, char_type __a);
100 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
101 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
102 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
103 {return char_type(__c);}
104 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
105 {return int_type(__c);}
106 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
107 {return __c1 == __c2;}
108 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
109 {return int_type(EOF);}
112 template <class _CharT>
113 _LIBCPP_CONSTEXPR_AFTER_CXX14 int
114 char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
116 for (; __n; --__n, ++__s1, ++__s2)
118 if (lt(*__s1, *__s2))
120 if (lt(*__s2, *__s1))
126 template <class _CharT>
128 _LIBCPP_CONSTEXPR_AFTER_CXX14 size_t
129 char_traits<_CharT>::length(const char_type* __s)
132 for (; !eq(*__s, char_type(0)); ++__s)
137 template <class _CharT>
139 _LIBCPP_CONSTEXPR_AFTER_CXX14 const _CharT*
140 char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
151 template <class _CharT>
153 char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
155 char_type* __r = __s1;
158 for (; __n; --__n, ++__s1, ++__s2)
159 assign(*__s1, *__s2);
161 else if (__s2 < __s1)
166 assign(*--__s1, *--__s2);
171 template <class _CharT>
174 char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
176 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
177 char_type* __r = __s1;
178 for (; __n; --__n, ++__s1, ++__s2)
179 assign(*__s1, *__s2);
183 template <class _CharT>
186 char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
188 char_type* __r = __s;
189 for (; __n; --__n, ++__s)
197 struct _LIBCPP_TEMPLATE_VIS char_traits<char>
199 typedef char char_type;
200 typedef int int_type;
201 typedef streamoff off_type;
202 typedef streampos pos_type;
203 typedef mbstate_t state_type;
205 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
206 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
207 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
208 {return __c1 == __c2;}
209 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
210 {return (unsigned char)__c1 < (unsigned char)__c2;}
212 static _LIBCPP_CONSTEXPR_AFTER_CXX14
213 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
214 static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14
215 length(const char_type* __s) _NOEXCEPT {return __builtin_strlen(__s);}
216 static _LIBCPP_CONSTEXPR_AFTER_CXX14
217 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
218 static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
219 {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);}
220 static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
222 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
223 return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n);
225 static inline char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
226 {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);}
228 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
229 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
230 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
231 {return char_type(__c);}
232 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
233 {return int_type((unsigned char)__c);}
234 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
235 {return __c1 == __c2;}
236 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
237 {return int_type(EOF);}
240 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
242 char_traits<char>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
246 #if __has_feature(cxx_constexpr_string_builtins)
247 return __builtin_memcmp(__s1, __s2, __n);
248 #elif _LIBCPP_STD_VER <= 14
249 return memcmp(__s1, __s2, __n);
251 for (; __n; --__n, ++__s1, ++__s2)
253 if (lt(*__s1, *__s2))
255 if (lt(*__s2, *__s1))
262 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
264 char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
268 #if __has_feature(cxx_constexpr_string_builtins)
269 return __builtin_char_memchr(__s, to_int_type(__a), __n);
270 #elif _LIBCPP_STD_VER <= 14
271 return (const char_type*) memchr(__s, to_int_type(__a), __n);
284 // char_traits<wchar_t>
287 struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
289 typedef wchar_t char_type;
290 typedef wint_t int_type;
291 typedef streamoff off_type;
292 typedef streampos pos_type;
293 typedef mbstate_t state_type;
295 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
296 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
297 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
298 {return __c1 == __c2;}
299 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
300 {return __c1 < __c2;}
302 static _LIBCPP_CONSTEXPR_AFTER_CXX14
303 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
304 static _LIBCPP_CONSTEXPR_AFTER_CXX14
305 size_t length(const char_type* __s) _NOEXCEPT;
306 static _LIBCPP_CONSTEXPR_AFTER_CXX14
307 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
308 static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
309 {return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);}
310 static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
312 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
313 return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n);
315 static inline char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
316 {return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);}
318 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
319 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
320 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
321 {return char_type(__c);}
322 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
323 {return int_type(__c);}
324 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
325 {return __c1 == __c2;}
326 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
327 {return int_type(WEOF);}
330 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
332 char_traits<wchar_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
336 #if __has_feature(cxx_constexpr_string_builtins)
337 return __builtin_wmemcmp(__s1, __s2, __n);
338 #elif _LIBCPP_STD_VER <= 14
339 return wmemcmp(__s1, __s2, __n);
341 for (; __n; --__n, ++__s1, ++__s2)
343 if (lt(*__s1, *__s2))
345 if (lt(*__s2, *__s1))
352 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
354 char_traits<wchar_t>::length(const char_type* __s) _NOEXCEPT
356 #if __has_feature(cxx_constexpr_string_builtins)
357 return __builtin_wcslen(__s);
358 #elif _LIBCPP_STD_VER <= 14
362 for (; !eq(*__s, char_type(0)); ++__s)
368 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
370 char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
374 #if __has_feature(cxx_constexpr_string_builtins)
375 return __builtin_wmemchr(__s, __a, __n);
376 #elif _LIBCPP_STD_VER <= 14
377 return wmemchr(__s, __a, __n);
390 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
393 struct _LIBCPP_TEMPLATE_VIS char_traits<char16_t>
395 typedef char16_t char_type;
396 typedef uint_least16_t int_type;
397 typedef streamoff off_type;
398 typedef u16streampos pos_type;
399 typedef mbstate_t state_type;
401 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
402 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
403 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
404 {return __c1 == __c2;}
405 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
406 {return __c1 < __c2;}
408 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
409 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
410 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
411 size_t length(const char_type* __s) _NOEXCEPT;
412 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
413 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
414 _LIBCPP_INLINE_VISIBILITY
415 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
416 _LIBCPP_INLINE_VISIBILITY
417 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
418 _LIBCPP_INLINE_VISIBILITY
419 static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT;
421 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
422 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
423 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
424 {return char_type(__c);}
425 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
426 {return int_type(__c);}
427 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
428 {return __c1 == __c2;}
429 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
430 {return int_type(0xFFFF);}
433 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
435 char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
437 for (; __n; --__n, ++__s1, ++__s2)
439 if (lt(*__s1, *__s2))
441 if (lt(*__s2, *__s1))
447 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
449 char_traits<char16_t>::length(const char_type* __s) _NOEXCEPT
452 for (; !eq(*__s, char_type(0)); ++__s)
457 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
459 char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
472 char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
474 char_type* __r = __s1;
477 for (; __n; --__n, ++__s1, ++__s2)
478 assign(*__s1, *__s2);
480 else if (__s2 < __s1)
485 assign(*--__s1, *--__s2);
492 char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
494 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
495 char_type* __r = __s1;
496 for (; __n; --__n, ++__s1, ++__s2)
497 assign(*__s1, *__s2);
503 char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
505 char_type* __r = __s;
506 for (; __n; --__n, ++__s)
512 struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t>
514 typedef char32_t char_type;
515 typedef uint_least32_t int_type;
516 typedef streamoff off_type;
517 typedef u32streampos pos_type;
518 typedef mbstate_t state_type;
520 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
521 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
522 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
523 {return __c1 == __c2;}
524 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
525 {return __c1 < __c2;}
527 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
528 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
529 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
530 size_t length(const char_type* __s) _NOEXCEPT;
531 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
532 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
533 _LIBCPP_INLINE_VISIBILITY
534 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
535 _LIBCPP_INLINE_VISIBILITY
536 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
537 _LIBCPP_INLINE_VISIBILITY
538 static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT;
540 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
541 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
542 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
543 {return char_type(__c);}
544 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
545 {return int_type(__c);}
546 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
547 {return __c1 == __c2;}
548 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
549 {return int_type(0xFFFFFFFF);}
552 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
554 char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
556 for (; __n; --__n, ++__s1, ++__s2)
558 if (lt(*__s1, *__s2))
560 if (lt(*__s2, *__s1))
566 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
568 char_traits<char32_t>::length(const char_type* __s) _NOEXCEPT
571 for (; !eq(*__s, char_type(0)); ++__s)
576 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
578 char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
591 char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
593 char_type* __r = __s1;
596 for (; __n; --__n, ++__s1, ++__s2)
597 assign(*__s1, *__s2);
599 else if (__s2 < __s1)
604 assign(*--__s1, *--__s2);
611 char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
613 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
614 char_type* __r = __s1;
615 for (; __n; --__n, ++__s1, ++__s2)
616 assign(*__s1, *__s2);
622 char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
624 char_type* __r = __s;
625 for (; __n; --__n, ++__s)
630 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
632 // helper fns for basic_string and string_view
635 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
636 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
637 __str_find(const _CharT *__p, _SizeT __sz,
638 _CharT __c, _SizeT __pos) _NOEXCEPT
642 const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
645 return static_cast<_SizeT>(__r - __p);
648 template <class _CharT, class _Traits>
649 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 const _CharT *
650 __search_substring(const _CharT *__first1, const _CharT *__last1,
651 const _CharT *__first2, const _CharT *__last2) {
652 // Take advantage of knowing source and pattern lengths.
653 // Stop short when source is smaller than pattern.
654 const ptrdiff_t __len2 = __last2 - __first2;
658 ptrdiff_t __len1 = __last1 - __first1;
662 // First element of __first2 is loop invariant.
663 _CharT __f2 = *__first2;
665 __len1 = __last1 - __first1;
666 // Check whether __first1 still has at least __len2 bytes.
670 // Find __f2 the first byte matching in __first1.
671 __first1 = _Traits::find(__first1, __len1 - __len2 + 1, __f2);
675 // It is faster to compare from the first byte of __first1 even if we
676 // already know that it matches the first byte of __first2: this is because
677 // __first2 is most likely aligned, as it is user's "pattern" string, and
678 // __first1 + 1 is most likely not aligned, as the match is in the middle of
680 if (_Traits::compare(__first1, __first2, __len2) == 0)
687 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
688 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
689 __str_find(const _CharT *__p, _SizeT __sz,
690 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
695 if (__n == 0) // There is nothing to search, just return __pos.
698 const _CharT *__r = __search_substring<_CharT, _Traits>(
699 __p + __pos, __p + __sz, __s, __s + __n);
701 if (__r == __p + __sz)
703 return static_cast<_SizeT>(__r - __p);
709 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
710 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
711 __str_rfind(const _CharT *__p, _SizeT __sz,
712 _CharT __c, _SizeT __pos) _NOEXCEPT
720 for (const _CharT* __ps = __p + __pos; __ps != __p;)
722 if (_Traits::eq(*--__ps, __c))
723 return static_cast<_SizeT>(__ps - __p);
728 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
729 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
730 __str_rfind(const _CharT *__p, _SizeT __sz,
731 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
733 __pos = _VSTD::min(__pos, __sz);
734 if (__n < __sz - __pos)
738 const _CharT* __r = _VSTD::__find_end(
739 __p, __p + __pos, __s, __s + __n, _Traits::eq,
740 random_access_iterator_tag(), random_access_iterator_tag());
741 if (__n > 0 && __r == __p + __pos)
743 return static_cast<_SizeT>(__r - __p);
746 // __str_find_first_of
747 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
748 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
749 __str_find_first_of(const _CharT *__p, _SizeT __sz,
750 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
752 if (__pos >= __sz || __n == 0)
754 const _CharT* __r = _VSTD::__find_first_of_ce
755 (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
756 if (__r == __p + __sz)
758 return static_cast<_SizeT>(__r - __p);
762 // __str_find_last_of
763 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
764 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
765 __str_find_last_of(const _CharT *__p, _SizeT __sz,
766 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
774 for (const _CharT* __ps = __p + __pos; __ps != __p;)
776 const _CharT* __r = _Traits::find(__s, __n, *--__ps);
778 return static_cast<_SizeT>(__ps - __p);
785 // __str_find_first_not_of
786 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
787 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
788 __str_find_first_not_of(const _CharT *__p, _SizeT __sz,
789 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
793 const _CharT* __pe = __p + __sz;
794 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
795 if (_Traits::find(__s, __n, *__ps) == 0)
796 return static_cast<_SizeT>(__ps - __p);
802 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
803 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
804 __str_find_first_not_of(const _CharT *__p, _SizeT __sz,
805 _CharT __c, _SizeT __pos) _NOEXCEPT
809 const _CharT* __pe = __p + __sz;
810 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
811 if (!_Traits::eq(*__ps, __c))
812 return static_cast<_SizeT>(__ps - __p);
818 // __str_find_last_not_of
819 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
820 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
821 __str_find_last_not_of(const _CharT *__p, _SizeT __sz,
822 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
828 for (const _CharT* __ps = __p + __pos; __ps != __p;)
829 if (_Traits::find(__s, __n, *--__ps) == 0)
830 return static_cast<_SizeT>(__ps - __p);
835 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
836 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
837 __str_find_last_not_of(const _CharT *__p, _SizeT __sz,
838 _CharT __c, _SizeT __pos) _NOEXCEPT
844 for (const _CharT* __ps = __p + __pos; __ps != __p;)
845 if (!_Traits::eq(*--__ps, __c))
846 return static_cast<_SizeT>(__ps - __p);
851 inline _LIBCPP_INLINE_VISIBILITY
852 size_t __do_string_hash(_Ptr __p, _Ptr __e)
854 typedef typename iterator_traits<_Ptr>::value_type value_type;
855 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
858 template <class _CharT, class _Iter, class _Traits=char_traits<_CharT> >
859 struct __quoted_output_proxy
866 __quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e)
867 : __first(__f), __last(__l), __delim(__d), __escape(__e) {}
868 // This would be a nice place for a string_ref
871 _LIBCPP_END_NAMESPACE_STD
873 #endif // _LIBCPP___STRING