Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===-------------------------- __string ----------------------------------===// |
| 3 | // |
Chandler Carruth | 7642bb1 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___STRING |
| 11 | #define _LIBCPP___STRING |
| 12 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 13 | #include <__config> |
| 14 | #include <algorithm> // for search and min |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 15 | #include <cstdio> // for EOF |
| 16 | #include <cstring> // for memcpy |
| 17 | #include <cwchar> // for wmemcpy |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 18 | #include <memory> // for __murmur2_or_cityhash |
| 19 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 20 | #include <__debug> |
| 21 | |
| 22 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 23 | #pragma GCC system_header |
| 24 | #endif |
| 25 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 26 | _LIBCPP_PUSH_MACROS |
| 27 | #include <__undef_macros> |
| 28 | |
| 29 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 30 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 31 | |
Eric Fiselier | 5dcce5c | 2020-01-15 17:12:09 -0500 | [diff] [blame] | 32 | // The the extern template ABI lists are kept outside of <string> to improve the |
| 33 | // readability of that header. |
Martijn Vels | 1e63ba0 | 2020-02-19 16:27:50 -0500 | [diff] [blame] | 34 | |
| 35 | // The extern template ABI lists are kept outside of <string> to improve the |
| 36 | // readability of that header. We maintain 2 ABI lists: |
| 37 | // - _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST |
| 38 | // - _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST |
| 39 | // As the name implies, the ABI lists define the V1 (Stable) and unstable ABI. |
| 40 | // |
| 41 | // For unstable, we may explicitly remove function that are external in V1, |
| 42 | // and add (new) external functions to better control inlining and compiler |
| 43 | // optimization opportunities. |
| 44 | // |
| 45 | // For stable, the ABI list should rarely change, except for adding new |
| 46 | // functions supporting new c++ version / API changes. Typically entries |
| 47 | // must never be removed from the stable list. |
| 48 | #define _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_Func, _CharType) \ |
| 49 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \ |
| 50 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \ |
| 51 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \ |
| 52 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&)) \ |
| 53 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \ |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 54 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&, allocator<_CharType> const&)) \ |
Martijn Vels | 1e63ba0 | 2020-02-19 16:27:50 -0500 | [diff] [blame] | 55 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_not_of(value_type const*, size_type, size_type) const) \ |
| 56 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::~basic_string()) \ |
| 57 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_not_of(value_type const*, size_type, size_type) const) \ |
| 58 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, size_type, value_type)) \ |
| 59 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::operator=(value_type)) \ |
| 60 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type)) \ |
| 61 | _Func(_LIBCPP_FUNC_VIS const _CharType& basic_string<_CharType>::at(size_type) const) \ |
| 62 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*, size_type)) \ |
| 63 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_of(value_type const*, size_type, size_type) const) \ |
| 64 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, size_type, value_type)) \ |
| 65 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(value_type const*, size_type)) \ |
| 66 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::reserve(size_type)) \ |
| 67 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*, size_type)) \ |
| 68 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(basic_string const&, size_type, size_type)) \ |
| 69 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::copy(value_type*, size_type, size_type) const) \ |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 70 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&, size_type, size_type, allocator<_CharType> const&)) \ |
Martijn Vels | 1e63ba0 | 2020-02-19 16:27:50 -0500 | [diff] [blame] | 71 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type, size_type) const) \ |
| 72 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(size_type, value_type)) \ |
| 73 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*)) \ |
| 74 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_of(value_type const*, size_type, size_type) const) \ |
| 75 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by(size_type, size_type, size_type, size_type, size_type, size_type)) \ |
| 76 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by_and_replace(size_type, size_type, size_type, size_type, size_type, size_type, value_type const*)) \ |
| 77 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::push_back(value_type)) \ |
| 78 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(size_type, value_type)) \ |
| 79 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type, size_type) const) \ |
| 80 | _Func(_LIBCPP_FUNC_VIS const basic_string<_CharType>::size_type basic_string<_CharType>::npos) \ |
| 81 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(size_type, value_type)) \ |
| 82 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::erase(size_type, size_type)) \ |
| 83 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(basic_string const&, size_type, size_type)) \ |
| 84 | _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(value_type const*) const) \ |
| 85 | _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*) const) \ |
| 86 | _Func(_LIBCPP_FUNC_VIS _CharType& basic_string<_CharType>::at(size_type)) \ |
| 87 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(value_type const*)) \ |
| 88 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type const*, size_type, size_type) const) \ |
| 89 | _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, basic_string const&, size_type, size_type) const) \ |
| 90 | _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*, size_type) const) \ |
| 91 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::operator=(basic_string const&)) \ |
| 92 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*)) \ |
| 93 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, basic_string const&, size_type, size_type)) \ |
| 94 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::iterator basic_string<_CharType>::insert(basic_string::const_iterator, value_type)) \ |
| 95 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::resize(size_type, value_type)) \ |
| 96 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, basic_string const&, size_type, size_type)) |
| 97 | |
| 98 | #define _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_Func, _CharType) \ |
Eric Fiselier | 5dcce5c | 2020-01-15 17:12:09 -0500 | [diff] [blame] | 99 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \ |
| 100 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \ |
| 101 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \ |
Eric Fiselier | 5dcce5c | 2020-01-15 17:12:09 -0500 | [diff] [blame] | 102 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \ |
Eric Fiselier | 5dcce5c | 2020-01-15 17:12:09 -0500 | [diff] [blame] | 103 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_not_of(value_type const*, size_type, size_type) const) \ |
| 104 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::~basic_string()) \ |
| 105 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_not_of(value_type const*, size_type, size_type) const) \ |
| 106 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, size_type, value_type)) \ |
| 107 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::operator=(value_type)) \ |
| 108 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(value_type const*, size_type)) \ |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 109 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init_copy_ctor_external(value_type const*, size_type)) \ |
Eric Fiselier | 5dcce5c | 2020-01-15 17:12:09 -0500 | [diff] [blame] | 110 | _Func(_LIBCPP_FUNC_VIS const _CharType& basic_string<_CharType>::at(size_type) const) \ |
| 111 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*, size_type)) \ |
| 112 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_first_of(value_type const*, size_type, size_type) const) \ |
| 113 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, size_type, value_type)) \ |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 114 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_external(value_type const*, size_type)) \ |
| 115 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_external(value_type const*)) \ |
Eric Fiselier | 5dcce5c | 2020-01-15 17:12:09 -0500 | [diff] [blame] | 116 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::reserve(size_type)) \ |
| 117 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*, size_type)) \ |
| 118 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(basic_string const&, size_type, size_type)) \ |
| 119 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::copy(value_type*, size_type, size_type) const) \ |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 120 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::basic_string(basic_string const&, size_type, size_type, allocator<_CharType> const&)) \ |
Eric Fiselier | 5dcce5c | 2020-01-15 17:12:09 -0500 | [diff] [blame] | 121 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type, size_type) const) \ |
| 122 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__init(size_type, value_type)) \ |
| 123 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*)) \ |
| 124 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find_last_of(value_type const*, size_type, size_type) const) \ |
| 125 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by(size_type, size_type, size_type, size_type, size_type, size_type)) \ |
| 126 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__grow_by_and_replace(size_type, size_type, size_type, size_type, size_type, size_type, value_type const*)) \ |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 127 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_no_alias<false>(value_type const*, size_type)) \ |
| 128 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::__assign_no_alias<true>(value_type const*, size_type)) \ |
Eric Fiselier | 5dcce5c | 2020-01-15 17:12:09 -0500 | [diff] [blame] | 129 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::push_back(value_type)) \ |
| 130 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(size_type, value_type)) \ |
| 131 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type, size_type) const) \ |
| 132 | _Func(_LIBCPP_FUNC_VIS const basic_string<_CharType>::size_type basic_string<_CharType>::npos) \ |
| 133 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::assign(size_type, value_type)) \ |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 134 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::__erase_external_with_move(size_type, size_type)) \ |
Eric Fiselier | 5dcce5c | 2020-01-15 17:12:09 -0500 | [diff] [blame] | 135 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(basic_string const&, size_type, size_type)) \ |
| 136 | _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(value_type const*) const) \ |
| 137 | _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*) const) \ |
| 138 | _Func(_LIBCPP_FUNC_VIS _CharType& basic_string<_CharType>::at(size_type)) \ |
Eric Fiselier | 5dcce5c | 2020-01-15 17:12:09 -0500 | [diff] [blame] | 139 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type const*, size_type, size_type) const) \ |
| 140 | _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, basic_string const&, size_type, size_type) const) \ |
| 141 | _Func(_LIBCPP_FUNC_VIS int basic_string<_CharType>::compare(size_type, size_type, value_type const*, size_type) const) \ |
Eric Fiselier | 5dcce5c | 2020-01-15 17:12:09 -0500 | [diff] [blame] | 142 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::append(value_type const*)) \ |
| 143 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, basic_string const&, size_type, size_type)) \ |
| 144 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>::iterator basic_string<_CharType>::insert(basic_string::const_iterator, value_type)) \ |
| 145 | _Func(_LIBCPP_FUNC_VIS void basic_string<_CharType>::resize(size_type, value_type)) \ |
| 146 | _Func(_LIBCPP_FUNC_VIS basic_string<_CharType>& basic_string<_CharType>::insert(size_type, basic_string const&, size_type, size_type)) |
| 147 | |
| 148 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 149 | // char_traits |
| 150 | |
| 151 | template <class _CharT> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 152 | struct _LIBCPP_TEMPLATE_VIS char_traits |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 153 | { |
| 154 | typedef _CharT char_type; |
| 155 | typedef int int_type; |
| 156 | typedef streamoff off_type; |
| 157 | typedef streampos pos_type; |
| 158 | typedef mbstate_t state_type; |
| 159 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 160 | static inline void _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 161 | assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 162 | static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT |
| 163 | {return __c1 == __c2;} |
| 164 | static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT |
| 165 | {return __c1 < __c2;} |
| 166 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 167 | static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 168 | int compare(const char_type* __s1, const char_type* __s2, size_t __n); |
| 169 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 170 | size_t length(const char_type* __s); |
| 171 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 172 | const char_type* find(const char_type* __s, size_t __n, const char_type& __a); |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 173 | static _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 174 | char_type* move(char_type* __s1, const char_type* __s2, size_t __n); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 175 | _LIBCPP_INLINE_VISIBILITY |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 176 | static _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 177 | char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 178 | _LIBCPP_INLINE_VISIBILITY |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 179 | static _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 180 | char_type* assign(char_type* __s, size_t __n, char_type __a); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 181 | |
| 182 | static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT |
| 183 | {return eq_int_type(__c, eof()) ? ~eof() : __c;} |
| 184 | static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT |
| 185 | {return char_type(__c);} |
| 186 | static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT |
| 187 | {return int_type(__c);} |
| 188 | static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT |
| 189 | {return __c1 == __c2;} |
| 190 | static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT |
| 191 | {return int_type(EOF);} |
| 192 | }; |
| 193 | |
| 194 | template <class _CharT> |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 195 | _LIBCPP_CONSTEXPR_AFTER_CXX14 int |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 196 | char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n) |
| 197 | { |
| 198 | for (; __n; --__n, ++__s1, ++__s2) |
| 199 | { |
| 200 | if (lt(*__s1, *__s2)) |
| 201 | return -1; |
| 202 | if (lt(*__s2, *__s1)) |
| 203 | return 1; |
| 204 | } |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | template <class _CharT> |
| 209 | inline |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 210 | _LIBCPP_CONSTEXPR_AFTER_CXX14 size_t |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 211 | char_traits<_CharT>::length(const char_type* __s) |
| 212 | { |
| 213 | size_t __len = 0; |
| 214 | for (; !eq(*__s, char_type(0)); ++__s) |
| 215 | ++__len; |
| 216 | return __len; |
| 217 | } |
| 218 | |
| 219 | template <class _CharT> |
| 220 | inline |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 221 | _LIBCPP_CONSTEXPR_AFTER_CXX14 const _CharT* |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 222 | char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a) |
| 223 | { |
| 224 | for (; __n; --__n) |
| 225 | { |
| 226 | if (eq(*__s, __a)) |
| 227 | return __s; |
| 228 | ++__s; |
| 229 | } |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 230 | return nullptr; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | template <class _CharT> |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 234 | _LIBCPP_CONSTEXPR_AFTER_CXX17 _CharT* |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 235 | char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n) |
| 236 | { |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 237 | if (__n == 0) return __s1; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 238 | char_type* __r = __s1; |
| 239 | if (__s1 < __s2) |
| 240 | { |
| 241 | for (; __n; --__n, ++__s1, ++__s2) |
| 242 | assign(*__s1, *__s2); |
| 243 | } |
| 244 | else if (__s2 < __s1) |
| 245 | { |
| 246 | __s1 += __n; |
| 247 | __s2 += __n; |
| 248 | for (; __n; --__n) |
| 249 | assign(*--__s1, *--__s2); |
| 250 | } |
| 251 | return __r; |
| 252 | } |
| 253 | |
| 254 | template <class _CharT> |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 255 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 256 | _CharT* |
| 257 | char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n) |
| 258 | { |
| 259 | _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); |
| 260 | char_type* __r = __s1; |
| 261 | for (; __n; --__n, ++__s1, ++__s2) |
| 262 | assign(*__s1, *__s2); |
| 263 | return __r; |
| 264 | } |
| 265 | |
| 266 | template <class _CharT> |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 267 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 268 | _CharT* |
| 269 | char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a) |
| 270 | { |
| 271 | char_type* __r = __s; |
| 272 | for (; __n; --__n, ++__s) |
| 273 | assign(*__s, __a); |
| 274 | return __r; |
| 275 | } |
| 276 | |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 277 | // constexpr versions of move/copy/assign. |
| 278 | |
| 279 | template <class _CharT> |
Arthur O'Dwyer | 14606d1 | 2020-11-23 12:44:41 -0500 | [diff] [blame] | 280 | static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 281 | _CharT* __move_constexpr(_CharT* __s1, const _CharT* __s2, size_t __n) _NOEXCEPT |
| 282 | { |
| 283 | if (__n == 0) return __s1; |
| 284 | if (__s1 < __s2) { |
| 285 | _VSTD::copy(__s2, __s2 + __n, __s1); |
| 286 | } else if (__s2 < __s1) { |
| 287 | _VSTD::copy_backward(__s2, __s2 + __n, __s1 + __n); |
| 288 | } |
| 289 | return __s1; |
| 290 | } |
| 291 | |
| 292 | template <class _CharT> |
Arthur O'Dwyer | 14606d1 | 2020-11-23 12:44:41 -0500 | [diff] [blame] | 293 | static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 294 | _CharT* __copy_constexpr(_CharT* __s1, const _CharT* __s2, size_t __n) _NOEXCEPT |
| 295 | { |
| 296 | _VSTD::copy_n(__s2, __n, __s1); |
| 297 | return __s1; |
| 298 | } |
| 299 | |
| 300 | template <class _CharT> |
Arthur O'Dwyer | 14606d1 | 2020-11-23 12:44:41 -0500 | [diff] [blame] | 301 | static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 302 | _CharT* __assign_constexpr(_CharT* __s, size_t __n, _CharT __a) _NOEXCEPT |
| 303 | { |
| 304 | _VSTD::fill_n(__s, __n, __a); |
| 305 | return __s; |
| 306 | } |
| 307 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 308 | // char_traits<char> |
| 309 | |
| 310 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 311 | struct _LIBCPP_TEMPLATE_VIS char_traits<char> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 312 | { |
| 313 | typedef char char_type; |
| 314 | typedef int int_type; |
| 315 | typedef streamoff off_type; |
| 316 | typedef streampos pos_type; |
| 317 | typedef mbstate_t state_type; |
| 318 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 319 | static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 320 | void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 321 | static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT |
| 322 | {return __c1 == __c2;} |
| 323 | static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT |
| 324 | {return (unsigned char)__c1 < (unsigned char)__c2;} |
| 325 | |
Marshall Clow | aa32f16 | 2017-01-12 05:40:58 +0000 | [diff] [blame] | 326 | static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 327 | int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 328 | static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 329 | length(const char_type* __s) _NOEXCEPT {return __builtin_strlen(__s);} |
| 330 | static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 331 | const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; |
Arthur O'Dwyer | 14606d1 | 2020-11-23 12:44:41 -0500 | [diff] [blame] | 332 | static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 333 | char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
| 334 | { |
| 335 | return __libcpp_is_constant_evaluated() |
Arthur O'Dwyer | e75dcfa | 2020-11-22 13:21:11 -0500 | [diff] [blame] | 336 | ? _VSTD::__move_constexpr(__s1, __s2, __n) |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 337 | : __n == 0 ? __s1 : (char_type*)_VSTD::memmove(__s1, __s2, __n); |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 338 | } |
Arthur O'Dwyer | 14606d1 | 2020-11-23 12:44:41 -0500 | [diff] [blame] | 339 | static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 340 | char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 341 | { |
| 342 | _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 343 | return __libcpp_is_constant_evaluated() |
Arthur O'Dwyer | e75dcfa | 2020-11-22 13:21:11 -0500 | [diff] [blame] | 344 | ? _VSTD::__copy_constexpr(__s1, __s2, __n) |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 345 | : __n == 0 ? __s1 : (char_type*)_VSTD::memcpy(__s1, __s2, __n); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 346 | } |
Arthur O'Dwyer | 14606d1 | 2020-11-23 12:44:41 -0500 | [diff] [blame] | 347 | static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 348 | char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT |
| 349 | { |
| 350 | return __libcpp_is_constant_evaluated() |
Arthur O'Dwyer | e75dcfa | 2020-11-22 13:21:11 -0500 | [diff] [blame] | 351 | ? _VSTD::__assign_constexpr(__s, __n, __a) |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 352 | : __n == 0 ? __s : (char_type*)_VSTD::memset(__s, to_int_type(__a), __n); |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 353 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 354 | |
| 355 | static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT |
| 356 | {return eq_int_type(__c, eof()) ? ~eof() : __c;} |
| 357 | static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT |
| 358 | {return char_type(__c);} |
| 359 | static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT |
| 360 | {return int_type((unsigned char)__c);} |
| 361 | static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT |
| 362 | {return __c1 == __c2;} |
| 363 | static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT |
| 364 | {return int_type(EOF);} |
| 365 | }; |
| 366 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 367 | inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | aa32f16 | 2017-01-12 05:40:58 +0000 | [diff] [blame] | 368 | int |
| 369 | char_traits<char>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
| 370 | { |
| 371 | if (__n == 0) |
| 372 | return 0; |
Marshall Clow | b344c36 | 2017-01-26 06:58:29 +0000 | [diff] [blame] | 373 | #if __has_feature(cxx_constexpr_string_builtins) |
Marshall Clow | aa32f16 | 2017-01-12 05:40:58 +0000 | [diff] [blame] | 374 | return __builtin_memcmp(__s1, __s2, __n); |
| 375 | #elif _LIBCPP_STD_VER <= 14 |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 376 | return _VSTD::memcmp(__s1, __s2, __n); |
Marshall Clow | aa32f16 | 2017-01-12 05:40:58 +0000 | [diff] [blame] | 377 | #else |
| 378 | for (; __n; --__n, ++__s1, ++__s2) |
| 379 | { |
| 380 | if (lt(*__s1, *__s2)) |
| 381 | return -1; |
| 382 | if (lt(*__s2, *__s1)) |
| 383 | return 1; |
| 384 | } |
| 385 | return 0; |
| 386 | #endif |
| 387 | } |
| 388 | |
| 389 | inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 390 | const char* |
| 391 | char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT |
| 392 | { |
| 393 | if (__n == 0) |
Marshall Clow | 32043ac | 2018-02-06 18:58:05 +0000 | [diff] [blame] | 394 | return nullptr; |
Marshall Clow | b344c36 | 2017-01-26 06:58:29 +0000 | [diff] [blame] | 395 | #if __has_feature(cxx_constexpr_string_builtins) |
| 396 | return __builtin_char_memchr(__s, to_int_type(__a), __n); |
| 397 | #elif _LIBCPP_STD_VER <= 14 |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 398 | return (const char_type*) _VSTD::memchr(__s, to_int_type(__a), __n); |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 399 | #else |
| 400 | for (; __n; --__n) |
| 401 | { |
| 402 | if (eq(*__s, __a)) |
| 403 | return __s; |
| 404 | ++__s; |
| 405 | } |
Marshall Clow | 32043ac | 2018-02-06 18:58:05 +0000 | [diff] [blame] | 406 | return nullptr; |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 407 | #endif |
| 408 | } |
| 409 | |
| 410 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 411 | // char_traits<wchar_t> |
| 412 | |
| 413 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 414 | struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 415 | { |
| 416 | typedef wchar_t char_type; |
| 417 | typedef wint_t int_type; |
| 418 | typedef streamoff off_type; |
| 419 | typedef streampos pos_type; |
| 420 | typedef mbstate_t state_type; |
| 421 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 422 | static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 423 | void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 424 | static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT |
| 425 | {return __c1 == __c2;} |
| 426 | static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT |
| 427 | {return __c1 < __c2;} |
| 428 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 429 | static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 430 | int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; |
| 431 | static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 432 | size_t length(const char_type* __s) _NOEXCEPT; |
| 433 | static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 434 | const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; |
Arthur O'Dwyer | 14606d1 | 2020-11-23 12:44:41 -0500 | [diff] [blame] | 435 | static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 436 | char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
| 437 | { |
| 438 | return __libcpp_is_constant_evaluated() |
Arthur O'Dwyer | e75dcfa | 2020-11-22 13:21:11 -0500 | [diff] [blame] | 439 | ? _VSTD::__move_constexpr(__s1, __s2, __n) |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 440 | : __n == 0 ? __s1 : _VSTD::wmemmove(__s1, __s2, __n); |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 441 | } |
Arthur O'Dwyer | 14606d1 | 2020-11-23 12:44:41 -0500 | [diff] [blame] | 442 | static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 443 | char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 444 | { |
| 445 | _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 446 | return __libcpp_is_constant_evaluated() |
Arthur O'Dwyer | e75dcfa | 2020-11-22 13:21:11 -0500 | [diff] [blame] | 447 | ? _VSTD::__copy_constexpr(__s1, __s2, __n) |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 448 | : __n == 0 ? __s1 : _VSTD::wmemcpy(__s1, __s2, __n); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 449 | } |
Arthur O'Dwyer | 14606d1 | 2020-11-23 12:44:41 -0500 | [diff] [blame] | 450 | static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 451 | char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT |
| 452 | { |
| 453 | return __libcpp_is_constant_evaluated() |
Arthur O'Dwyer | e75dcfa | 2020-11-22 13:21:11 -0500 | [diff] [blame] | 454 | ? _VSTD::__assign_constexpr(__s, __n, __a) |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 455 | : __n == 0 ? __s : _VSTD::wmemset(__s, __a, __n); |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 456 | } |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 457 | static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT |
| 458 | {return eq_int_type(__c, eof()) ? ~eof() : __c;} |
| 459 | static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT |
| 460 | {return char_type(__c);} |
| 461 | static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT |
| 462 | {return int_type(__c);} |
| 463 | static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT |
| 464 | {return __c1 == __c2;} |
| 465 | static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT |
| 466 | {return int_type(WEOF);} |
| 467 | }; |
| 468 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 469 | inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 470 | int |
| 471 | char_traits<wchar_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
| 472 | { |
| 473 | if (__n == 0) |
| 474 | return 0; |
Marshall Clow | b344c36 | 2017-01-26 06:58:29 +0000 | [diff] [blame] | 475 | #if __has_feature(cxx_constexpr_string_builtins) |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 476 | return __builtin_wmemcmp(__s1, __s2, __n); |
| 477 | #elif _LIBCPP_STD_VER <= 14 |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 478 | return _VSTD::wmemcmp(__s1, __s2, __n); |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 479 | #else |
| 480 | for (; __n; --__n, ++__s1, ++__s2) |
| 481 | { |
| 482 | if (lt(*__s1, *__s2)) |
| 483 | return -1; |
| 484 | if (lt(*__s2, *__s1)) |
| 485 | return 1; |
| 486 | } |
| 487 | return 0; |
| 488 | #endif |
| 489 | } |
| 490 | |
Eric Fiselier | d36a76c | 2019-09-14 19:55:28 +0000 | [diff] [blame] | 491 | |
| 492 | template <class _Traits> |
| 493 | _LIBCPP_INLINE_VISIBILITY |
| 494 | _LIBCPP_CONSTEXPR |
| 495 | inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT { |
| 496 | #if _LIBCPP_DEBUG_LEVEL >= 1 |
| 497 | return __s ? _Traits::length(__s) : (_VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, "p == nullptr", "null pointer pass to non-null argument of char_traits<...>::length")), 0); |
| 498 | #else |
| 499 | return _Traits::length(__s); |
| 500 | #endif |
| 501 | } |
| 502 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 503 | inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 504 | size_t |
| 505 | char_traits<wchar_t>::length(const char_type* __s) _NOEXCEPT |
| 506 | { |
Marshall Clow | b344c36 | 2017-01-26 06:58:29 +0000 | [diff] [blame] | 507 | #if __has_feature(cxx_constexpr_string_builtins) |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 508 | return __builtin_wcslen(__s); |
| 509 | #elif _LIBCPP_STD_VER <= 14 |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 510 | return _VSTD::wcslen(__s); |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 511 | #else |
| 512 | size_t __len = 0; |
| 513 | for (; !eq(*__s, char_type(0)); ++__s) |
| 514 | ++__len; |
| 515 | return __len; |
| 516 | #endif |
| 517 | } |
| 518 | |
| 519 | inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 520 | const wchar_t* |
| 521 | char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT |
| 522 | { |
| 523 | if (__n == 0) |
Marshall Clow | 32043ac | 2018-02-06 18:58:05 +0000 | [diff] [blame] | 524 | return nullptr; |
Marshall Clow | b344c36 | 2017-01-26 06:58:29 +0000 | [diff] [blame] | 525 | #if __has_feature(cxx_constexpr_string_builtins) |
Marshall Clow | 32043ac | 2018-02-06 18:58:05 +0000 | [diff] [blame] | 526 | return __builtin_wmemchr(__s, __a, __n); |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 527 | #elif _LIBCPP_STD_VER <= 14 |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 528 | return _VSTD::wmemchr(__s, __a, __n); |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 529 | #else |
| 530 | for (; __n; --__n) |
| 531 | { |
| 532 | if (eq(*__s, __a)) |
| 533 | return __s; |
| 534 | ++__s; |
| 535 | } |
Marshall Clow | 32043ac | 2018-02-06 18:58:05 +0000 | [diff] [blame] | 536 | return nullptr; |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 537 | #endif |
| 538 | } |
| 539 | |
| 540 | |
Marshall Clow | 8732fed | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 541 | #ifndef _LIBCPP_NO_HAS_CHAR8_T |
| 542 | |
| 543 | template <> |
| 544 | struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t> |
| 545 | { |
| 546 | typedef char8_t char_type; |
| 547 | typedef unsigned int int_type; |
| 548 | typedef streamoff off_type; |
| 549 | typedef u8streampos pos_type; |
| 550 | typedef mbstate_t state_type; |
| 551 | |
| 552 | static inline constexpr void assign(char_type& __c1, const char_type& __c2) noexcept |
| 553 | {__c1 = __c2;} |
| 554 | static inline constexpr bool eq(char_type __c1, char_type __c2) noexcept |
| 555 | {return __c1 == __c2;} |
| 556 | static inline constexpr bool lt(char_type __c1, char_type __c2) noexcept |
| 557 | {return __c1 < __c2;} |
| 558 | |
| 559 | static constexpr |
| 560 | int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; |
| 561 | |
| 562 | static constexpr |
| 563 | size_t length(const char_type* __s) _NOEXCEPT; |
Louis Dionne | fd77e4f | 2019-10-23 10:40:15 -0700 | [diff] [blame] | 564 | |
Marshall Clow | 8732fed | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 565 | _LIBCPP_INLINE_VISIBILITY static constexpr |
| 566 | const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; |
Louis Dionne | fd77e4f | 2019-10-23 10:40:15 -0700 | [diff] [blame] | 567 | |
Arthur O'Dwyer | 14606d1 | 2020-11-23 12:44:41 -0500 | [diff] [blame] | 568 | static _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 569 | char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
| 570 | { |
| 571 | return __libcpp_is_constant_evaluated() |
Arthur O'Dwyer | e75dcfa | 2020-11-22 13:21:11 -0500 | [diff] [blame] | 572 | ? _VSTD::__move_constexpr(__s1, __s2, __n) |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 573 | : __n == 0 ? __s1 : (char_type*)_VSTD::memmove(__s1, __s2, __n); |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 574 | } |
Louis Dionne | fd77e4f | 2019-10-23 10:40:15 -0700 | [diff] [blame] | 575 | |
Arthur O'Dwyer | 14606d1 | 2020-11-23 12:44:41 -0500 | [diff] [blame] | 576 | static _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 577 | char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
Marshall Clow | 8732fed | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 578 | { |
| 579 | _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 580 | return __libcpp_is_constant_evaluated() |
Arthur O'Dwyer | e75dcfa | 2020-11-22 13:21:11 -0500 | [diff] [blame] | 581 | ? _VSTD::__copy_constexpr(__s1, __s2, __n) |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 582 | : __n == 0 ? __s1 : (char_type*)_VSTD::memcpy(__s1, __s2, __n); |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 583 | } |
Louis Dionne | fd77e4f | 2019-10-23 10:40:15 -0700 | [diff] [blame] | 584 | |
Arthur O'Dwyer | 14606d1 | 2020-11-23 12:44:41 -0500 | [diff] [blame] | 585 | static _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 586 | char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT |
| 587 | { |
| 588 | return __libcpp_is_constant_evaluated() |
Arthur O'Dwyer | e75dcfa | 2020-11-22 13:21:11 -0500 | [diff] [blame] | 589 | ? _VSTD::__assign_constexpr(__s, __n, __a) |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 590 | : __n == 0 ? __s : (char_type*)_VSTD::memset(__s, to_int_type(__a), __n); |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 591 | } |
Marshall Clow | 8732fed | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 592 | |
| 593 | static inline constexpr int_type not_eof(int_type __c) noexcept |
| 594 | {return eq_int_type(__c, eof()) ? ~eof() : __c;} |
| 595 | static inline constexpr char_type to_char_type(int_type __c) noexcept |
| 596 | {return char_type(__c);} |
| 597 | static inline constexpr int_type to_int_type(char_type __c) noexcept |
| 598 | {return int_type(__c);} |
| 599 | static inline constexpr bool eq_int_type(int_type __c1, int_type __c2) noexcept |
| 600 | {return __c1 == __c2;} |
| 601 | static inline constexpr int_type eof() noexcept |
| 602 | {return int_type(EOF);} |
| 603 | }; |
| 604 | |
| 605 | // TODO use '__builtin_strlen' if it ever supports char8_t ?? |
| 606 | inline constexpr |
| 607 | size_t |
| 608 | char_traits<char8_t>::length(const char_type* __s) _NOEXCEPT |
| 609 | { |
| 610 | size_t __len = 0; |
| 611 | for (; !eq(*__s, char_type(0)); ++__s) |
| 612 | ++__len; |
| 613 | return __len; |
| 614 | } |
| 615 | |
| 616 | inline constexpr |
| 617 | int |
| 618 | char_traits<char8_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
| 619 | { |
| 620 | #if __has_feature(cxx_constexpr_string_builtins) |
| 621 | return __builtin_memcmp(__s1, __s2, __n); |
| 622 | #else |
| 623 | for (; __n; --__n, ++__s1, ++__s2) |
| 624 | { |
| 625 | if (lt(*__s1, *__s2)) |
| 626 | return -1; |
| 627 | if (lt(*__s2, *__s1)) |
| 628 | return 1; |
| 629 | } |
| 630 | return 0; |
| 631 | #endif |
| 632 | } |
| 633 | |
| 634 | // TODO use '__builtin_char_memchr' if it ever supports char8_t ?? |
| 635 | inline constexpr |
| 636 | const char8_t* |
| 637 | char_traits<char8_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT |
| 638 | { |
| 639 | for (; __n; --__n) |
| 640 | { |
| 641 | if (eq(*__s, __a)) |
| 642 | return __s; |
| 643 | ++__s; |
| 644 | } |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 645 | return nullptr; |
Marshall Clow | 8732fed | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | #endif // #_LIBCPP_NO_HAS_CHAR8_T |
| 649 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 650 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 651 | |
| 652 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 653 | struct _LIBCPP_TEMPLATE_VIS char_traits<char16_t> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 654 | { |
| 655 | typedef char16_t char_type; |
| 656 | typedef uint_least16_t int_type; |
| 657 | typedef streamoff off_type; |
| 658 | typedef u16streampos pos_type; |
| 659 | typedef mbstate_t state_type; |
| 660 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 661 | static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 662 | void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 663 | static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT |
| 664 | {return __c1 == __c2;} |
| 665 | static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT |
| 666 | {return __c1 < __c2;} |
| 667 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 668 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 669 | int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; |
| 670 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 671 | size_t length(const char_type* __s) _NOEXCEPT; |
| 672 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 673 | const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 674 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 675 | static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 676 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 677 | static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 678 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 679 | static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 680 | |
| 681 | static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT |
| 682 | {return eq_int_type(__c, eof()) ? ~eof() : __c;} |
| 683 | static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT |
| 684 | {return char_type(__c);} |
| 685 | static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT |
| 686 | {return int_type(__c);} |
| 687 | static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT |
| 688 | {return __c1 == __c2;} |
| 689 | static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT |
| 690 | {return int_type(0xFFFF);} |
| 691 | }; |
| 692 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 693 | inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 694 | int |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 695 | char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 696 | { |
| 697 | for (; __n; --__n, ++__s1, ++__s2) |
| 698 | { |
| 699 | if (lt(*__s1, *__s2)) |
| 700 | return -1; |
| 701 | if (lt(*__s2, *__s1)) |
| 702 | return 1; |
| 703 | } |
| 704 | return 0; |
| 705 | } |
| 706 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 707 | inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 708 | size_t |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 709 | char_traits<char16_t>::length(const char_type* __s) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 710 | { |
| 711 | size_t __len = 0; |
| 712 | for (; !eq(*__s, char_type(0)); ++__s) |
| 713 | ++__len; |
| 714 | return __len; |
| 715 | } |
| 716 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 717 | inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 718 | const char16_t* |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 719 | char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 720 | { |
| 721 | for (; __n; --__n) |
| 722 | { |
| 723 | if (eq(*__s, __a)) |
| 724 | return __s; |
| 725 | ++__s; |
| 726 | } |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 727 | return nullptr; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 728 | } |
| 729 | |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 730 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 731 | char16_t* |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 732 | char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 733 | { |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 734 | if (__n == 0) return __s1; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 735 | char_type* __r = __s1; |
| 736 | if (__s1 < __s2) |
| 737 | { |
| 738 | for (; __n; --__n, ++__s1, ++__s2) |
| 739 | assign(*__s1, *__s2); |
| 740 | } |
| 741 | else if (__s2 < __s1) |
| 742 | { |
| 743 | __s1 += __n; |
| 744 | __s2 += __n; |
| 745 | for (; __n; --__n) |
| 746 | assign(*--__s1, *--__s2); |
| 747 | } |
| 748 | return __r; |
| 749 | } |
| 750 | |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 751 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 752 | char16_t* |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 753 | char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 754 | { |
| 755 | _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); |
| 756 | char_type* __r = __s1; |
| 757 | for (; __n; --__n, ++__s1, ++__s2) |
| 758 | assign(*__s1, *__s2); |
| 759 | return __r; |
| 760 | } |
| 761 | |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 762 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 763 | char16_t* |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 764 | char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 765 | { |
| 766 | char_type* __r = __s; |
| 767 | for (; __n; --__n, ++__s) |
| 768 | assign(*__s, __a); |
| 769 | return __r; |
| 770 | } |
| 771 | |
| 772 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 773 | struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 774 | { |
| 775 | typedef char32_t char_type; |
| 776 | typedef uint_least32_t int_type; |
| 777 | typedef streamoff off_type; |
| 778 | typedef u32streampos pos_type; |
| 779 | typedef mbstate_t state_type; |
| 780 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 781 | static inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 782 | void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 783 | static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT |
| 784 | {return __c1 == __c2;} |
| 785 | static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT |
| 786 | {return __c1 < __c2;} |
| 787 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 788 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 789 | int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; |
| 790 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 791 | size_t length(const char_type* __s) _NOEXCEPT; |
| 792 | _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 793 | const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 794 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 795 | static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 796 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 797 | static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 798 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 799 | static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 800 | |
| 801 | static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT |
| 802 | {return eq_int_type(__c, eof()) ? ~eof() : __c;} |
| 803 | static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT |
| 804 | {return char_type(__c);} |
| 805 | static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT |
| 806 | {return int_type(__c);} |
| 807 | static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT |
| 808 | {return __c1 == __c2;} |
| 809 | static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT |
| 810 | {return int_type(0xFFFFFFFF);} |
| 811 | }; |
| 812 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 813 | inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 814 | int |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 815 | char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 816 | { |
| 817 | for (; __n; --__n, ++__s1, ++__s2) |
| 818 | { |
| 819 | if (lt(*__s1, *__s2)) |
| 820 | return -1; |
| 821 | if (lt(*__s2, *__s1)) |
| 822 | return 1; |
| 823 | } |
| 824 | return 0; |
| 825 | } |
| 826 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 827 | inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 828 | size_t |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 829 | char_traits<char32_t>::length(const char_type* __s) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 830 | { |
| 831 | size_t __len = 0; |
| 832 | for (; !eq(*__s, char_type(0)); ++__s) |
| 833 | ++__len; |
| 834 | return __len; |
| 835 | } |
| 836 | |
Marshall Clow | 951035b | 2017-01-12 04:37:14 +0000 | [diff] [blame] | 837 | inline _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 838 | const char32_t* |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 839 | char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 840 | { |
| 841 | for (; __n; --__n) |
| 842 | { |
| 843 | if (eq(*__s, __a)) |
| 844 | return __s; |
| 845 | ++__s; |
| 846 | } |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 847 | return nullptr; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 848 | } |
| 849 | |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 850 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 851 | char32_t* |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 852 | char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 853 | { |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 854 | if (__n == 0) return __s1; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 855 | char_type* __r = __s1; |
| 856 | if (__s1 < __s2) |
| 857 | { |
| 858 | for (; __n; --__n, ++__s1, ++__s2) |
| 859 | assign(*__s1, *__s2); |
| 860 | } |
| 861 | else if (__s2 < __s1) |
| 862 | { |
| 863 | __s1 += __n; |
| 864 | __s2 += __n; |
| 865 | for (; __n; --__n) |
| 866 | assign(*--__s1, *--__s2); |
| 867 | } |
| 868 | return __r; |
| 869 | } |
| 870 | |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 871 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 872 | char32_t* |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 873 | char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 874 | { |
| 875 | _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); |
| 876 | char_type* __r = __s1; |
| 877 | for (; __n; --__n, ++__s1, ++__s2) |
| 878 | assign(*__s1, *__s2); |
| 879 | return __r; |
| 880 | } |
| 881 | |
Michael Park | b5f4447 | 2019-11-08 13:42:26 +0000 | [diff] [blame] | 882 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 883 | char32_t* |
Marshall Clow | 36097db | 2016-07-28 04:52:02 +0000 | [diff] [blame] | 884 | char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 885 | { |
| 886 | char_type* __r = __s; |
| 887 | for (; __n; --__n, ++__s) |
| 888 | assign(*__s, __a); |
| 889 | return __r; |
| 890 | } |
| 891 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame^] | 892 | #endif // _LIBCPP_HAS_NO_UNICODE_CHARS |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 893 | |
| 894 | // helper fns for basic_string and string_view |
| 895 | |
| 896 | // __str_find |
| 897 | template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> |
| 898 | inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | fd77e4f | 2019-10-23 10:40:15 -0700 | [diff] [blame] | 899 | __str_find(const _CharT *__p, _SizeT __sz, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 900 | _CharT __c, _SizeT __pos) _NOEXCEPT |
| 901 | { |
| 902 | if (__pos >= __sz) |
| 903 | return __npos; |
| 904 | const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c); |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 905 | if (__r == nullptr) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 906 | return __npos; |
| 907 | return static_cast<_SizeT>(__r - __p); |
| 908 | } |
| 909 | |
Sebastian Pop | 6511520 | 2016-12-30 18:01:36 +0000 | [diff] [blame] | 910 | template <class _CharT, class _Traits> |
| 911 | inline _LIBCPP_CONSTEXPR_AFTER_CXX11 const _CharT * |
| 912 | __search_substring(const _CharT *__first1, const _CharT *__last1, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 913 | const _CharT *__first2, const _CharT *__last2) _NOEXCEPT { |
Sebastian Pop | 6511520 | 2016-12-30 18:01:36 +0000 | [diff] [blame] | 914 | // Take advantage of knowing source and pattern lengths. |
| 915 | // Stop short when source is smaller than pattern. |
| 916 | const ptrdiff_t __len2 = __last2 - __first2; |
| 917 | if (__len2 == 0) |
| 918 | return __first1; |
| 919 | |
| 920 | ptrdiff_t __len1 = __last1 - __first1; |
| 921 | if (__len1 < __len2) |
| 922 | return __last1; |
| 923 | |
| 924 | // First element of __first2 is loop invariant. |
| 925 | _CharT __f2 = *__first2; |
| 926 | while (true) { |
| 927 | __len1 = __last1 - __first1; |
| 928 | // Check whether __first1 still has at least __len2 bytes. |
| 929 | if (__len1 < __len2) |
| 930 | return __last1; |
| 931 | |
| 932 | // Find __f2 the first byte matching in __first1. |
| 933 | __first1 = _Traits::find(__first1, __len1 - __len2 + 1, __f2); |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 934 | if (__first1 == nullptr) |
Sebastian Pop | 6511520 | 2016-12-30 18:01:36 +0000 | [diff] [blame] | 935 | return __last1; |
| 936 | |
| 937 | // It is faster to compare from the first byte of __first1 even if we |
| 938 | // already know that it matches the first byte of __first2: this is because |
| 939 | // __first2 is most likely aligned, as it is user's "pattern" string, and |
| 940 | // __first1 + 1 is most likely not aligned, as the match is in the middle of |
| 941 | // the string. |
| 942 | if (_Traits::compare(__first1, __first2, __len2) == 0) |
| 943 | return __first1; |
| 944 | |
| 945 | ++__first1; |
| 946 | } |
| 947 | } |
| 948 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 949 | template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> |
| 950 | inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | fd77e4f | 2019-10-23 10:40:15 -0700 | [diff] [blame] | 951 | __str_find(const _CharT *__p, _SizeT __sz, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 952 | const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT |
| 953 | { |
Sebastian Pop | 6511520 | 2016-12-30 18:01:36 +0000 | [diff] [blame] | 954 | if (__pos > __sz) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 955 | return __npos; |
Sebastian Pop | 6511520 | 2016-12-30 18:01:36 +0000 | [diff] [blame] | 956 | |
| 957 | if (__n == 0) // There is nothing to search, just return __pos. |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 958 | return __pos; |
Sebastian Pop | 6511520 | 2016-12-30 18:01:36 +0000 | [diff] [blame] | 959 | |
| 960 | const _CharT *__r = __search_substring<_CharT, _Traits>( |
| 961 | __p + __pos, __p + __sz, __s, __s + __n); |
| 962 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 963 | if (__r == __p + __sz) |
| 964 | return __npos; |
| 965 | return static_cast<_SizeT>(__r - __p); |
| 966 | } |
| 967 | |
| 968 | |
| 969 | // __str_rfind |
| 970 | |
| 971 | template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> |
| 972 | inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | fd77e4f | 2019-10-23 10:40:15 -0700 | [diff] [blame] | 973 | __str_rfind(const _CharT *__p, _SizeT __sz, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 974 | _CharT __c, _SizeT __pos) _NOEXCEPT |
| 975 | { |
| 976 | if (__sz < 1) |
| 977 | return __npos; |
| 978 | if (__pos < __sz) |
| 979 | ++__pos; |
| 980 | else |
| 981 | __pos = __sz; |
| 982 | for (const _CharT* __ps = __p + __pos; __ps != __p;) |
| 983 | { |
| 984 | if (_Traits::eq(*--__ps, __c)) |
| 985 | return static_cast<_SizeT>(__ps - __p); |
| 986 | } |
| 987 | return __npos; |
| 988 | } |
| 989 | |
| 990 | template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> |
| 991 | inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | fd77e4f | 2019-10-23 10:40:15 -0700 | [diff] [blame] | 992 | __str_rfind(const _CharT *__p, _SizeT __sz, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 993 | const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT |
| 994 | { |
| 995 | __pos = _VSTD::min(__pos, __sz); |
| 996 | if (__n < __sz - __pos) |
| 997 | __pos += __n; |
| 998 | else |
| 999 | __pos = __sz; |
| 1000 | const _CharT* __r = _VSTD::__find_end( |
Louis Dionne | fd77e4f | 2019-10-23 10:40:15 -0700 | [diff] [blame] | 1001 | __p, __p + __pos, __s, __s + __n, _Traits::eq, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1002 | random_access_iterator_tag(), random_access_iterator_tag()); |
| 1003 | if (__n > 0 && __r == __p + __pos) |
| 1004 | return __npos; |
| 1005 | return static_cast<_SizeT>(__r - __p); |
| 1006 | } |
| 1007 | |
| 1008 | // __str_find_first_of |
| 1009 | template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> |
| 1010 | inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1011 | __str_find_first_of(const _CharT *__p, _SizeT __sz, |
| 1012 | const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT |
| 1013 | { |
| 1014 | if (__pos >= __sz || __n == 0) |
| 1015 | return __npos; |
| 1016 | const _CharT* __r = _VSTD::__find_first_of_ce |
| 1017 | (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq ); |
| 1018 | if (__r == __p + __sz) |
| 1019 | return __npos; |
| 1020 | return static_cast<_SizeT>(__r - __p); |
| 1021 | } |
| 1022 | |
| 1023 | |
| 1024 | // __str_find_last_of |
| 1025 | template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> |
| 1026 | inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1027 | __str_find_last_of(const _CharT *__p, _SizeT __sz, |
| 1028 | const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT |
| 1029 | { |
| 1030 | if (__n != 0) |
| 1031 | { |
| 1032 | if (__pos < __sz) |
| 1033 | ++__pos; |
| 1034 | else |
| 1035 | __pos = __sz; |
| 1036 | for (const _CharT* __ps = __p + __pos; __ps != __p;) |
| 1037 | { |
| 1038 | const _CharT* __r = _Traits::find(__s, __n, *--__ps); |
| 1039 | if (__r) |
| 1040 | return static_cast<_SizeT>(__ps - __p); |
| 1041 | } |
| 1042 | } |
| 1043 | return __npos; |
| 1044 | } |
| 1045 | |
| 1046 | |
| 1047 | // __str_find_first_not_of |
| 1048 | template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> |
| 1049 | inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1050 | __str_find_first_not_of(const _CharT *__p, _SizeT __sz, |
| 1051 | const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT |
| 1052 | { |
| 1053 | if (__pos < __sz) |
| 1054 | { |
| 1055 | const _CharT* __pe = __p + __sz; |
| 1056 | for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps) |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1057 | if (_Traits::find(__s, __n, *__ps) == nullptr) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1058 | return static_cast<_SizeT>(__ps - __p); |
| 1059 | } |
| 1060 | return __npos; |
| 1061 | } |
| 1062 | |
| 1063 | |
| 1064 | template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> |
| 1065 | inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1066 | __str_find_first_not_of(const _CharT *__p, _SizeT __sz, |
| 1067 | _CharT __c, _SizeT __pos) _NOEXCEPT |
| 1068 | { |
| 1069 | if (__pos < __sz) |
| 1070 | { |
| 1071 | const _CharT* __pe = __p + __sz; |
| 1072 | for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps) |
| 1073 | if (!_Traits::eq(*__ps, __c)) |
| 1074 | return static_cast<_SizeT>(__ps - __p); |
| 1075 | } |
| 1076 | return __npos; |
| 1077 | } |
| 1078 | |
| 1079 | |
| 1080 | // __str_find_last_not_of |
| 1081 | template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> |
| 1082 | inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1083 | __str_find_last_not_of(const _CharT *__p, _SizeT __sz, |
| 1084 | const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT |
| 1085 | { |
| 1086 | if (__pos < __sz) |
| 1087 | ++__pos; |
| 1088 | else |
| 1089 | __pos = __sz; |
| 1090 | for (const _CharT* __ps = __p + __pos; __ps != __p;) |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1091 | if (_Traits::find(__s, __n, *--__ps) == nullptr) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1092 | return static_cast<_SizeT>(__ps - __p); |
| 1093 | return __npos; |
| 1094 | } |
| 1095 | |
| 1096 | |
| 1097 | template<class _CharT, class _SizeT, class _Traits, _SizeT __npos> |
| 1098 | inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1099 | __str_find_last_not_of(const _CharT *__p, _SizeT __sz, |
| 1100 | _CharT __c, _SizeT __pos) _NOEXCEPT |
| 1101 | { |
| 1102 | if (__pos < __sz) |
| 1103 | ++__pos; |
| 1104 | else |
| 1105 | __pos = __sz; |
| 1106 | for (const _CharT* __ps = __p + __pos; __ps != __p;) |
| 1107 | if (!_Traits::eq(*--__ps, __c)) |
| 1108 | return static_cast<_SizeT>(__ps - __p); |
| 1109 | return __npos; |
| 1110 | } |
| 1111 | |
| 1112 | template<class _Ptr> |
Eric Fiselier | 1b57fa8 | 2016-09-15 22:27:07 +0000 | [diff] [blame] | 1113 | inline _LIBCPP_INLINE_VISIBILITY |
| 1114 | size_t __do_string_hash(_Ptr __p, _Ptr __e) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1115 | { |
| 1116 | typedef typename iterator_traits<_Ptr>::value_type value_type; |
| 1117 | return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type)); |
| 1118 | } |
| 1119 | |
| 1120 | template <class _CharT, class _Iter, class _Traits=char_traits<_CharT> > |
| 1121 | struct __quoted_output_proxy |
| 1122 | { |
| 1123 | _Iter __first; |
| 1124 | _Iter __last; |
| 1125 | _CharT __delim; |
| 1126 | _CharT __escape; |
| 1127 | |
| 1128 | __quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e) |
| 1129 | : __first(__f), __last(__l), __delim(__d), __escape(__e) {} |
Louis Dionne | fd77e4f | 2019-10-23 10:40:15 -0700 | [diff] [blame] | 1130 | // This would be a nice place for a string_ref |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1131 | }; |
| 1132 | |
| 1133 | _LIBCPP_END_NAMESPACE_STD |
| 1134 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 1135 | _LIBCPP_POP_MACROS |
| 1136 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame^] | 1137 | #endif // _LIBCPP___STRING |