From 1b97645e56bf321b06d1353024339958b64fd242 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 15 Oct 2022 15:06:37 -0700 Subject: [ADT] Introduce StringRef::{starts,ends}_width{,_insensitive} This patch introduces: StringRef::starts_with StringRef::starts_with_insensitive StringRef::ends_with StringRef::ends_with_insensitive to be more compatible with std::string and std::string_view. I'm planning to deprecate the existing functions in favor of the new ones. Differential Revision: https://reviews.llvm.org/D136030 --- llvm/lib/Support/StringRef.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Support/StringRef.cpp') diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp index 7e19a79..dd54d53 100644 --- a/llvm/lib/Support/StringRef.cpp +++ b/llvm/lib/Support/StringRef.cpp @@ -42,12 +42,12 @@ int StringRef::compare_insensitive(StringRef RHS) const { return Length < RHS.Length ? -1 : 1; } -bool StringRef::startswith_insensitive(StringRef Prefix) const { +bool StringRef::starts_with_insensitive(StringRef Prefix) const { return Length >= Prefix.Length && ascii_strncasecmp(Data, Prefix.Data, Prefix.Length) == 0; } -bool StringRef::endswith_insensitive(StringRef Suffix) const { +bool StringRef::ends_with_insensitive(StringRef Suffix) const { return Length >= Suffix.Length && ascii_strncasecmp(end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0; } -- cgit v1.1