summaryrefslogtreecommitdiffstats
path: root/libcxx/include/string_view
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2017-12-04 20:11:38 +0000
committerMarshall Clow <mclow.lists@gmail.com>2017-12-04 20:11:38 +0000
commit800259c98d6fe81fefabb38c01a79504f2652cf2 (patch)
treecc866a4940edef9a6d7bcb0b505433f64756e059 /libcxx/include/string_view
parentde4c0ae2055824cd0d861966cfc543e02a97b211 (diff)
downloadbcm5719-llvm-800259c98d6fe81fefabb38c01a79504f2652cf2.tar.gz
bcm5719-llvm-800259c98d6fe81fefabb38c01a79504f2652cf2.zip
Implement P0457R2: 'String Prefix and Suffix Checking' for c++2a
llvm-svn: 319687
Diffstat (limited to 'libcxx/include/string_view')
-rw-r--r--libcxx/include/string_view33
1 files changed, 33 insertions, 0 deletions
diff --git a/libcxx/include/string_view b/libcxx/include/string_view
index 4d8e1a9312c..4d8358288f0 100644
--- a/libcxx/include/string_view
+++ b/libcxx/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;
OpenPOWER on IntegriCloud