1//===- StringRef.h - Constant String Reference Wrapper ----------*- C++ -*-===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9#ifndef LLVM_ADT_STRINGREF_H 10#define LLVM_ADT_STRINGREF_H 31template <
typename T>
classSmallVectorImpl;
34 /// Helper functions for StringRef::getAsInteger. 36unsignedlonglong &Result);
41unsignedlonglong &Result);
44 /// StringRef - Represent a constant reference to a string, i.e. a character 45 /// array and a length, which need not be null terminated. 47 /// This class does not own the string data, it is expected to be used in 48 /// situations where the character data resides in some other buffer, whose 49 /// lifetime extends past that of the StringRef. For this reason, it is not in 50 /// general safe to store a StringRef. 53staticconstexprsize_tnpos = ~size_t(0);
63 /// The start of the string, in an external buffer. 64constchar *Data =
nullptr;
66 /// The length of the string. 69// Workaround memcmp issue with null pointers (undefined behavior) 70// by providing a specialized version 71staticint compareMemory(
constchar *Lhs,
constchar *Rhs,
size_t Length) {
72if (
Length == 0) {
return 0; }
73 return ::memcmp(Lhs,Rhs,
Length);
77 /// @name Constructors 80 /// Construct an empty string ref. 83 /// Disable conversion from nullptr. This prevents things like 87 /// Construct a string ref from a cstring. 90// GCC 7 doesn't have constexpr char_traits. Fall back to __builtin_strlen. 91#
if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 8
94std::char_traits<
char>::length(Str)
99 /// Construct a string ref from a pointer and length. 104 /// Construct a string ref from an std::string. 108 /// Construct a string ref from an std::string_view. 121return std::make_reverse_iterator(end());
125return std::make_reverse_iterator(begin());
129returnreinterpret_cast<constunsignedchar *
>(begin());
132returnreinterpret_cast<constunsignedchar *
>(end());
139 /// @name String Operations 142 /// data - Get a pointer to the start of the string (which may not be null 144 [[nodiscard]]
constexprconstchar *
data()
const{
return Data; }
146 /// empty - Check if the string is empty. 147 [[nodiscard]]
constexprboolempty()
const{
returnsize() == 0; }
149 /// size - Get the string size. 152 /// front - Get the first character in the string. 158 /// back - Get the last character in the string. 164// copy - Allocate copy in Allocator and return StringRef to it. 165template <
typename Allocator>
167// Don't request a length 0 copy from the allocator. 170char *S =
A.template Allocate<char>(
size());
171 std::copy(begin(), end(), S);
175 /// Check for string equality, ignoring case. 177returnsize() ==
RHS.size() && compare_insensitive(
RHS) == 0;
180 /// compare - Compare two strings; the result is negative, zero, or positive 181 /// if this string is lexicographically less than, equal to, or greater than 184// Check the prefix for a mismatch. 187return Res < 0 ? -1 : 1;
189// Otherwise the prefixes match, so we only need to check the lengths. 192returnsize() <
RHS.size() ? -1 : 1;
195 /// Compare two strings, ignoring case. 196 [[nodiscard]]
int compare_insensitive(
StringRefRHS)
const;
198 /// compare_numeric - Compare two strings, treating sequences of digits as 202 /// Determine the edit distance between this string and another 205 /// \param Other the string to compare this string against. 207 /// \param AllowReplacements whether to allow character 208 /// replacements (change one character into another) as a single 209 /// operation, rather than as two operations (an insertion and a 212 /// \param MaxEditDistance If non-zero, the maximum edit distance that 213 /// this routine is allowed to compute. If the edit distance will exceed 214 /// that maximum, returns \c MaxEditDistance+1. 216 /// \returns the minimum number of character insertions, removals, 217 /// or (if \p AllowReplacements is \c true) replacements needed to 218 /// transform one of the given strings into the other. If zero, 219 /// the strings are identical. 221bool AllowReplacements =
true,
222unsigned MaxEditDistance = 0)
const;
224 [[nodiscard]]
unsigned 225 edit_distance_insensitive(
StringRefOther,
bool AllowReplacements =
true,
226unsigned MaxEditDistance = 0)
const;
228 /// str - Get the contents as an std::string. 229 [[nodiscard]] std::string
str()
const{
236 /// @name Operator Overloads 244 /// Disallow accidental assignment from a temporary std::string. 246 /// The declaration here is extra complicated so that `stringRef = {}` 247 /// and `stringRef = "abc"` continue to select the move assignment operator. 249 std::enable_if_t<std::is_same<T, std::string>::value,
StringRef> &
253 /// @name Type Conversions 256constexproperator std::string_view()
const{
257return std::string_view(
data(),
size());
261 /// @name String Predicates 264 /// Check if this string starts with the given \p Prefix. 266returnsize() >= Prefix.size() &&
267 compareMemory(
data(), Prefix.data(), Prefix.size()) == 0;
270return !empty() && front() == Prefix;
273 /// Check if this string starts with the given \p Prefix, ignoring case. 274 [[nodiscard]]
bool starts_with_insensitive(
StringRef Prefix)
const;
276 /// Check if this string ends with the given \p Suffix. 279 compareMemory(end() - Suffix.
size(), Suffix.
data(),
283return !empty() && back() == Suffix;
286 /// Check if this string ends with the given \p Suffix, ignoring case. 287 [[nodiscard]]
bool ends_with_insensitive(
StringRef Suffix)
const;
290 /// @name String Searching 293 /// Search for the first character \p C in the string. 295 /// \returns The index of the first occurrence of \p C, or npos if not 298return std::string_view(*this).find(
C,
From);
301 /// Search for the first character \p C in the string, ignoring case. 303 /// \returns The index of the first occurrence of \p C, or npos if not 305 [[nodiscard]]
size_t find_insensitive(
charC,
size_tFrom = 0)
const;
307 /// Search for the first character satisfying the predicate \p F 309 /// \returns The index of the first character satisfying \p F starting from 310 /// \p From, or npos if not found. 312size_tFrom = 0)
const{
322 /// Search for the first character not satisfying the predicate \p F 324 /// \returns The index of the first character not satisfying \p F starting 325 /// from \p From, or npos if not found. 327size_tFrom = 0)
const{
331 /// Search for the first string \p Str in the string. 333 /// \returns The index of the first occurrence of \p Str, or npos if not 337 /// Search for the first string \p Str in the string, ignoring case. 339 /// \returns The index of the first occurrence of \p Str, or npos if not 341 [[nodiscard]]
size_t find_insensitive(
StringRef Str,
size_tFrom = 0)
const;
343 /// Search for the last character \p C in the string. 345 /// \returns The index of the last occurrence of \p C, or npos if not 357 /// Search for the last character \p C in the string, ignoring case. 359 /// \returns The index of the last occurrence of \p C, or npos if not 361 [[nodiscard]]
size_t rfind_insensitive(
charC,
size_tFrom =
npos)
const;
363 /// Search for the last string \p Str in the string. 365 /// \returns The index of the last occurrence of \p Str, or npos if not 367 [[nodiscard]]
size_t rfind(
StringRef Str)
const;
369 /// Search for the last string \p Str in the string, ignoring case. 371 /// \returns The index of the last occurrence of \p Str, or npos if not 373 [[nodiscard]]
size_t rfind_insensitive(
StringRef Str)
const;
375 /// Find the first character in the string that is \p C, or npos if not 376 /// found. Same as find. 381 /// Find the first character in the string that is in \p Chars, or npos if 384 /// Complexity: O(size() + Chars.size()) 385 [[nodiscard]]
size_t find_first_of(
StringRef Chars,
size_tFrom = 0)
const;
387 /// Find the first character in the string that is not \p C or npos if not 389 [[nodiscard]]
size_t find_first_not_of(
charC,
size_tFrom = 0)
const;
391 /// Find the first character in the string that is not in the string 392 /// \p Chars, or npos if not found. 394 /// Complexity: O(size() + Chars.size()) 395 [[nodiscard]]
size_t find_first_not_of(
StringRef Chars,
398 /// Find the last character in the string that is \p C, or npos if not 404 /// Find the last character in the string that is in \p C, or npos if not 407 /// Complexity: O(size() + Chars.size()) 408 [[nodiscard]]
size_t find_last_of(
StringRef Chars,
411 /// Find the last character in the string that is not \p C, or npos if not 413 [[nodiscard]]
size_t find_last_not_of(
charC,
size_tFrom =
npos)
const;
415 /// Find the last character in the string that is not in \p Chars, or 416 /// npos if not found. 418 /// Complexity: O(size() + Chars.size()) 419 [[nodiscard]]
size_t find_last_not_of(
StringRef Chars,
422 /// Return true if the given string is a substring of *this, and false 428 /// Return true if the given character is contained in *this, and false 431return find_first_of(
C) !=
npos;
434 /// Return true if the given string is a substring of *this, and false 440 /// Return true if the given character is contained in *this, and false 443return find_insensitive(
C) !=
npos;
447 /// @name Helpful Algorithms 450 /// Return the number of occurrences of \p C in the string. 453for (
size_tI = 0;
I !=
size(); ++
I)
459 /// Return the number of non-overlapped occurrences of \p Str in 463 /// Parse the current string as an integer of the specified radix. If 464 /// \p Radix is specified as zero, this does radix autosensing using 465 /// extended C rules: 0 is octal, 0x is hex, 0b is binary. 467 /// If the string is invalid or if only a subset of the string is valid, 468 /// this returns true to signify the error. The string is considered 469 /// erroneous if empty or if it overflows T. 471ifconstexpr (std::numeric_limits<T>::is_signed) {
474static_cast<T>(LLVal) != LLVal)
478unsignedlonglong ULLVal;
479// The additional cast to unsigned long long is required to avoid the 480// Visual C++ warning C4805: '!=' : unsafe mix of type 'bool' and type 481// 'unsigned __int64' when instantiating getAsInteger with T = bool. 483static_cast<unsignedlonglong>(
static_cast<T>(ULLVal)) != ULLVal)
490 /// Parse the current string as an integer of the specified radix. If 491 /// \p Radix is specified as zero, this does radix autosensing using 492 /// extended C rules: 0 is octal, 0x is hex, 0b is binary. 494 /// If the string does not begin with a number of the specified radix, 495 /// this returns true to signify the error. The string is considered 496 /// erroneous if empty or if it overflows T. 497 /// The portion of the string representing the discovered numeric value 498 /// is removed from the beginning of the string. 500ifconstexpr (std::numeric_limits<T>::is_signed) {
503static_cast<longlong>(
static_cast<T>(LLVal)) != LLVal)
507unsignedlonglong ULLVal;
509static_cast<unsignedlonglong>(
static_cast<T>(ULLVal)) != ULLVal)
516 /// Parse the current string as an integer of the specified \p Radix, or of 517 /// an autosensed radix if the \p Radix given is 0. The current value in 518 /// \p Result is discarded, and the storage is changed to be wide enough to 519 /// store the parsed integer. 521 /// \returns true if the string does not solely consist of a valid 522 /// non-empty number in the appropriate base. 524 /// APInt::fromString is superficially similar but assumes the 525 /// string is well-formed in the given radix. 526bool getAsInteger(
unsigned Radix,
APInt &Result)
const;
528 /// Parse the current string as an integer of the specified \p Radix. If 529 /// \p Radix is specified as zero, this does radix autosensing using 530 /// extended C rules: 0 is octal, 0x is hex, 0b is binary. 532 /// If the string does not begin with a number of the specified radix, 533 /// this returns true to signify the error. The string is considered 534 /// erroneous if empty. 535 /// The portion of the string representing the discovered numeric value 536 /// is removed from the beginning of the string. 537bool consumeInteger(
unsigned Radix,
APInt &Result);
539 /// Parse the current string as an IEEE double-precision floating 540 /// point value. The string must be a well-formed double. 542 /// If \p AllowInexact is false, the function will fail if the string 543 /// cannot be represented exactly. Otherwise, the function only fails 544 /// in case of an overflow or underflow, or an invalid floating point 546bool getAsDouble(
double &Result,
bool AllowInexact =
true)
const;
549 /// @name String Operations 552// Convert the given ASCII string to lowercase. 553 [[nodiscard]] std::string lower()
const;
555 /// Convert the given ASCII string to uppercase. 556 [[nodiscard]] std::string upper()
const;
559 /// @name Substring Operations 562 /// Return a reference to the substring from [Start, Start + N). 564 /// \param Start The index of the starting character in the substring; if 565 /// the index is npos or greater than the length of the string then the 566 /// empty substring will be returned. 568 /// \param N The number of characters to included in the substring. If N 569 /// exceeds the number of characters remaining in the string, the string 570 /// suffix (starting with \p Start) will be returned. 573 Start = std::min(Start,
size());
577 /// Return a StringRef equal to 'this' but with only the first \p N 578 /// elements remaining. If \p N is greater than the length of the 579 /// string, the entire string is returned. 583return drop_back(
size() -
N);
586 /// Return a StringRef equal to 'this' but with only the last \p N 587 /// elements remaining. If \p N is greater than the length of the 588 /// string, the entire string is returned. 592return drop_front(
size() -
N);
595 /// Return the longest prefix of 'this' such that every character 596 /// in the prefix satisfies the given predicate. 601 /// Return the longest prefix of 'this' such that no character in 602 /// the prefix satisfies the given predicate. 607 /// Return a StringRef equal to 'this' but with the first \p N elements 610assert(
size() >=
N &&
"Dropping more elements than exist");
614 /// Return a StringRef equal to 'this' but with the last \p N elements 617assert(
size() >=
N &&
"Dropping more elements than exist");
621 /// Return a StringRef equal to 'this', but with all characters satisfying 622 /// the given predicate dropped from the beginning of the string. 627 /// Return a StringRef equal to 'this', but with all characters not 628 /// satisfying the given predicate dropped from the beginning of the string. 633 /// Returns true if this StringRef has the given prefix and removes that 639 *
this =
substr(Prefix.size());
643 /// Returns true if this StringRef has the given prefix, ignoring case, 644 /// and removes that prefix. 646if (!starts_with_insensitive(Prefix))
649 *
this =
substr(Prefix.size());
653 /// Returns true if this StringRef has the given suffix and removes that 656if (!ends_with(Suffix))
663 /// Returns true if this StringRef has the given suffix, ignoring case, 664 /// and removes that suffix. 666if (!ends_with_insensitive(Suffix))
673 /// Return a reference to the substring from [Start, End). 675 /// \param Start The index of the starting character in the substring; if 676 /// the index is npos or greater than the length of the string then the 677 /// empty substring will be returned. 679 /// \param End The index following the last character to include in the 680 /// substring. If this is npos or exceeds the number of characters 681 /// remaining in the string, the string suffix (starting with \p Start) 682 /// will be returned. If this is less than \p Start, an empty string will 685 Start = std::min(Start,
size());
690 /// Split into two substrings around the first occurrence of a separator 693 /// If \p Separator is in the string, then the result is a pair (LHS, RHS) 694 /// such that (*this == LHS + Separator + RHS) is true and RHS is 695 /// maximal. If \p Separator is not in the string, then the result is a 696 /// pair (LHS, RHS) where (*this == LHS) and (RHS == ""). 698 /// \param Separator The character to split on. 699 /// \returns The split substrings. 700 [[nodiscard]] std::pair<StringRef, StringRef>
split(
char Separator)
const{
704 /// Split into two substrings around the first occurrence of a separator 707 /// If \p Separator is in the string, then the result is a pair (LHS, RHS) 708 /// such that (*this == LHS + Separator + RHS) is true and RHS is 709 /// maximal. If \p Separator is not in the string, then the result is a 710 /// pair (LHS, RHS) where (*this == LHS) and (RHS == ""). 712 /// \param Separator - The string to split on. 713 /// \return - The split substrings. 714 [[nodiscard]] std::pair<StringRef, StringRef>
722 /// Split into two substrings around the last occurrence of a separator 725 /// If \p Separator is in the string, then the result is a pair (LHS, RHS) 726 /// such that (*this == LHS + Separator + RHS) is true and RHS is 727 /// minimal. If \p Separator is not in the string, then the result is a 728 /// pair (LHS, RHS) where (*this == LHS) and (RHS == ""). 730 /// \param Separator - The string to split on. 731 /// \return - The split substrings. 732 [[nodiscard]] std::pair<StringRef, StringRef>
734size_tIdx = rfind(Separator);
740 /// Split into substrings around the occurrences of a separator string. 742 /// Each substring is stored in \p A. If \p MaxSplit is >= 0, at most 743 /// \p MaxSplit splits are done and consequently <= \p MaxSplit + 1 744 /// elements are added to A. 745 /// If \p KeepEmpty is false, empty strings are not added to \p A. They 746 /// still count when considering \p MaxSplit 747 /// An useful invariant is that 748 /// Separator.join(A) == *this if MaxSplit == -1 and KeepEmpty == true 750 /// \param A - Where to put the substrings. 751 /// \param Separator - The string to split on. 752 /// \param MaxSplit - The maximum number of times the string is split. 753 /// \param KeepEmpty - True if empty substring should be added. 756bool KeepEmpty =
true)
const;
758 /// Split into substrings around the occurrences of a separator character. 760 /// Each substring is stored in \p A. If \p MaxSplit is >= 0, at most 761 /// \p MaxSplit splits are done and consequently <= \p MaxSplit + 1 762 /// elements are added to A. 763 /// If \p KeepEmpty is false, empty strings are not added to \p A. They 764 /// still count when considering \p MaxSplit 765 /// An useful invariant is that 766 /// Separator.join(A) == *this if MaxSplit == -1 and KeepEmpty == true 768 /// \param A - Where to put the substrings. 769 /// \param Separator - The string to split on. 770 /// \param MaxSplit - The maximum number of times the string is split. 771 /// \param KeepEmpty - True if empty substring should be added. 773bool KeepEmpty =
true)
const;
775 /// Split into two substrings around the last occurrence of a separator 778 /// If \p Separator is in the string, then the result is a pair (LHS, RHS) 779 /// such that (*this == LHS + Separator + RHS) is true and RHS is 780 /// minimal. If \p Separator is not in the string, then the result is a 781 /// pair (LHS, RHS) where (*this == LHS) and (RHS == ""). 783 /// \param Separator - The character to split on. 784 /// \return - The split substrings. 785 [[nodiscard]] std::pair<StringRef, StringRef>
rsplit(
char Separator)
const{
789 /// Return string with consecutive \p Char characters starting from the 790 /// the left removed. 792return drop_front(std::min(
size(), find_first_not_of(Char)));
795 /// Return string with consecutive characters in \p Chars starting from 796 /// the left removed. 798return drop_front(std::min(
size(), find_first_not_of(Chars)));
801 /// Return string with consecutive \p Char characters starting from the 804return drop_back(
size() - std::min(
size(), find_last_not_of(Char) + 1));
807 /// Return string with consecutive characters in \p Chars starting from 808 /// the right removed. 810return drop_back(
size() - std::min(
size(), find_last_not_of(Chars) + 1));
813 /// Return string with consecutive \p Char characters starting from the 814 /// left and right removed. 816return ltrim(Char).
rtrim(Char);
819 /// Return string with consecutive characters in \p Chars starting from 820 /// the left and right removed. 822return ltrim(Chars).
rtrim(Chars);
825 /// Detect the line ending style of the string. 827 /// If the string contains a line ending, return the line ending character 828 /// sequence that is detected. Otherwise return '\n' for unix line endings. 830 /// \return - The line ending character sequence. 832size_t Pos =
find(
'\r');
834// If there is no carriage return, assume unix 837if (Pos + 1 <
size() &&
data()[Pos + 1] ==
'\n')
838return"\r\n";
// Windows 839if (Pos > 0 &&
data()[Pos - 1] ==
'\n')
840return"\n\r";
// You monster! 841return"\r";
// Classic Mac 846 /// A wrapper around a string literal that serves as a proxy for constructing 847 /// global tables of StringRefs with the length computed at compile time. 848 /// In order to avoid the invocation of a global constructor, StringLiteral 849 /// should *only* be used in a constexpr context, as such: 851 /// constexpr StringLiteral S("test"); 861#if defined(__clang__) && __has_attribute(enable_if) 862#pragma clang diagnostic push 863#pragma clang diagnostic ignored "-Wgcc-compat" 864 __attribute((enable_if(__builtin_strlen(Str) ==
N - 1,
865"invalid string literal")))
866#pragma clang diagnostic pop 871// Explicit construction for strings like "foo\0bar". 878 /// @name StringRef Comparison Operators 882if (
LHS.size() !=
RHS.size())
886 return ::memcmp(
LHS.data(),
RHS.data(),
LHS.size()) == 0;
892returnLHS.compare(
RHS) < 0;
896returnLHS.compare(
RHS) <= 0;
900returnLHS.compare(
RHS) > 0;
904returnLHS.compare(
RHS) >= 0;
908return buffer.append(
string.
data(),
string.
size());
913 /// Compute a hash_code for a StringRef. 914 [[nodiscard]] hash_code
hash_value(StringRef S);
916// Provide DenseMapInfo for StringRefs. 920reinterpret_cast<constchar *
>(~
static_cast<uintptr_t
>(0)), 0);
925reinterpret_cast<constchar *
>(~
static_cast<uintptr_t
>(1)), 0);
931if (
RHS.data() == getEmptyKey().
data())
932returnLHS.data() == getEmptyKey().data();
933if (
RHS.data() == getTombstoneKey().
data())
934returnLHS.data() == getTombstoneKey().data();
939}
// end namespace llvm 941#endif// LLVM_ADT_STRINGREF_H BlockVerifier::State From
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_LIFETIME_BOUND
#define LLVM_GSL_POINTER
LLVM_GSL_POINTER - Apply this to non-owning classes like StringRef to enable lifetime warnings.
static constexpr size_t npos
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines DenseMapInfo traits for DenseMap.
std::optional< std::vector< StOtherPiece > > Other
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static StringRef substr(StringRef Str, uint64_t Len)
DEMANGLE_NAMESPACE_BEGIN bool starts_with(std::string_view self, char C) noexcept
Class for arbitrary precision integers.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
constexpr StringLiteral(const char(&Str)[N])
static constexpr StringLiteral withInnerNUL(const char(&Str)[N])
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
StringRef trim(StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the left and right removed.
bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
bool consumeInteger(unsigned Radix, T &Result)
Parse the current string as an integer of the specified radix.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
iterator_range< const unsigned char * > bytes() const
std::string str() const
str - Get the contents as an std::string.
size_t find_if(function_ref< bool(char)> F, size_t From=0) const
Search for the first character satisfying the predicate F.
const unsigned char * bytes_end() const
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
std::reverse_iterator< const_iterator > const_reverse_iterator
bool contains_insensitive(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
StringRef take_while(function_ref< bool(char)> F) const
Return the longest prefix of 'this' such that every character in the prefix satisfies the given predi...
bool ends_with(char Suffix) const
char operator[](size_t Index) const
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
bool contains_insensitive(char C) const
Return true if the given character is contained in *this, and false otherwise.
std::pair< StringRef, StringRef > rsplit(char Separator) const
Split into two substrings around the last occurrence of a separator character.
StringRef drop_until(function_ref< bool(char)> F) const
Return a StringRef equal to 'this', but with all characters not satisfying the given predicate droppe...
char back() const
back - Get the last character in the string.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
constexpr size_t size() const
size - Get the string size.
char front() const
front - Get the first character in the string.
reverse_iterator rbegin() const
constexpr StringRef(const char *data LLVM_LIFETIME_BOUND, size_t length)
Construct a string ref from a pointer and length.
std::reverse_iterator< iterator > reverse_iterator
bool starts_with(char Prefix) const
size_t find_last_of(char C, size_t From=npos) const
Find the last character in the string that is C, or npos if not found.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef ltrim(char Char) const
Return string with consecutive Char characters starting from the the left removed.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
StringRef detectEOL() const
Detect the line ending style of the string.
size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
StringRef()=default
Construct an empty string ref.
size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
StringRef rtrim(char Char) const
Return string with consecutive Char characters starting from the right removed.
constexpr StringRef(const char *Str LLVM_LIFETIME_BOUND)
Construct a string ref from a cstring.
bool contains(char C) const
Return true if the given character is contained in *this, and false otherwise.
StringRef(std::nullptr_t)=delete
Disable conversion from nullptr.
StringRef take_back(size_t N=1) const
Return a StringRef equal to 'this' but with only the last N elements remaining.
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
StringRef take_until(function_ref< bool(char)> F) const
Return the longest prefix of 'this' such that no character in the prefix satisfies the given predicat...
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
size_t count(char C) const
Return the number of occurrences of C in the string.
bool consume_back_insensitive(StringRef Suffix)
Returns true if this StringRef has the given suffix, ignoring case, and removes that suffix.
StringRef copy(Allocator &A) const
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
std::pair< StringRef, StringRef > rsplit(StringRef Separator) const
Split into two substrings around the last occurrence of a separator string.
std::pair< StringRef, StringRef > split(StringRef Separator) const
Split into two substrings around the first occurrence of a separator string.
StringRef ltrim(StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the left removed.
std::enable_if_t< std::is_same< T, std::string >::value, StringRef > & operator=(T &&Str)=delete
Disallow accidental assignment from a temporary std::string.
StringRef rtrim(StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the right removed.
StringRef drop_while(function_ref< bool(char)> F) const
Return a StringRef equal to 'this', but with all characters satisfying the given predicate dropped fr...
const unsigned char * bytes_begin() const
int compare(StringRef RHS) const
compare - Compare two strings; the result is negative, zero, or positive if this string is lexicograp...
StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
bool consume_front_insensitive(StringRef Prefix)
Returns true if this StringRef has the given prefix, ignoring case, and removes that prefix.
StringRef(const std::string &Str)
Construct a string ref from an std::string.
reverse_iterator rend() const
constexpr StringRef(std::string_view Str)
Construct a string ref from an std::string_view.
size_t find_if_not(function_ref< bool(char)> F, size_t From=0) const
Search for the first character not satisfying the predicate F.
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
bool getAsSignedInteger(StringRef Str, unsigned Radix, long long &Result)
hash_code hash_value(const FixedPointSemantics &Val)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
bool operator!=(uint64_t V1, const APInt &V2)
bool operator>=(int64_t V1, const APSInt &V2)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator+=(DynamicAPInt &A, int64_t B)
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
bool consumeUnsignedInteger(StringRef &Str, unsigned Radix, unsigned long long &Result)
bool operator>(int64_t V1, const APSInt &V2)
auto find_if_not(R &&Range, UnaryPredicate P)
bool consumeSignedInteger(StringRef &Str, unsigned Radix, long long &Result)
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
bool operator<=(int64_t V1, const APSInt &V2)
Implement std::hash so that hash_code can be used in STL containers.
static StringRef getEmptyKey()
static bool isEqual(StringRef LHS, StringRef RHS)
static unsigned getHashValue(StringRef Val)
static StringRef getTombstoneKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...