25 if (x >=
'A' && x <=
'Z')
31 if (x >=
'a' && x <=
'z')
37 return x >=
'0' && x <=
'9';
43 for (
size_t I = 0;
I < Length; ++
I) {
47 return LHC < RHC ? -1 : 1;
56 if (Length == RHS.Length)
58 return Length < RHS.Length ? -1 : 1;
63 return Length >= Prefix.Length &&
69 return Length >= Suffix.Length &&
75 for (
size_t I = 0, E = min(Length, RHS.Length);
I != E; ++
I) {
81 for (J = I + 1; J != E + 1; ++J) {
90 if (
int Res = compareMemory(Data + I, RHS.Data + I, J - I))
91 return Res < 0 ? -1 : 1;
96 if (Data[I] != RHS.Data[I])
97 return (
unsigned char)Data[
I] < (
unsigned char)RHS.Data[I] ? -1 : 1;
99 if (Length == RHS.Length)
101 return Length < RHS.Length ? -1 : 1;
106 bool AllowReplacements,
107 unsigned MaxEditDistance)
const {
111 AllowReplacements, MaxEditDistance);
119 std::string Result(
size(),
char());
127 std::string Result(
size(),
char());
144 size_t N = Str.
size();
149 if (Length < 16 || N > 255 || N == 0) {
150 for (
size_t e = Length - N + 1, i = min(From, e); i != e; ++i)
160 uint8_t BadCharSkip[256];
162 for (
unsigned i = 0; i != N-1; ++i)
163 BadCharSkip[(uint8_t)Str[i]] = N-1-i;
165 unsigned Len = Length-From, Pos = From;
171 uint8_t Skip = BadCharSkip[(uint8_t)(*
this)[Pos+N-1]];
184 size_t N = Str.
size();
187 for (
size_t i = Length - N + 1, e = 0; i != e;) {
201 std::bitset<1 << CHAR_BIT> CharBits;
203 CharBits.set((
unsigned char)Chars[i]);
205 for (
size_type i = min(From, Length), e = Length; i != e; ++i)
206 if (CharBits.test((
unsigned char)Data[i]))
214 for (
size_type i = min(From, Length), e = Length; i != e; ++i)
226 std::bitset<1 << CHAR_BIT> CharBits;
228 CharBits.set((
unsigned char)Chars[i]);
230 for (
size_type i = min(From, Length), e = Length; i != e; ++i)
231 if (!CharBits.test((
unsigned char)Data[i]))
242 std::bitset<1 << CHAR_BIT> CharBits;
244 CharBits.set((
unsigned char)Chars[i]);
246 for (
size_type i = min(From, Length) - 1, e = -1; i != e; --i)
247 if (CharBits.test((
unsigned char)Data[i]))
255 for (
size_type i = min(From, Length) - 1, e = -1; i != e; --i)
267 std::bitset<1 << CHAR_BIT> CharBits;
269 CharBits.set((
unsigned char)Chars[i]);
271 for (
size_type i = min(From, Length) - 1, e = -1; i != e; --i)
272 if (!CharBits.test((
unsigned char)Data[i]))
279 bool KeepEmpty)
const {
285 rest.
data() != NULL && (MaxSplit < 0 || splits < MaxSplit);
287 std::pair<StringRef, StringRef> p = rest.
split(Separators);
289 if (KeepEmpty || p.first.size() != 0)
294 if (rest.
data() != NULL && (rest.
size() != 0 || KeepEmpty))
306 size_t N = Str.
size();
309 for (
size_t i = 0, e = Length - N + 1; i != e; ++i)
341 unsigned long long &Result) {
347 if (Str.
empty())
return true;
351 while (!Str.
empty()) {
353 if (Str[0] >=
'0' && Str[0] <=
'9')
354 CharVal = Str[0]-
'0';
355 else if (Str[0] >=
'a' && Str[0] <=
'z')
356 CharVal = Str[0]-
'a'+10;
357 else if (Str[0] >=
'A' && Str[0] <=
'Z')
358 CharVal = Str[0]-
'A'+10;
364 if (CharVal >= Radix)
368 unsigned long long PrevResult = Result;
369 Result = Result*Radix+CharVal;
372 if (Result/Radix < PrevResult)
383 unsigned long long ULLVal;
389 (
long long)ULLVal < 0)
400 (
long long)-ULLVal > 0)
414 assert(Radix > 1 && Radix <= 36);
417 if (Str.
empty())
return true;
426 Result =
APInt(64, 0);
431 unsigned Log2Radix = 0;
432 while ((1U << Log2Radix) < Radix) Log2Radix++;
433 bool IsPowerOf2Radix = ((1U << Log2Radix) == Radix);
435 unsigned BitWidth = Log2Radix * Str.
size();
439 Result = Result.
zext(BitWidth);
441 APInt RadixAP, CharAP;
442 if (!IsPowerOf2Radix) {
444 RadixAP =
APInt(BitWidth, Radix);
445 CharAP =
APInt(BitWidth, 0);
450 while (!Str.
empty()) {
452 if (Str[0] >=
'0' && Str[0] <=
'9')
453 CharVal = Str[0]-
'0';
454 else if (Str[0] >=
'a' && Str[0] <=
'z')
455 CharVal = Str[0]-
'a'+10;
456 else if (Str[0] >=
'A' && Str[0] <=
'Z')
457 CharVal = Str[0]-
'A'+10;
463 if (CharVal >= Radix)
467 if (IsPowerOf2Radix) {
468 Result <<= Log2Radix;
void push_back(const T &Elt)
int compare_lower(StringRef RHS) const
compare_lower - Compare two strings, ignoring case.
size_t size() const
size - Get the string size.
static char ascii_toupper(char x)
unsigned ComputeEditDistance(ArrayRef< T > FromArray, ArrayRef< T > ToArray, bool AllowReplacements=true, unsigned MaxEditDistance=0)
Determine the edit distance between two sequences.
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.
std::pair< StringRef, StringRef > split(char Separator) const
size_t rfind(char C, size_t From=npos) const
StringRef substr(size_t Start, size_t N=npos) const
bool endswith_lower(StringRef Suffix) const
Check if this string ends with the given Suffix, ignoring case.
This file implements a class to represent arbitrary precision integral constant values and operations...
const char * data() const
hash_code hash_value(const APFloat &Arg)
size_t find_last_not_of(char C, size_t From=npos) const
size_t count(char C) const
Return the number of occurrences of C in the string.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static int ascii_strncasecmp(const char *LHS, const char *RHS, size_t Length)
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.
size_t find_last_of(char C, size_t From=npos) const
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
std::string upper() const
Convert the given ASCII string to uppercase.
static char ascii_tolower(char x)
static unsigned GetAutoSenseRadix(StringRef &Str)
Class for arbitrary precision integers.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
An opaque object representing a hash code.
bool equals(StringRef RHS) const
size_t find_first_of(char C, size_t From=0) const
static bool ascii_isdigit(char x)
char front() const
front - Get the first character in the string.
int compare_numeric(StringRef RHS) const
compare_numeric - Compare strings, handle embedded numbers.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zext(unsigned width) const
Zero extend to a new width.
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)
bool empty() const
empty - Check if the string is empty.