diff options
Diffstat (limited to 'libcxx/include/string')
| -rw-r--r-- | libcxx/include/string | 342 |
1 files changed, 198 insertions, 144 deletions
diff --git a/libcxx/include/string b/libcxx/include/string index 2f846eda06c5..687795c79bb9 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -153,7 +153,8 @@ public: void resize(size_type n, value_type c); void resize(size_type n); - void reserve(size_type res_arg = 0); + void reserve(size_type res_arg); + void reserve(); // deprecated in C++20 void shrink_to_fit(); void clear() noexcept; bool empty() const noexcept; @@ -316,12 +317,16 @@ public: int compare(size_type pos1, size_type n1, const value_type* s) const; int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const; - bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a - bool starts_with(charT c) const noexcept; // C++2a - bool starts_with(const charT* s) const; // C++2a - bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a - bool ends_with(charT c) const noexcept; // C++2a - bool ends_with(const charT* s) const; // C++2a + bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 + bool starts_with(charT c) const noexcept; // C++20 + bool starts_with(const charT* s) const; // C++20 + bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 + bool ends_with(charT c) const noexcept; // C++20 + bool ends_with(const charT* s) const; // C++20 + + constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b + constexpr bool contains(charT c) const noexcept; // C++2b + constexpr bool contains(const charT* s) const; // C++2b bool __invariants() const; }; @@ -448,15 +453,15 @@ typedef basic_string<wchar_t> wstring; typedef basic_string<char16_t> u16string; typedef basic_string<char32_t> u32string; -int stoi (const string& str, size_t* idx = 0, int base = 10); -long stol (const string& str, size_t* idx = 0, int base = 10); -unsigned long stoul (const string& str, size_t* idx = 0, int base = 10); -long long stoll (const string& str, size_t* idx = 0, int base = 10); -unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10); +int stoi (const string& str, size_t* idx = nullptr, int base = 10); +long stol (const string& str, size_t* idx = nullptr, int base = 10); +unsigned long stoul (const string& str, size_t* idx = nullptr, int base = 10); +long long stoll (const string& str, size_t* idx = nullptr, int base = 10); +unsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10); -float stof (const string& str, size_t* idx = 0); -double stod (const string& str, size_t* idx = 0); -long double stold(const string& str, size_t* idx = 0); +float stof (const string& str, size_t* idx = nullptr); +double stod (const string& str, size_t* idx = nullptr); +long double stold(const string& str, size_t* idx = nullptr); string to_string(int val); string to_string(unsigned val); @@ -468,15 +473,15 @@ string to_string(float val); string to_string(double val); string to_string(long double val); -int stoi (const wstring& str, size_t* idx = 0, int base = 10); -long stol (const wstring& str, size_t* idx = 0, int base = 10); -unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10); -long long stoll (const wstring& str, size_t* idx = 0, int base = 10); -unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10); +int stoi (const wstring& str, size_t* idx = nullptr, int base = 10); +long stol (const wstring& str, size_t* idx = nullptr, int base = 10); +unsigned long stoul (const wstring& str, size_t* idx = nullptr, int base = 10); +long long stoll (const wstring& str, size_t* idx = nullptr, int base = 10); +unsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10); -float stof (const wstring& str, size_t* idx = 0); -double stod (const wstring& str, size_t* idx = 0); -long double stold(const wstring& str, size_t* idx = 0); +float stof (const wstring& str, size_t* idx = nullptr); +double stod (const wstring& str, size_t* idx = nullptr); +long double stold(const wstring& str, size_t* idx = nullptr); wstring to_wstring(int val); wstring to_wstring(unsigned val); @@ -665,8 +670,26 @@ struct __padding<_CharT, 1> #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT +#ifndef _LIBCPP_NO_HAS_CHAR8_T +typedef basic_string<char8_t> u8string; +#endif + +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS +typedef basic_string<char16_t> u16string; +typedef basic_string<char32_t> u32string; +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + template<class _CharT, class _Traits, class _Allocator> -class _LIBCPP_TEMPLATE_VIS basic_string +class + _LIBCPP_TEMPLATE_VIS +#ifndef _LIBCPP_NO_HAS_CHAR8_T + _LIBCPP_PREFERRED_NAME(u8string) +#endif +#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS + _LIBCPP_PREFERRED_NAME(u16string) + _LIBCPP_PREFERRED_NAME(u32string) +#endif + basic_string : private __basic_string_common<true> { public: @@ -816,7 +839,7 @@ public: basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) { _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); __init(__s, traits_type::length(__s)); -# if _LIBCPP_DEBUG_LEVEL >= 2 +# if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); # endif } @@ -890,7 +913,7 @@ public: _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);} basic_string& operator=(value_type __c); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return iterator(this, __get_pointer());} @@ -916,7 +939,7 @@ public: _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return const_iterator(__get_pointer() + size());} -#endif // _LIBCPP_DEBUG_LEVEL >= 2 +#endif // _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_INLINE_VISIBILITY reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} @@ -954,13 +977,13 @@ public: void resize(size_type __n, value_type __c); _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());} - void reserve(size_type __res_arg); + void reserve(size_type __requested_capacity); _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n); + _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_INLINE_VISIBILITY + void reserve() _NOEXCEPT {shrink_to_fit();} _LIBCPP_INLINE_VISIBILITY - void reserve() _NOEXCEPT {reserve(0);} - _LIBCPP_INLINE_VISIBILITY - void shrink_to_fit() _NOEXCEPT {reserve();} + void shrink_to_fit() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT; _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY @@ -1414,22 +1437,38 @@ public: { return ends_with(__self_view(__s)); } #endif +#if _LIBCPP_STD_VER > 20 + constexpr _LIBCPP_INLINE_VISIBILITY + bool contains(__self_view __sv) const noexcept + { return __self_view(data(), size()).contains(__sv); } + + constexpr _LIBCPP_INLINE_VISIBILITY + bool contains(value_type __c) const noexcept + { return __self_view(data(), size()).contains(__c); } + + constexpr _LIBCPP_INLINE_VISIBILITY + bool contains(const value_type* __s) const + { return __self_view(data(), size()).contains(__s); } +#endif + _LIBCPP_INLINE_VISIBILITY bool __invariants() const; _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY void __shrink_or_extend(size_type __target_capacity); + _LIBCPP_INLINE_VISIBILITY bool __is_long() const _NOEXCEPT {return bool(__r_.first().__s.__size_ & __short_mask);} -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 bool __dereferenceable(const const_iterator* __i) const; bool __decrementable(const const_iterator* __i) const; bool __addable(const const_iterator* __i, ptrdiff_t __n) const; bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; -#endif // _LIBCPP_DEBUG_LEVEL >= 2 +#endif // _LIBCPP_DEBUG_LEVEL == 2 private: _LIBCPP_INLINE_VISIBILITY @@ -1726,21 +1765,21 @@ inline void basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators() { -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__invalidate_all(this); -#endif // _LIBCPP_DEBUG_LEVEL >= 2 +#endif } template <class _CharT, class _Traits, class _Allocator> inline void basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __pos #endif ) { -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __c_node* __c = __get_db()->__find_c_and_lock(this); if (__c) { @@ -1753,12 +1792,12 @@ basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type { (*__p)->__c_ = nullptr; if (--__c->end_ != __p) - memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); } } __get_db()->unlock(); } -#endif // _LIBCPP_DEBUG_LEVEL >= 2 +#endif // _LIBCPP_DEBUG_LEVEL == 2 } template <class _CharT, class _Traits, class _Allocator> @@ -1767,7 +1806,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) : __r_(__default_init_tag(), __default_init_tag()) { -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif __zero(); @@ -1783,7 +1822,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __ #endif : __r_(__default_init_tag(), __a) { -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif __zero(); @@ -1845,7 +1884,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const { _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); __init(__s, traits_type::length(__s)); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -1857,7 +1896,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_ { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); __init(__s, __n); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -1869,7 +1908,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_ { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); __init(__s, __n); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -1884,7 +1923,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -1899,7 +1938,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string( else __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -1936,7 +1975,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str) : __r_(_VSTD::move(__str.__r_)) { __str.__zero(); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); if (__is_long()) __get_db()->swap(this, &__str); @@ -1955,7 +1994,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, co __r_.first().__r = __str.__r_.first().__r; __str.__zero(); } -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); if (__is_long()) __get_db()->swap(this, &__str); @@ -1994,7 +2033,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __ : __r_(__default_init_tag(), __default_init_tag()) { __init(__n, __c); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -2005,7 +2044,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __ : __r_(__default_init_tag(), __a) { __init(__n, __c); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -2020,7 +2059,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st if (__pos > __str_sz) this->__throw_out_of_range(); __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos)); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -2035,7 +2074,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st if (__pos > __str_sz) this->__throw_out_of_range(); __init(__str.data() + __pos, __str_sz - __pos); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -2049,7 +2088,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string( __self_view __sv0 = __t; __self_view __sv = __sv0.substr(__pos, __n); __init(__sv.data(), __sv.size()); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -2061,7 +2100,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t) { __self_view __sv = __t; __init(__sv.data(), __sv.size()); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -2073,7 +2112,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _ { __self_view __sv = __t; __init(__sv.data(), __sv.size()); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -2141,7 +2180,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, : __r_(__default_init_tag(), __default_init_tag()) { __init(__first, __last); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -2154,7 +2193,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, : __r_(__default_init_tag(), __a) { __init(__first, __last); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -2168,7 +2207,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string( : __r_(__default_init_tag(), __default_init_tag()) { __init(__il.begin(), __il.end()); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -2181,7 +2220,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string( : __r_(__default_init_tag(), __a) { __init(__il.begin(), __il.end()); -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__insert_c(this); #endif } @@ -2191,7 +2230,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string( template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>::~basic_string() { -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 __get_db()->__erase_c(this); #endif if (__is_long()) @@ -2768,7 +2807,7 @@ _EnableIf > basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) { -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, "string::insert(iterator, range) called with an iterator not" " referring to this string"); @@ -2787,7 +2826,7 @@ _EnableIf > basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) { -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, "string::insert(iterator, range) called with an iterator not" " referring to this string"); @@ -2903,7 +2942,7 @@ inline typename basic_string<_CharT, _Traits, _Allocator>::iterator basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c) { -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, "string::insert(iterator, n, value) called with an iterator not" " referring to this string"); @@ -3137,7 +3176,7 @@ inline typename basic_string<_CharT, _Traits, _Allocator>::iterator basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos) { -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, "string::erase(iterator) called with an iterator not" " referring to this string"); @@ -3155,7 +3194,7 @@ inline typename basic_string<_CharT, _Traits, _Allocator>::iterator basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last) { -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, "string::erase(iterator, iterator) called with an iterator not" " referring to this string"); @@ -3262,65 +3301,88 @@ basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT template <class _CharT, class _Traits, class _Allocator> void -basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg) +basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity) { - if (__res_arg > max_size()) + if (__requested_capacity > max_size()) this->__throw_length_error(); + +#if _LIBCPP_STD_VER > 17 + // Reserve never shrinks as of C++20. + if (__requested_capacity <= capacity()) return; +#endif + + size_type __target_capacity = _VSTD::max(__requested_capacity, size()); + __target_capacity = __recommend(__target_capacity); + if (__target_capacity == capacity()) return; + + __shrink_or_extend(__target_capacity); +} + +template <class _CharT, class _Traits, class _Allocator> +void +basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT +{ + size_type __target_capacity = __recommend(size()); + if (__target_capacity == capacity()) return; + + __shrink_or_extend(__target_capacity); +} + +template <class _CharT, class _Traits, class _Allocator> +void +basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity) +{ size_type __cap = capacity(); size_type __sz = size(); - __res_arg = _VSTD::max(__res_arg, __sz); - __res_arg = __recommend(__res_arg); - if (__res_arg != __cap) + + pointer __new_data, __p; + bool __was_long, __now_long; + if (__target_capacity == __min_cap - 1) { - pointer __new_data, __p; - bool __was_long, __now_long; - if (__res_arg == __min_cap - 1) - { - __was_long = true; - __now_long = false; - __new_data = __get_short_pointer(); - __p = __get_long_pointer(); - } + __was_long = true; + __now_long = false; + __new_data = __get_short_pointer(); + __p = __get_long_pointer(); + } + else + { + if (__target_capacity > __cap) + __new_data = __alloc_traits::allocate(__alloc(), __target_capacity+1); else { - if (__res_arg > __cap) - __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1); - else + #ifndef _LIBCPP_NO_EXCEPTIONS + try { - #ifndef _LIBCPP_NO_EXCEPTIONS - try - { - #endif // _LIBCPP_NO_EXCEPTIONS - __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1); - #ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - return; - } - #else // _LIBCPP_NO_EXCEPTIONS - if (__new_data == nullptr) - return; - #endif // _LIBCPP_NO_EXCEPTIONS + #endif // _LIBCPP_NO_EXCEPTIONS + __new_data = __alloc_traits::allocate(__alloc(), __target_capacity+1); + #ifndef _LIBCPP_NO_EXCEPTIONS } - __now_long = true; - __was_long = __is_long(); - __p = __get_pointer(); - } - traits_type::copy(_VSTD::__to_address(__new_data), - _VSTD::__to_address(__p), size()+1); - if (__was_long) - __alloc_traits::deallocate(__alloc(), __p, __cap+1); - if (__now_long) - { - __set_long_cap(__res_arg+1); - __set_long_size(__sz); - __set_long_pointer(__new_data); + catch (...) + { + return; + } + #else // _LIBCPP_NO_EXCEPTIONS + if (__new_data == nullptr) + return; + #endif // _LIBCPP_NO_EXCEPTIONS } - else - __set_short_size(__sz); - __invalidate_all_iterators(); + __now_long = true; + __was_long = __is_long(); + __p = __get_pointer(); } + traits_type::copy(_VSTD::__to_address(__new_data), + _VSTD::__to_address(__p), size()+1); + if (__was_long) + __alloc_traits::deallocate(__alloc(), __p, __cap+1); + if (__now_long) + { + __set_long_cap(__target_capacity+1); + __set_long_size(__sz); + __set_long_pointer(__new_data); + } + else + __set_short_size(__sz); + __invalidate_all_iterators(); } template <class _CharT, class _Traits, class _Allocator> @@ -3426,7 +3488,7 @@ basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) __is_nothrow_swappable<allocator_type>::value) #endif { -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 if (!__is_long()) __get_db()->__invalidate_all(this); if (!__str.__is_long()) @@ -3438,7 +3500,7 @@ basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) __alloc_traits::is_always_equal::value || __alloc() == __str.__alloc(), "swapping non-equal allocators"); _VSTD::swap(__r_.first(), __str.__r_.first()); - __swap_allocator(__alloc(), __str.__alloc()); + _VSTD::__swap_allocator(__alloc(), __str.__alloc()); } // find @@ -3939,9 +4001,9 @@ basic_string<_CharT, _Traits, _Allocator>::__invariants() const return false; if (capacity() < __min_cap - 1) return false; - if (data() == 0) + if (data() == nullptr) return false; - if (data()[size()] != value_type(0)) + if (data()[size()] != value_type()) return false; return true; } @@ -3959,6 +4021,7 @@ basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1); __set_long_cap(0); __set_short_size(0); + traits_type::assign(*__get_short_pointer(), value_type()); } } @@ -4300,24 +4363,15 @@ swap(basic_string<_CharT, _Traits, _Allocator>& __lhs, __lhs.swap(__rhs); } -#ifndef _LIBCPP_NO_HAS_CHAR8_T -typedef basic_string<char8_t> u8string; -#endif - -#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS -typedef basic_string<char16_t> u16string; -typedef basic_string<char32_t> u32string; -#endif // _LIBCPP_HAS_NO_UNICODE_CHARS - -_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10); -_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10); -_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10); -_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10); -_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10); +_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10); +_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = nullptr, int __base = 10); +_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10); +_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = nullptr, int __base = 10); +_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = nullptr, int __base = 10); -_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0); -_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0); -_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0); +_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = nullptr); +_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = nullptr); +_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = nullptr); _LIBCPP_FUNC_VIS string to_string(int __val); _LIBCPP_FUNC_VIS string to_string(unsigned __val); @@ -4329,15 +4383,15 @@ _LIBCPP_FUNC_VIS string to_string(float __val); _LIBCPP_FUNC_VIS string to_string(double __val); _LIBCPP_FUNC_VIS string to_string(long double __val); -_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10); -_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10); -_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10); -_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10); -_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10); +_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10); +_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10); +_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10); +_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10); +_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = nullptr, int __base = 10); -_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0); -_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0); -_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0); +_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = nullptr); +_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = nullptr); +_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = nullptr); _LIBCPP_FUNC_VIS wstring to_wstring(int __val); _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val); @@ -4425,7 +4479,7 @@ inline _LIBCPP_INLINE_VISIBILITY } #endif -#if _LIBCPP_DEBUG_LEVEL >= 2 +#if _LIBCPP_DEBUG_LEVEL == 2 template<class _CharT, class _Traits, class _Allocator> bool @@ -4459,7 +4513,7 @@ basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* return this->data() <= __p && __p < this->data() + this->size(); } -#endif // _LIBCPP_DEBUG_LEVEL >= 2 +#endif // _LIBCPP_DEBUG_LEVEL == 2 #if _LIBCPP_STD_VER > 11 // Literal suffixes for basic_string [basic.string.literals] |
