From 5f8d605c098acf44c73577ab8df48cad8067c587 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 22 Jan 2025 13:31:42 -0800 Subject: [PATCH] Add lifetimebound to StripPrefix/StripSuffix. PiperOrigin-RevId: 718507839 Change-Id: I86e394b1d29150c3cf1c9aaec6cd84785f4c3684 --- absl/strings/strip.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/absl/strings/strip.h b/absl/strings/strip.h index 4a8c5e77510..8a55375169e 100644 --- a/absl/strings/strip.h +++ b/absl/strings/strip.h @@ -24,6 +24,7 @@ #include #include +#include "absl/base/attributes.h" #include "absl/base/macros.h" #include "absl/base/nullability.h" #include "absl/strings/ascii.h" @@ -74,7 +75,8 @@ inline constexpr bool ConsumeSuffix(absl::Nonnull str, // but leaving the original string intact. If the prefix does not match at the // start of the string, returns the original string instead. ABSL_MUST_USE_RESULT inline constexpr absl::string_view StripPrefix( - absl::string_view str, absl::string_view prefix) { + absl::string_view str ABSL_ATTRIBUTE_LIFETIME_BOUND, + absl::string_view prefix) { if (absl::StartsWith(str, prefix)) str.remove_prefix(prefix.size()); return str; } @@ -85,7 +87,8 @@ ABSL_MUST_USE_RESULT inline constexpr absl::string_view StripPrefix( // but leaving the original string intact. If the suffix does not match at the // end of the string, returns the original string instead. ABSL_MUST_USE_RESULT inline constexpr absl::string_view StripSuffix( - absl::string_view str, absl::string_view suffix) { + absl::string_view str ABSL_ATTRIBUTE_LIFETIME_BOUND, + absl::string_view suffix) { if (absl::EndsWith(str, suffix)) str.remove_suffix(suffix.size()); return str; }