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 #ifdef _LIBCPP_BUILTIN_MEMCMP_ISCONSTEXPR
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 _LIBCPP_STD_VER <= 14
269 return (const char_type*) memchr(__s, to_int_type(__a), __n);
282 // char_traits<wchar_t>
285 struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
287 typedef wchar_t char_type;
288 typedef wint_t int_type;
289 typedef streamoff off_type;
290 typedef streampos pos_type;
291 typedef mbstate_t state_type;
293 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
294 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
295 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
296 {return __c1 == __c2;}
297 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
298 {return __c1 < __c2;}
300 static _LIBCPP_CONSTEXPR_AFTER_CXX14
301 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
302 static _LIBCPP_CONSTEXPR_AFTER_CXX14
303 size_t length(const char_type* __s) _NOEXCEPT;
304 static _LIBCPP_CONSTEXPR_AFTER_CXX14
305 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
306 static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
307 {return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);}
308 static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
310 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
311 return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n);
313 static inline char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
314 {return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);}
316 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
317 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
318 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
319 {return char_type(__c);}
320 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
321 {return int_type(__c);}
322 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
323 {return __c1 == __c2;}
324 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
325 {return int_type(WEOF);}
328 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
330 char_traits<wchar_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
334 #if __has_builtin(__builtin_wmemcmp)
335 return __builtin_wmemcmp(__s1, __s2, __n);
336 #elif _LIBCPP_STD_VER <= 14
337 return wmemcmp(__s1, __s2, __n);
339 for (; __n; --__n, ++__s1, ++__s2)
341 if (lt(*__s1, *__s2))
343 if (lt(*__s2, *__s1))
350 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
352 char_traits<wchar_t>::length(const char_type* __s) _NOEXCEPT
354 #if __has_builtin(__builtin_wcslen)
355 return __builtin_wcslen(__s);
356 #elif _LIBCPP_STD_VER <= 14
360 for (; !eq(*__s, char_type(0)); ++__s)
366 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
368 char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
372 #if __has_builtin(__builtin_wmemchr)
373 return __builtin_wmemchr(__s, __a, __n);
374 #elif _LIBCPP_STD_VER <= 14
375 return wmemchr(__s, __a, __n);
388 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
391 struct _LIBCPP_TEMPLATE_VIS char_traits<char16_t>
393 typedef char16_t char_type;
394 typedef uint_least16_t int_type;
395 typedef streamoff off_type;
396 typedef u16streampos pos_type;
397 typedef mbstate_t state_type;
399 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
400 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
401 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
402 {return __c1 == __c2;}
403 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
404 {return __c1 < __c2;}
406 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
407 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
408 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
409 size_t length(const char_type* __s) _NOEXCEPT;
410 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
411 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
412 _LIBCPP_INLINE_VISIBILITY
413 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
414 _LIBCPP_INLINE_VISIBILITY
415 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
416 _LIBCPP_INLINE_VISIBILITY
417 static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT;
419 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
420 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
421 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
422 {return char_type(__c);}
423 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
424 {return int_type(__c);}
425 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
426 {return __c1 == __c2;}
427 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
428 {return int_type(0xFFFF);}
431 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
433 char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
435 for (; __n; --__n, ++__s1, ++__s2)
437 if (lt(*__s1, *__s2))
439 if (lt(*__s2, *__s1))
445 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
447 char_traits<char16_t>::length(const char_type* __s) _NOEXCEPT
450 for (; !eq(*__s, char_type(0)); ++__s)
455 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
457 char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
470 char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
472 char_type* __r = __s1;
475 for (; __n; --__n, ++__s1, ++__s2)
476 assign(*__s1, *__s2);
478 else if (__s2 < __s1)
483 assign(*--__s1, *--__s2);
490 char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
492 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
493 char_type* __r = __s1;
494 for (; __n; --__n, ++__s1, ++__s2)
495 assign(*__s1, *__s2);
501 char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
503 char_type* __r = __s;
504 for (; __n; --__n, ++__s)
510 struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t>
512 typedef char32_t char_type;
513 typedef uint_least32_t int_type;
514 typedef streamoff off_type;
515 typedef u32streampos pos_type;
516 typedef mbstate_t state_type;
518 static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
519 void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
520 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
521 {return __c1 == __c2;}
522 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
523 {return __c1 < __c2;}
525 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
526 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
527 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
528 size_t length(const char_type* __s) _NOEXCEPT;
529 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
530 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
531 _LIBCPP_INLINE_VISIBILITY
532 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
533 _LIBCPP_INLINE_VISIBILITY
534 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
535 _LIBCPP_INLINE_VISIBILITY
536 static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT;
538 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
539 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
540 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
541 {return char_type(__c);}
542 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
543 {return int_type(__c);}
544 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
545 {return __c1 == __c2;}
546 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
547 {return int_type(0xFFFFFFFF);}
550 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
552 char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
554 for (; __n; --__n, ++__s1, ++__s2)
556 if (lt(*__s1, *__s2))
558 if (lt(*__s2, *__s1))
564 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
566 char_traits<char32_t>::length(const char_type* __s) _NOEXCEPT
569 for (; !eq(*__s, char_type(0)); ++__s)
574 inline _LIBCPP_CONSTEXPR_AFTER_CXX14
576 char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
589 char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
591 char_type* __r = __s1;
594 for (; __n; --__n, ++__s1, ++__s2)
595 assign(*__s1, *__s2);
597 else if (__s2 < __s1)
602 assign(*--__s1, *--__s2);
609 char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
611 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
612 char_type* __r = __s1;
613 for (; __n; --__n, ++__s1, ++__s2)
614 assign(*__s1, *__s2);
620 char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
622 char_type* __r = __s;
623 for (; __n; --__n, ++__s)
628 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
630 // helper fns for basic_string and string_view
633 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
634 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
635 __str_find(const _CharT *__p, _SizeT __sz,
636 _CharT __c, _SizeT __pos) _NOEXCEPT
640 const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
643 return static_cast<_SizeT>(__r - __p);
646 template <class _CharT, class _Traits>
647 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 const _CharT *
648 __search_substring(const _CharT *__first1, const _CharT *__last1,
649 const _CharT *__first2, const _CharT *__last2) {
650 // Take advantage of knowing source and pattern lengths.
651 // Stop short when source is smaller than pattern.
652 const ptrdiff_t __len2 = __last2 - __first2;
656 ptrdiff_t __len1 = __last1 - __first1;
660 // First element of __first2 is loop invariant.
661 _CharT __f2 = *__first2;
663 __len1 = __last1 - __first1;
664 // Check whether __first1 still has at least __len2 bytes.
668 // Find __f2 the first byte matching in __first1.
669 __first1 = _Traits::find(__first1, __len1 - __len2 + 1, __f2);
673 // It is faster to compare from the first byte of __first1 even if we
674 // already know that it matches the first byte of __first2: this is because
675 // __first2 is most likely aligned, as it is user's "pattern" string, and
676 // __first1 + 1 is most likely not aligned, as the match is in the middle of
678 if (_Traits::compare(__first1, __first2, __len2) == 0)
685 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
686 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
687 __str_find(const _CharT *__p, _SizeT __sz,
688 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
693 if (__n == 0) // There is nothing to search, just return __pos.
696 const _CharT *__r = __search_substring<_CharT, _Traits>(
697 __p + __pos, __p + __sz, __s, __s + __n);
699 if (__r == __p + __sz)
701 return static_cast<_SizeT>(__r - __p);
707 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
708 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
709 __str_rfind(const _CharT *__p, _SizeT __sz,
710 _CharT __c, _SizeT __pos) _NOEXCEPT
718 for (const _CharT* __ps = __p + __pos; __ps != __p;)
720 if (_Traits::eq(*--__ps, __c))
721 return static_cast<_SizeT>(__ps - __p);
726 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
727 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
728 __str_rfind(const _CharT *__p, _SizeT __sz,
729 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
731 __pos = _VSTD::min(__pos, __sz);
732 if (__n < __sz - __pos)
736 const _CharT* __r = _VSTD::__find_end(
737 __p, __p + __pos, __s, __s + __n, _Traits::eq,
738 random_access_iterator_tag(), random_access_iterator_tag());
739 if (__n > 0 && __r == __p + __pos)
741 return static_cast<_SizeT>(__r - __p);
744 // __str_find_first_of
745 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
746 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
747 __str_find_first_of(const _CharT *__p, _SizeT __sz,
748 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
750 if (__pos >= __sz || __n == 0)
752 const _CharT* __r = _VSTD::__find_first_of_ce
753 (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
754 if (__r == __p + __sz)
756 return static_cast<_SizeT>(__r - __p);
760 // __str_find_last_of
761 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
762 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
763 __str_find_last_of(const _CharT *__p, _SizeT __sz,
764 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
772 for (const _CharT* __ps = __p + __pos; __ps != __p;)
774 const _CharT* __r = _Traits::find(__s, __n, *--__ps);
776 return static_cast<_SizeT>(__ps - __p);
783 // __str_find_first_not_of
784 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
785 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
786 __str_find_first_not_of(const _CharT *__p, _SizeT __sz,
787 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
791 const _CharT* __pe = __p + __sz;
792 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
793 if (_Traits::find(__s, __n, *__ps) == 0)
794 return static_cast<_SizeT>(__ps - __p);
800 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
801 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
802 __str_find_first_not_of(const _CharT *__p, _SizeT __sz,
803 _CharT __c, _SizeT __pos) _NOEXCEPT
807 const _CharT* __pe = __p + __sz;
808 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
809 if (!_Traits::eq(*__ps, __c))
810 return static_cast<_SizeT>(__ps - __p);
816 // __str_find_last_not_of
817 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
818 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
819 __str_find_last_not_of(const _CharT *__p, _SizeT __sz,
820 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
826 for (const _CharT* __ps = __p + __pos; __ps != __p;)
827 if (_Traits::find(__s, __n, *--__ps) == 0)
828 return static_cast<_SizeT>(__ps - __p);
833 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
834 inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
835 __str_find_last_not_of(const _CharT *__p, _SizeT __sz,
836 _CharT __c, _SizeT __pos) _NOEXCEPT
842 for (const _CharT* __ps = __p + __pos; __ps != __p;)
843 if (!_Traits::eq(*--__ps, __c))
844 return static_cast<_SizeT>(__ps - __p);
849 inline _LIBCPP_INLINE_VISIBILITY
850 size_t __do_string_hash(_Ptr __p, _Ptr __e)
852 typedef typename iterator_traits<_Ptr>::value_type value_type;
853 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
856 template <class _CharT, class _Iter, class _Traits=char_traits<_CharT> >
857 struct __quoted_output_proxy
864 __quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e)
865 : __first(__f), __last(__l), __delim(__d), __escape(__e) {}
866 // This would be a nice place for a string_ref
869 _LIBCPP_END_NAMESPACE_STD
871 #endif // _LIBCPP___STRING