10 #ifndef LLVM_ADT_STRINGREF_H
11 #define LLVM_ADT_STRINGREF_H
23 class SmallVectorImpl;
30 unsigned long long &Result);
45 static const size_t npos = ~size_t(0);
58 static size_t min(
size_t a,
size_t b) {
return a < b ? a : b; }
59 static size_t max(
size_t a,
size_t b) {
return a > b ? a : b; }
63 static int compareMemory(
const char *Lhs,
const char *Rhs,
size_t Length) {
64 if (Length == 0) {
return 0; }
78 assert(Str &&
"StringRef cannot be built from a NULL argument");
84 : Data(data), Length(length) {
85 assert((data || length == 0) &&
86 "StringRef cannot be built from a NULL argument with non-null length");
91 : Data(Str.
data()), Length(Str.length()) {}
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];
130 return (Length == RHS.Length &&
131 compareMemory(Data, RHS.Data, RHS.Length) == 0);
143 if (
int Res = compareMemory(Data, RHS.Data, min(Length, RHS.Length)))
144 return Res < 0 ? -1 : 1;
147 if (Length == RHS.Length)
149 return Length < RHS.Length ? -1 : 1;
178 unsigned MaxEditDistance = 0)
const;
182 if (Data == 0)
return std::string();
183 return std::string(Data, Length);
191 assert(Index < Length &&
"Invalid index!");
199 operator std::string()
const {
209 return Length >= Prefix.Length &&
210 compareMemory(Data, Prefix.Data, Prefix.Length) == 0;
218 return Length >= Suffix.Length &&
219 compareMemory(
end() - Suffix.Length, Suffix.Data, Suffix.Length) == 0;
233 size_t find(
char C,
size_t From = 0)
const {
234 for (
size_t i = min(From, Length), e = Length; i != e; ++i)
251 From = min(From, Length);
270 return find(C, From);
292 return rfind(C, From);
318 for (
size_t i = 0, e = Length; i != e; ++i)
335 template <
typename T>
340 static_cast<T>(LLVal) != LLVal)
346 template <
typename T>
349 unsigned long long ULLVal;
351 static_cast<T>(ULLVal) != ULLVal)
374 std::string
lower()
const;
377 std::string
upper()
const;
393 Start = min(Start, Length);
394 return StringRef(Data + Start, min(
N, Length - Start));
400 assert(
size() >=
N &&
"Dropping more elements than exist");
407 assert(
size() >=
N &&
"Dropping more elements than exist");
422 Start = min(Start, Length);
423 End = min(max(Start, End), Length);
424 return StringRef(Data + Start, End - Start);
437 std::pair<StringRef, StringRef>
split(
char Separator)
const {
438 size_t Idx =
find(Separator);
440 return std::make_pair(*
this,
StringRef());
455 size_t Idx =
find(Separator);
457 return std::make_pair(*
this,
StringRef());
477 bool KeepEmpty =
true)
const;
489 std::pair<StringRef, StringRef>
rsplit(
char Separator)
const {
490 size_t Idx =
rfind(Separator);
492 return std::make_pair(*
this,
StringRef());
525 return !(LHS == RHS);
545 return buffer.append(
string.data(),
string.size());
554 template <
typename T>
struct isPodLike;
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
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
std::pair< StringRef, StringRef > split(char Separator) const
void operator>(const Optional< T > &X, const Optional< U > &Y)
Poison comparison between two Optional objects. Clients needs to explicitly compare the underlying va...
size_t rfind(char C, size_t From=npos) const
StringRef substr(size_t Start, size_t N=npos) const
void operator<(const Optional< T > &X, const Optional< U > &Y)
Poison comparison between two Optional objects. Clients needs to explicitly compare the underlying va...
std::string str() const
str - Get the contents as an std::string.
StringRef drop_back(size_t N=1) const
std::pair< StringRef, StringRef > rsplit(char Separator) const
bool endswith_lower(StringRef Suffix) const
Check if this string ends with the given Suffix, ignoring case.
int compare(StringRef RHS) const
StringRef rtrim(StringRef Chars=" \t\n\v\f\r") const
const char * data() const
hash_code hash_value(const APFloat &Arg)
StringRef()
Construct an empty string ref.
size_t find_last_not_of(char C, size_t From=npos) const
void operator<=(const Optional< T > &X, const Optional< U > &Y)
Poison comparison between two Optional objects. Clients needs to explicitly compare the underlying va...
int memcmp(const void *s1, const void *s2, size_t n);
StringRef trim(StringRef Chars=" \t\n\v\f\r") const
enable_if_c<!std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
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
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
enable_if_c< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
size_t find_first_not_of(char C, size_t From=0) const
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
const char * const_iterator
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
StringRef drop_front(size_t N=1) const
std::string upper() const
Convert the given ASCII string to uppercase.
char operator[](size_t Index) const
void operator>=(const Optional< T > &X, const Optional< U > &Y)
Poison comparison between two Optional objects. Clients needs to explicitly compare the underlying va...
size_t strlen(const char *s);
Class for arbitrary precision integers.
bool equals(StringRef RHS) const
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
char front() const
front - Get the first character in the string.
int compare_numeric(StringRef RHS) const
compare_numeric - Compare strings, handle embedded numbers.
StringRef slice(size_t Start, size_t End) const
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
bool empty() const
empty - Check if the string is empty.