10 #ifndef LLVM_ADT_STRINGREF_H
11 #define LLVM_ADT_STRINGREF_H
22 #include <type_traits>
29 template <
typename T>
class SmallVectorImpl;
34 unsigned long long &Result);
39 unsigned long long &Result);
59 const char *Data =
nullptr;
67 static int compareMemory(
const char *Lhs,
const char *Rhs,
size_t Length) {
68 if (Length == 0) {
return 0; }
69 return ::memcmp(Lhs,Rhs,Length);
86 : Data(Str), Length(Str ? ::strlen(Str) : 0) {}
91 : Data(data), Length(length) {}
96 : Data(Str.
data()), Length(Str.length()) {}
111 return reinterpret_cast<const unsigned char *
>(
begin());
114 return reinterpret_cast<const unsigned char *
>(
end());
128 const char *
data()
const {
return Data; }
133 bool empty()
const {
return Length == 0; }
138 size_t size()
const {
return Length; }
151 return Data[Length-1];
155 template <
typename Allocator>
160 char *S = A.template Allocate<char>(Length);
170 return (Length == RHS.Length &&
171 compareMemory(Data, RHS.Data, RHS.Length) == 0);
186 if (
int Res = compareMemory(Data, RHS.Data,
std::min(Length, RHS.Length)))
187 return Res < 0 ? -1 : 1;
190 if (Length == RHS.Length)
192 return Length < RHS.Length ? -1 : 1;
224 unsigned MaxEditDistance = 0)
const;
229 if (!Data)
return std::string();
230 return std::string(Data, Length);
239 assert(Index < Length &&
"Invalid index!");
247 template <
typename T>
248 typename std::enable_if<std::is_same<T, std::string>::value,
256 operator std::string()
const {
268 return Length >= Prefix.Length &&
269 compareMemory(Data, Prefix.Data, Prefix.Length) == 0;
280 return Length >= Suffix.Length &&
281 compareMemory(
end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0;
298 size_t find(
char C,
size_t From = 0)
const {
299 size_t FindBegin =
std::min(From, Length);
300 if (FindBegin < Length) {
302 if (
const void *
P = ::memchr(Data + FindBegin, C, Length - FindBegin))
303 return static_cast<const char *
>(
P) - Data;
338 return find_if([
F](
char c) {
return !
F(c); }, From);
396 return find(C, From);
422 return rfind(C, From);
478 for (
size_t i = 0, e = Length; i != e; ++i)
495 template <
typename T>
496 typename std::enable_if<std::numeric_limits<T>::is_signed,
bool>::type
500 static_cast<T>(LLVal) != LLVal)
506 template <
typename T>
507 typename std::enable_if<!std::numeric_limits<T>::is_signed,
bool>::type
509 unsigned long long ULLVal;
514 static_cast<unsigned long long>(static_cast<T>(ULLVal)) != ULLVal)
529 template <
typename T>
530 typename std::enable_if<std::numeric_limits<T>::is_signed,
bool>::type
534 static_cast<long long>(static_cast<T>(LLVal)) != LLVal)
540 template <
typename T>
541 typename std::enable_if<!std::numeric_limits<T>::is_signed,
bool>::type
543 unsigned long long ULLVal;
545 static_cast<unsigned long long>(static_cast<T>(ULLVal)) != ULLVal)
569 bool getAsDouble(
double &Result,
bool AllowInexact =
true)
const;
577 std::string
lower()
const;
581 std::string
upper()
const;
646 assert(
size() >=
N &&
"Dropping more elements than exist");
655 assert(
size() >=
N &&
"Dropping more elements than exist");
713 return StringRef(Data + Start, End - Start);
728 size_t Idx =
find(Separator);
730 return std::make_pair(*
this,
StringRef());
746 size_t Idx =
find(Separator);
748 return std::make_pair(*
this,
StringRef());
768 bool KeepEmpty =
true)
const;
785 bool KeepEmpty =
true)
const;
799 size_t Idx =
rfind(Separator);
801 return std::make_pair(*
this,
StringRef());
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
900 return buffer.append(
string.data(),
string.size());
910 template <
typename T>
struct isPodLike;
915 #endif // LLVM_ADT_STRINGREF_H
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.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef take_back(size_t N=1) const
Return a StringRef equal to 'this' but with only the last 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.
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 tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
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.
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).
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 ...
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
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
bool getAsDouble(double &Result, bool AllowInexact=true) const
Parse the current string as an IEEE double-precision floating point value.
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)
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.