diff options
Diffstat (limited to 'include/string_view')
-rw-r--r-- | include/string_view | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/include/string_view b/include/string_view index 4d8e1a931..4d8358288 100644 --- a/include/string_view +++ b/include/string_view @@ -143,6 +143,13 @@ namespace std { constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const; constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const; + constexpr bool starts_with(basic_string_view s) const noexcept; // C++2a + constexpr bool starts_with(charT c) const noexcept; // C++2a + constexpr bool starts_with(const charT* s) const; // C++2a + constexpr bool ends_with(basic_string_view s) const noexcept; // C++2a + constexpr bool ends_with(charT c) const noexcept; // C++2a + constexpr bool ends_with(const charT* s) const; // C++2a + private: const_pointer data_; // exposition only size_type size_; // exposition only @@ -565,6 +572,32 @@ public: (data(), size(), __s, __pos, traits_type::length(__s)); } +#if _LIBCPP_STD_VER > 17 + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(basic_string_view __s) const _NOEXCEPT + { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(front(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(const value_type* __s) const _NOEXCEPT + { return starts_with(basic_string_view(__s)); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(basic_string_view __s) const _NOEXCEPT + { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(back(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(const value_type* __s) const _NOEXCEPT + { return ends_with(basic_string_view(__s)); } +#endif + private: const value_type* __data; size_type __size; |