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; }
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;
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;
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;
599 Start = std::min(Start, Length);
600 return StringRef(Data + Start, std::min(
N, Length - Start));
646 assert(
size() >=
N &&
"Dropping more elements than exist");
655 assert(
size() >=
N &&
"Dropping more elements than exist");
711 Start = std::min(Start, Length);
712 End = std::min(
std::max(Start, End), Length);
713 return StringRef(Data + Start, End - Start);
727 std::pair<StringRef, StringRef>
split(
char Separator)
const {
743 size_t Idx =
find(Separator);
745 return std::make_pair(*
this,
StringRef());
761 size_t Idx =
rfind(Separator);
763 return std::make_pair(*
this,
StringRef());
783 bool KeepEmpty =
true)
const;
800 bool KeepEmpty =
true)
const;
813 std::pair<StringRef, StringRef>
rsplit(
char Separator)
const {
877 #if defined(__clang__) && __has_attribute(enable_if) 878 #pragma clang diagnostic push 879 #pragma clang diagnostic ignored "-Wgcc-compat" 880 __attribute((enable_if(__builtin_strlen(Str) == N - 1,
881 "invalid string literal")))
882 #pragma clang diagnostic pop 890 return StringLiteral(Str, N - 1);
922 return buffer.append(
string.
data(),
string.
size());
937 #endif // LLVM_ADT_STRINGREF_H
std::string & operator+=(std::string &buffer, StringRef string)
std::enable_if<!std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
static StringRef withNullAsEmpty(const char *data)
LLVM_NODISCARD char operator[](size_t Index) const
LLVM_NODISCARD bool startswith_lower(StringRef Prefix) const
Check if this string starts with the given Prefix, ignoring case.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
This class represents lattice values for constants.
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.
const unsigned char * bytes_end() const
LLVM_NODISCARD bool equals_lower(StringRef RHS) const
equals_lower - Check for string equality, ignoring case.
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.
bool consumeUnsignedInteger(StringRef &Str, unsigned Radix, unsigned long long &Result)
LLVM_NODISCARD size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
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 LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
bool operator>(int64_t V1, const APSInt &V2)
static constexpr StringLiteral withInnerNUL(const char(&Str)[N])
An efficient, type-erasing, non-owning reference to a callable.
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 std::pair< StringRef, StringRef > rsplit(StringRef Separator) const
Split into two substrings around the last occurrence of a separator string.
LLVM_NODISCARD bool endswith_lower(StringRef Suffix) const
Check if this string ends with the given Suffix, ignoring case.
LLVM_NODISCARD StringRef ltrim(char Char) const
Return string with consecutive Char characters starting from the the left removed.
std::enable_if<!std::numeric_limits< T >::is_signed, bool >::type consumeInteger(unsigned Radix, T &Result)
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 LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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.
bool operator<=(int64_t V1, const APSInt &V2)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
bool operator>=(int64_t V1, const APSInt &V2)
LLVM_NODISCARD StringRef copy(Allocator &A) const
LLVM_NODISCARD size_t count(char C) const
Return the number of occurrences of C in the string.
LLVM_ATTRIBUTE_ALWAYS_INLINE bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
iterator_range< const unsigned char * > bytes() const
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...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
LLVM_ATTRIBUTE_ALWAYS_INLINE bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that 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.
#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 StringRef rtrim(StringRef Chars=" \\\) const
Return string with consecutive characters in Chars starting from the right removed.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
LLVM_NODISCARD std::pair< StringRef, StringRef > rsplit(char Separator) const
Split into two substrings around the last occurrence of a separator character.
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
StringRef()=default
Construct an empty string ref.
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 LLVM_ATTRIBUTE_ALWAYS_INLINE bool contains_lower(char C) const
Return true if the given character is contained in *this, and false otherwise.
LLVM_ATTRIBUTE_ALWAYS_INLINE constexpr StringRef(const char *data, size_t length)
Construct a string ref from a pointer and length.
LLVM_NODISCARD std::string upper() const
Convert the given ASCII string to uppercase.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
LLVM_NODISCARD StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
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_NODISCARD size_t rfind_lower(char C, size_t From=npos) const
Search for the last character C in the string, ignoring case.
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 StringRef ltrim(StringRef Chars=" \\\) const
Return string with consecutive characters in Chars starting from the left removed.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef(const std::string &Str)
Construct a string ref from an std::string.
LLVM_NODISCARD char back() const
back - Get the last character in the string.
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.
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.
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_while(function_ref< bool(char)> F) const
Return the longest prefix of 'this' such that every character in the prefix satisfies the given predi...
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 int compare_lower(StringRef RHS) const
compare_lower - Compare two strings, ignoring case.
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...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool contains(char C) const
Return true if the given character is contained in *this, and false otherwise.
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
BlockVerifier::State From
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool getAsDouble(double &Result, bool AllowInexact=true) const
Parse the current string as an IEEE double-precision floating point value.
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 LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
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 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.
A range adaptor for a pair of iterators.
Class for arbitrary precision integers.
An opaque object representing a hash code.
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 int compare_numeric(StringRef RHS) const
compare_numeric - Compare two strings, treating sequences of digits as numbers.
constexpr StringLiteral(const char(&Str)[N])
bool operator!=(uint64_t V1, const APInt &V2)
const unsigned char * bytes_begin() const
Merge contiguous icmps into a memcmp
LLVM_NODISCARD StringRef trim(StringRef Chars=" \\\) const
Return string with consecutive characters in Chars starting from the left and right removed...
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.
LLVM_NODISCARD std::string lower() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM_NODISCARD char front() const
front - Get the first character in the string.
bool operator<(int64_t V1, const APSInt &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 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...
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_NODISCARD StringRef rtrim(char Char) const
Return string with consecutive Char characters starting from the right removed.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(StringRef Separator) const
Split into two substrings around the first occurrence of a separator string.
StringRef - Represent a constant reference to a string, i.e.
bool operator==(uint64_t V1, const APInt &V2)
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.
bool consumeSignedInteger(StringRef &Str, unsigned Radix, long long &Result)
OutputIt copy(R &&Range, OutputIt Out)
bool getAsSignedInteger(StringRef Str, unsigned Radix, long long &Result)
LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef(const char *Str)
Construct a string ref from a cstring.