10 #ifndef LLVM_ADT_STRINGREF_H
11 #define LLVM_ADT_STRINGREF_H
22 class SmallVectorImpl;
29 unsigned long long &Result);
44 static const size_t npos = ~size_t(0);
56 static int compareMemory(
const char *Lhs,
const char *Rhs,
size_t Length) {
57 if (Length == 0) {
return 0; }
58 return ::memcmp(Lhs,Rhs,Length);
71 assert(Str &&
"StringRef cannot be built from a NULL argument");
72 Length = ::strlen(Str);
77 : Data(data), Length(length) {
78 assert((data || length == 0) &&
79 "StringRef cannot be built from a NULL argument with non-null length");
84 : Data(Str.
data()), Length(Str.length()) {}
95 return reinterpret_cast<const unsigned char *
>(
begin());
98 return reinterpret_cast<const unsigned char *
>(
end());
107 const char *
data()
const {
return Data; }
110 bool empty()
const {
return Length == 0; }
113 size_t size()
const {
return Length; }
124 return Data[Length-1];
129 char *S = A.template Allocate<char>(Length);
137 return (Length == RHS.Length &&
138 compareMemory(Data, RHS.Data, RHS.Length) == 0);
150 if (
int Res = compareMemory(Data, RHS.Data,
std::min(Length, RHS.Length)))
151 return Res < 0 ? -1 : 1;
154 if (Length == RHS.Length)
156 return Length < RHS.Length ? -1 : 1;
185 unsigned MaxEditDistance = 0)
const;
189 if (!Data)
return std::string();
190 return std::string(Data, Length);
198 assert(Index < Length &&
"Invalid index!");
206 operator std::string()
const {
216 return Length >= Prefix.Length &&
217 compareMemory(Data, Prefix.Data, Prefix.Length) == 0;
225 return Length >= Suffix.Length &&
226 compareMemory(
end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0;
240 size_t find(
char C,
size_t From = 0)
const {
241 size_t FindBegin =
std::min(From, Length);
242 if (FindBegin < Length) {
244 if (
const void *
P = ::memchr(Data + FindBegin, C, Length - FindBegin))
245 return static_cast<const char *
>(
P) - Data;
280 return find(C, From);
302 return rfind(C, From);
328 for (
size_t i = 0, e = Length; i != e; ++i)
345 template <
typename T>
346 typename std::enable_if<std::numeric_limits<T>::is_signed,
bool>::type
350 static_cast<T>(LLVal) != LLVal)
356 template <
typename T>
357 typename std::enable_if<!std::numeric_limits<T>::is_signed,
bool>::type
359 unsigned long long ULLVal;
364 static_cast<unsigned long long>(static_cast<T>(ULLVal)) != ULLVal)
387 std::string
lower()
const;
390 std::string
upper()
const;
413 assert(
size() >=
N &&
"Dropping more elements than exist");
420 assert(
size() >=
N &&
"Dropping more elements than exist");
436 End =
std::min(std::max(Start, End), Length);
437 return StringRef(Data + Start, End - Start);
450 std::pair<StringRef, StringRef>
split(
char Separator)
const {
451 size_t Idx =
find(Separator);
453 return std::make_pair(*
this,
StringRef());
468 size_t Idx =
find(Separator);
470 return std::make_pair(*
this,
StringRef());
490 bool KeepEmpty =
true)
const;
502 std::pair<StringRef, StringRef>
rsplit(
char Separator)
const {
503 size_t Idx =
rfind(Separator);
505 return std::make_pair(*
this,
StringRef());
538 return !(LHS == RHS);
558 return buffer.append(
string.data(),
string.
size());
567 template <
typename T>
struct isPodLike;
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.
std::string & operator+=(std::string &buffer, StringRef string)
int compare_lower(StringRef RHS) const
compare_lower - Compare two strings, ignoring case.
size_t size() const
size - Get the string size.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
bool operator>(int64_t V1, const APSInt &V2)
bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
const unsigned char * bytes_end() const
std::string str() const
str - Get the contents as an std::string.
StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
std::pair< StringRef, StringRef > rsplit(char Separator) const
Split into two substrings around the last occurrence of a separator character.
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)
int compare(StringRef RHS) const
compare - Compare two strings; the result is -1, 0, or 1 if this string is lexicographically less tha...
StringRef rtrim(StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the right removed.
bool operator>=(int64_t V1, const APSInt &V2)
StringRef copy(Allocator &A) const
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
StringRef()
Construct an empty string ref.
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.
StringRef trim(StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the left and right removed...
char back() const
back - Get the last character in the string.
size_t count(char C) const
Return the number of occurrences of C in the string.
StringRef(const char *data, size_t length)
Construct a string ref from a pointer and length.
std::pair< StringRef, StringRef > split(StringRef Separator) const
Split into two substrings around the first occurrence of a separator string.
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.
unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
StringRef(const std::string &Str)
Construct a string ref from an std::string.
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.
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
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
std::string upper() const
Convert the given ASCII string to uppercase.
char operator[](size_t Index) const
Class for arbitrary precision integers.
bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
bool operator!=(uint64_t V1, const APInt &V2)
bool equals_lower(StringRef RHS) const
equals_lower - Check for string equality, ignoring case.
StringRef(const char *Str)
Construct a string ref from a cstring.
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.
char front() const
front - Get the first character in the string.
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)
StringRef - Represent a constant reference to a string, i.e.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
bool operator==(uint64_t V1, const APInt &V2)
bool startswith_lower(StringRef Prefix) const
Check if this string starts with the given Prefix, ignoring case.
std::string lower() const
bool getAsSignedInteger(StringRef Str, unsigned Radix, long long &Result)
StringRef ltrim(StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the left removed.
bool empty() const
empty - Check if the string is empty.