From 220d4ae0a9e50a314a2d8c693a8ae45bd1ad40d6 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 10 Oct 2021 17:47:57 +0300 Subject: [PATCH] Improve starts_with/ends_with --- include/boost/core/string_view.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/core/string_view.hpp b/include/boost/core/string_view.hpp index 05c7393..3c35c48 100644 --- a/include/boost/core/string_view.hpp +++ b/include/boost/core/string_view.hpp @@ -592,7 +592,7 @@ public: BOOST_CONSTEXPR bool starts_with( basic_string_view x ) const BOOST_NOEXCEPT { - return substr( 0, x.size() ) == x; + return size() >= x.size() && traits_type::compare( data(), x.data(), x.size() ) == 0; } BOOST_CONSTEXPR bool starts_with( Ch x ) const BOOST_NOEXCEPT @@ -609,7 +609,7 @@ public: BOOST_CONSTEXPR bool ends_with( basic_string_view x ) const BOOST_NOEXCEPT { - return size() >= x.size() && compare( size() - x.size(), npos, x ) == 0; + return size() >= x.size() && traits_type::compare( data() + size() - x.size(), x.data(), x.size() ) == 0; } BOOST_CONSTEXPR bool ends_with( Ch x ) const BOOST_NOEXCEPT