Skip to content

Commit

Permalink
Add lifetimebound to StripPrefix/StripSuffix.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 718507839
Change-Id: I86e394b1d29150c3cf1c9aaec6cd84785f4c3684
  • Loading branch information
Abseil Team authored and copybara-github committed Jan 22, 2025
1 parent fd8b35b commit 5f8d605
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions absl/strings/strip.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <cstddef>
#include <string>

#include "absl/base/attributes.h"
#include "absl/base/macros.h"
#include "absl/base/nullability.h"
#include "absl/strings/ascii.h"
Expand Down Expand Up @@ -74,7 +75,8 @@ inline constexpr bool ConsumeSuffix(absl::Nonnull<absl::string_view*> 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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 5f8d605

Please sign in to comment.