10 #ifndef LLVM_ADT_STRINGREF_H
11 #define LLVM_ADT_STRINGREF_H
25 class SmallVectorImpl;
32 unsigned long long &Result);
37 unsigned long long &Result);
51 static const size_t npos = ~size_t(0);
56 const char *Data =
nullptr;
64 static int compareMemory(
const char *Lhs,
const char *Rhs,
size_t Length) {
65 if (Length == 0) {
return 0; }
66 return ::memcmp(Lhs,Rhs,Length);
83 : Data(Str), Length(Str ? ::strlen(Str) : 0) {}
88 : Data(data), Length(length) {}
93 : Data(Str.
data()), Length(Str.length()) {}
108 return reinterpret_cast<const unsigned char *
>(
begin());
111 return reinterpret_cast<const unsigned char *
>(
end());
125 const char *
data()
const {
return Data; }
130 bool empty()
const {
return Length == 0; }
135 size_t size()
const {
return Length; }
148 return Data[Length-1];
152 template <
typename Allocator>
157 char *S = A.template Allocate<char>(Length);
167 return (Length == RHS.Length &&
168 compareMemory(Data, RHS.Data, RHS.Length) == 0);
183 if (
int Res = compareMemory(Data, RHS.Data,
std::min(Length, RHS.Length)))
184 return Res < 0 ? -1 : 1;
187 if (Length == RHS.Length)
189 return Length < RHS.Length ? -1 : 1;
221 unsigned MaxEditDistance = 0)
const;
226 if (!Data)
return std::string();
227 return std::string(Data, Length);
236 assert(Index < Length &&
"Invalid index!");
244 template <
typename T>
245 typename std::enable_if<std::is_same<T, std::string>::value,
253 operator std::string()
const {
265 return Length >= Prefix.Length &&
266 compareMemory(Data, Prefix.Data, Prefix.Length) == 0;
277 return Length >= Suffix.Length &&
278 compareMemory(
end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0;
295 size_t find(
char C,
size_t From = 0)
const {
296 size_t FindBegin =
std::min(From, Length);
297 if (FindBegin < Length) {
299 if (
const void *
P = ::memchr(Data + FindBegin, C, Length - FindBegin))
300 return static_cast<const char *
>(
P) - Data;
335 return find_if([
F](
char c) {
return !
F(c); }, From);
393 return find(C, From);
419 return rfind(C, From);
475 for (
size_t i = 0, e = Length;
i != e; ++
i)
492 template <
typename T>
493 typename std::enable_if<std::numeric_limits<T>::is_signed,
bool>::type
497 static_cast<T>(LLVal) != LLVal)
503 template <
typename T>
504 typename std::enable_if<!std::numeric_limits<T>::is_signed,
bool>::type
506 unsigned long long ULLVal;
511 static_cast<unsigned long long>(static_cast<T>(ULLVal)) != ULLVal)
526 template <
typename T>
527 typename std::enable_if<std::numeric_limits<T>::is_signed,
bool>::type
531 static_cast<long long>(static_cast<T>(LLVal)) != LLVal)
537 template <
typename T>
538 typename std::enable_if<!std::numeric_limits<T>::is_signed,
bool>::type
540 unsigned long long ULLVal;
542 static_cast<unsigned long long>(static_cast<T>(ULLVal)) != ULLVal)
566 std::string
lower()
const;
570 std::string
upper()
const;
635 assert(
size() >=
N &&
"Dropping more elements than exist");
644 assert(
size() >=
N &&
"Dropping more elements than exist");
701 End =
std::min(std::max(Start, End), Length);
702 return StringRef(Data + Start, End - Start);
717 size_t Idx =
find(Separator);
719 return std::make_pair(*
this,
StringRef());
735 size_t Idx =
find(Separator);
737 return std::make_pair(*
this,
StringRef());
757 bool KeepEmpty =
true)
const;
774 bool KeepEmpty =
true)
const;
788 size_t Idx =
rfind(Separator);
790 return std::make_pair(*
this,
StringRef());
850 #if defined(__clang__) && __has_attribute(enable_if)
851 #pragma clang diagnostic push
852 #pragma clang diagnostic ignored "-Wgcc-compat"
853 __attribute((enable_if(__builtin_strlen(Str) == N - 1,
854 "invalid string literal")))
855 #pragma clang diagnostic pop
889 return buffer.append(
string.data(),
string.size());
899 template <
typename T>
struct isPodLike;
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE 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.
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE 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...
std::string & operator+=(std::string &buffer, StringRef string)
static StringRef withNullAsEmpty(const char *data)
LLVM_NODISCARD int compare_lower(StringRef RHS) const
compare_lower - Compare two strings, ignoring case.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef take_back(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
LLVM_NODISCARD StringRef ltrim(StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the left removed.
bool consumeUnsignedInteger(StringRef &Str, unsigned Radix, unsigned long long &Result)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
LLVM_NODISCARD size_t rfind_lower(char C, size_t From=npos) const
Search for the last character C in the string, ignoring case.
bool operator>(int64_t V1, const APSInt &V2)
LLVM_NODISCARD size_t find_lower(char C, size_t From=0) const
Search for the first character C in the string, ignoring case.
LLVM_NODISCARD bool equals_lower(StringRef RHS) const
equals_lower - Check for string equality, ignoring case.
An efficient, type-erasing, non-owning reference to a callable.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE 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_end() const
std::enable_if<!std::numeric_limits< T >::is_signed, bool >::type consumeInteger(unsigned Radix, T &Result)
LLVM_NODISCARD char back() const
back - Get the last character in the string.
LLVM_NODISCARD bool endswith_lower(StringRef Suffix) const
Check if this string ends with the given Suffix, ignoring case.
bool operator<=(int64_t V1, const APSInt &V2)
bool operator>=(int64_t V1, const APSInt &V2)
LLVM_ATTRIBUTE_ALWAYS_INLINE bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
LLVM_NODISCARD StringRef rtrim(char Char) const
Return string with consecutive Char characters starting from the right removed.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
LLVM_ATTRIBUTE_ALWAYS_INLINE bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type consumeInteger(unsigned Radix, T &Result)
Parse the current string as an integer of the specified radix.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
StringRef()=default
Construct an empty string ref.
LLVM_NODISCARD char front() const
front - Get the first character in the string.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
LLVM_ATTRIBUTE_ALWAYS_INLINE constexpr StringRef(const char *data, size_t length)
Construct a string ref from a pointer and length.
LLVM_NODISCARD size_t find_last_not_of(char C, size_t From=npos) const
Find the last character in the string that is not C, or npos if not found.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE 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...
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
LLVM_NODISCARD StringRef rtrim(StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the right removed.
LLVM_NODISCARD std::pair< StringRef, StringRef > rsplit(char Separator) const
Split into two substrings around the last occurrence of a separator character.
LLVM_NODISCARD 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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Greedy Register Allocator
LLVM_NODISCARD StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
LLVM_NODISCARD size_t count(char C) const
Return the number of occurrences of C in the string.
static const unsigned End
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find_if(function_ref< bool(char)> F, size_t From=0) const
Search for the first character satisfying the predicate F.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool contains_lower(char C) const
Return true if the given character is contained in *this, and false otherwise.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE int compare(StringRef RHS) const
compare - Compare two strings; the result is -1, 0, or 1 if this string is lexicographically less tha...
LLVM_NODISCARD size_t find_first_not_of(char C, size_t From=0) const
Find the first character in the string that is not C or npos if not found.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef(const std::string &Str)
Construct a string ref from an std::string.
LLVM_NODISCARD unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
LLVM_NODISCARD size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool contains(char C) const
Return true if the given character is contained in *this, and false otherwise.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
const char * const_iterator
std::enable_if<!std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
LLVM_NODISCARD std::pair< StringRef, StringRef > split(StringRef Separator) const
Split into two substrings around the first occurrence of a separator string.
static const char * Separator
LLVM_NODISCARD std::string upper() const
Convert the given ASCII string to uppercase.
std::enable_if< std::is_same< T, std::string >::value, StringRef >::type & operator=(T &&Str)=delete
Disallow accidental assignment from a temporary std::string.
LLVM_NODISCARD char operator[](size_t Index) const
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
A range adaptor for a pair of iterators.
Class for arbitrary precision integers.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
LLVM_NODISCARD StringRef copy(Allocator &A) const
constexpr StringLiteral(const char(&Str)[N])
bool operator!=(uint64_t V1, const APInt &V2)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE 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...
LLVM_NODISCARD StringRef ltrim(char Char) const
Return string with consecutive Char characters starting from the the left removed.
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
LLVM_NODISCARD 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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
iterator_range< const unsigned char * > bytes() const
LLVM_NODISCARD int compare_numeric(StringRef RHS) const
compare_numeric - Compare two strings, treating sequences of digits as numbers.
const unsigned char * bytes_begin() const
bool operator<(int64_t V1, const APSInt &V2)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef - Represent a constant reference to a string, i.e.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
bool operator==(uint64_t V1, const APInt &V2)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool contains_lower(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
LLVM_NODISCARD StringRef trim(StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the left and right removed...
LLVM_NODISCARD bool startswith_lower(StringRef Prefix) const
Check if this string starts with the given Prefix, ignoring case.
bool consumeSignedInteger(StringRef &Str, unsigned Radix, long long &Result)
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
LLVM_NODISCARD std::string lower() const
bool getAsSignedInteger(StringRef Str, unsigned Radix, long long &Result)
LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef(const char *Str)
Construct a string ref from a cstring.