diff --git a/libcxx/include/string b/libcxx/include/string index e8bd69fcabd7..f93fac187b9b 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -988,6 +988,108 @@ char_traits::assign(char_type* __s, size_t __n, char_type __a) #endif // _LIBCPP_HAS_NO_UNICODE_CHARS +// helper fns for basic_string + +template +_SizeT _LIBCPP_INLINE_VISIBILITY __find_first_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT +{ + if (__pos >= __sz || __n == 0) + return __npos; + const _CharT* __r = _VSTD::find_first_of + (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq ); + if (__r == __p + __sz) + return __npos; + return static_cast<_SizeT>(__r - __p); +} + +template +_SizeT _LIBCPP_INLINE_VISIBILITY __find_last_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT + { + if (__n != 0) + { + if (__pos < __sz) + ++__pos; + else + __pos = __sz; + for (const _CharT* __ps = __p + __pos; __ps != __p;) + { + const _CharT* __r = _Traits::find(__s, __n, *--__ps); + if (__r) + return static_cast<_SizeT>(__ps - __p); + } + } + return __npos; +} + + +template +_SizeT _LIBCPP_INLINE_VISIBILITY __find_first_not_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT +{ + if (__pos < __sz) + { + const _CharT* __pe = __p + __sz; + for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps) + if (_Traits::find(__s, __n, *__ps) == 0) + return static_cast<_SizeT>(__ps - __p); + } + return __npos; +} + + +template +_SizeT _LIBCPP_INLINE_VISIBILITY __find_first_not_of(const _CharT *__p, _SizeT __sz, + _CharT __c, _SizeT __pos) _NOEXCEPT +{ + if (__pos < __sz) + { + const _CharT* __pe = __p + __sz; + for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps) + if (!_Traits::eq(*__ps, __c)) + return static_cast<_SizeT>(__ps - __p); + } + return __npos; +} + + +template +_SizeT _LIBCPP_INLINE_VISIBILITY __find_last_not_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT +{ + if (__pos < __sz) + ++__pos; + else + __pos = __sz; + for (const _CharT* __ps = __p + __pos; __ps != __p;) + if (_Traits::find(__s, __n, *--__ps) == 0) + return static_cast<_SizeT>(__ps - __p); + return __npos; +} + + +template +_SizeT _LIBCPP_INLINE_VISIBILITY __find_last_not_of(const _CharT *__p, _SizeT __sz, + _CharT __c, _SizeT __pos) _NOEXCEPT +{ + if (__pos < __sz) + ++__pos; + else + __pos = __sz; + for (const _CharT* __ps = __p + __pos; __ps != __p;) + if (!_Traits::eq(*--__ps, __c)) + return static_cast<_SizeT>(__ps - __p); + return __npos; +} + +template +size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e) +{ + typedef typename iterator_traits<_Ptr>::value_type value_type; + return __murmur2_or_cityhash()(__p, (__e-__p)*sizeof(value_type)); +} + // basic_string template @@ -3364,15 +3466,8 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): recieved nullptr"); - size_type __sz = size(); - if (__pos >= __sz || __n == 0) - return npos; - const value_type* __p = data(); - const value_type* __r = _VSTD::find_first_of(__p + __pos, __p + __sz, __s, - __s + __n, __traits_eq()); - if (__r == __p + __sz) - return npos; - return static_cast(__r - __p); + return _VSTD::__find_first_of + (data(), size(), __s, __pos, __n); } template @@ -3381,7 +3476,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return find_first_of(__str.data(), __pos, __str.size()); + return _VSTD::__find_first_of + (data(), size(), __str.data(), __pos, __str.size()); } template @@ -3391,7 +3487,8 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): recieved nullptr"); - return find_first_of(__s, __pos, traits_type::length(__s)); + return _VSTD::__find_first_of + (data(), size(), __s, __pos, traits_type::length(__s)); } template @@ -3412,22 +3509,8 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): recieved nullptr"); - if (__n != 0) - { - size_type __sz = size(); - if (__pos < __sz) - ++__pos; - else - __pos = __sz; - const value_type* __p = data(); - for (const value_type* __ps = __p + __pos; __ps != __p;) - { - const value_type* __r = traits_type::find(__s, __n, *--__ps); - if (__r) - return static_cast(__ps - __p); - } - } - return npos; + return _VSTD::__find_last_of + (data(), size(), __s, __pos, __n); } template @@ -3436,7 +3519,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return find_last_of(__str.data(), __pos, __str.size()); + return _VSTD::__find_last_of + (data(), size(), __str.data(), __pos, __str.size()); } template @@ -3446,7 +3530,8 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): recieved nullptr"); - return find_last_of(__s, __pos, traits_type::length(__s)); + return _VSTD::__find_last_of + (data(), size(), __s, __pos, traits_type::length(__s)); } template @@ -3467,16 +3552,8 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* _ size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): recieved nullptr"); - size_type __sz = size(); - if (__pos < __sz) - { - const value_type* __p = data(); - const value_type* __pe = __p + __sz; - for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps) - if (traits_type::find(__s, __n, *__ps) == 0) - return static_cast(__ps - __p); - } - return npos; + return _VSTD::__find_first_not_of + (data(), size(), __s, __pos, __n); } template @@ -3485,7 +3562,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return find_first_not_of(__str.data(), __pos, __str.size()); + return _VSTD::__find_first_not_of + (data(), size(), __str.data(), __pos, __str.size()); } template @@ -3495,7 +3573,8 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* _ size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): recieved nullptr"); - return find_first_not_of(__s, __pos, traits_type::length(__s)); + return _VSTD::__find_first_not_of + (data(), size(), __s, __pos, traits_type::length(__s)); } template @@ -3504,16 +3583,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, size_type __pos) const _NOEXCEPT { - size_type __sz = size(); - if (__pos < __sz) - { - const value_type* __p = data(); - const value_type* __pe = __p + __sz; - for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps) - if (!traits_type::eq(*__ps, __c)) - return static_cast(__ps - __p); - } - return npos; + return _VSTD::__find_first_not_of + (data(), size(), __c, __pos); } // find_last_not_of @@ -3525,16 +3596,8 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __ size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): recieved nullptr"); - size_type __sz = size(); - if (__pos < __sz) - ++__pos; - else - __pos = __sz; - const value_type* __p = data(); - for (const value_type* __ps = __p + __pos; __ps != __p;) - if (traits_type::find(__s, __n, *--__ps) == 0) - return static_cast(__ps - __p); - return npos; + return _VSTD::__find_last_not_of + (data(), size(), __s, __pos, __n); } template @@ -3543,7 +3606,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, size_type __pos) const _NOEXCEPT { - return find_last_not_of(__str.data(), __pos, __str.size()); + return _VSTD::__find_last_not_of + (data(), size(), __str.data(), __pos, __str.size()); } template @@ -3553,7 +3617,8 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __ size_type __pos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): recieved nullptr"); - return find_last_not_of(__s, __pos, traits_type::length(__s)); + return _VSTD::__find_last_not_of + (data(), size(), __s, __pos, traits_type::length(__s)); } template @@ -3562,16 +3627,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, size_type __pos) const _NOEXCEPT { - size_type __sz = size(); - if (__pos < __sz) - ++__pos; - else - __pos = __sz; - const value_type* __p = data(); - for (const value_type* __ps = __p + __pos; __ps != __p;) - if (!traits_type::eq(*--__ps, __c)) - return static_cast(__ps - __p); - return npos; + return _VSTD::__find_last_not_of + (data(), size(), __c, __pos); } // compare @@ -4060,13 +4117,6 @@ template const typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::npos; -template -size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e) -{ - typedef typename iterator_traits<_Ptr>::value_type value_type; - return __murmur2_or_cityhash()(__p, (__e-__p)*sizeof(value_type)); -} - template struct _LIBCPP_TYPE_VIS_ONLY hash > : public unary_function, size_t>