LLVM 24.0.0git
StringRef.cpp
Go to the documentation of this file.
1//===-- StringRef.cpp - Lightweight String References ---------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "llvm/ADT/APFloat.h"
11#include "llvm/ADT/APInt.h"
12#include "llvm/ADT/Hashing.h"
15#include "llvm/Support/Error.h"
16#include <bitset>
17
18using namespace llvm;
19
20// strncasecmp() is not available on non-POSIX systems, so define an
21// alternative function here.
23 for (auto [LC, RC] : zip_equal(LHS, RHS)) {
24 unsigned char LHC = toLower(LC);
25 unsigned char RHC = toLower(RC);
26 if (LHC != RHC)
27 return LHC < RHC ? -1 : 1;
28 }
29 return 0;
30}
31
33 size_t Min = std::min(size(), RHS.size());
34 if (int Res = ascii_strncasecmp(take_front(Min), RHS.take_front(Min)))
35 return Res;
36 if (size() == RHS.size())
37 return 0;
38 return size() < RHS.size() ? -1 : 1;
39}
40
42 return size() >= Prefix.size() &&
43 ascii_strncasecmp(take_front(Prefix.size()), Prefix) == 0;
44}
45
47 return size() >= Suffix.size() &&
48 ascii_strncasecmp(take_back(Suffix.size()), Suffix) == 0;
49}
50
51size_t StringRef::find_insensitive(char C, size_t From) const {
52 char L = toLower(C);
53 return find_if([L](char D) { return toLower(D) == L; }, From);
54}
55
56/// compare_numeric - Compare strings, handle embedded numbers.
58 for (size_t I = 0, E = std::min(size(), RHS.size()); I != E; ++I) {
59 // Check for sequences of digits.
60 if (isDigit(data()[I]) && isDigit(RHS.data()[I])) {
61 // The longer sequence of numbers is considered larger.
62 // This doesn't really handle prefixed zeros well.
63 size_t J;
64 for (J = I + 1; J != E + 1; ++J) {
65 bool ld = J < size() && isDigit(data()[J]);
66 bool rd = J < RHS.size() && isDigit(RHS.data()[J]);
67 if (ld != rd)
68 return rd ? -1 : 1;
69 if (!rd)
70 break;
71 }
72 // The two number sequences have the same length (J-I), just memcmp them.
73 if (int Res = compareMemory(data() + I, RHS.data() + I, J - I))
74 return Res < 0 ? -1 : 1;
75 // Identical number sequences, continue search after the numbers.
76 I = J - 1;
77 continue;
78 }
79 if (data()[I] != RHS.data()[I])
80 return (unsigned char)data()[I] < (unsigned char)RHS.data()[I] ? -1 : 1;
81 }
82 if (size() == RHS.size())
83 return 0;
84 return size() < RHS.size() ? -1 : 1;
85}
86
87// Compute the edit distance between the two given strings.
89 bool AllowReplacements,
90 unsigned MaxEditDistance) const {
92 ArrayRef(Other.data(), Other.size()),
93 AllowReplacements, MaxEditDistance);
94}
95
97 StringRef Other, bool AllowReplacements, unsigned MaxEditDistance) const {
99 ArrayRef(data(), size()), ArrayRef(Other.data(), Other.size()),
100 llvm::toLower, AllowReplacements, MaxEditDistance);
101}
102
103//===----------------------------------------------------------------------===//
104// String Operations
105//===----------------------------------------------------------------------===//
106
107std::string StringRef::lower() const {
108 return std::string(map_iterator(begin(), toLower),
110}
111
112std::string StringRef::upper() const {
113 return std::string(map_iterator(begin(), toUpper),
115}
116
117//===----------------------------------------------------------------------===//
118// String Searching
119//===----------------------------------------------------------------------===//
120
121
122/// find - Search for the first string \arg Str in the string.
123///
124/// \return - The index of the first occurrence of \arg Str, or npos if not
125/// found.
126size_t StringRef::find(StringRef Str, size_t From) const {
127 if (From > size())
128 return npos;
129
130 const char *Start = data() + From;
131 size_t Size = size() - From;
132
133 const char *Needle = Str.data();
134 size_t N = Str.size();
135 if (N == 0)
136 return From;
137 if (Size < N)
138 return npos;
139 if (N == 1) {
140 const char *Ptr = (const char *)::memchr(Start, Needle[0], Size);
141 return Ptr == nullptr ? npos : Ptr - data();
142 }
143
144 const char *Stop = Start + (Size - N + 1);
145
146 if (N == 2) {
147 // Provide a fast path for newline finding (CRLF case) in InclusionRewriter.
148 // Not the most optimized strategy, but getting memcmp inlined should be
149 // good enough.
150 do {
151 if (std::memcmp(Start, Needle, 2) == 0)
152 return Start - data();
153 ++Start;
154 } while (Start < Stop);
155 return npos;
156 }
157
158 // For short haystacks or unsupported needles fall back to the naive algorithm
159 if (Size < 16 || N > 255) {
160 do {
161 if (std::memcmp(Start, Needle, N) == 0)
162 return Start - data();
163 ++Start;
164 } while (Start < Stop);
165 return npos;
166 }
167
168 // Build the bad char heuristic table, with uint8_t to reduce cache thrashing.
169 uint8_t BadCharSkip[256];
170 std::memset(BadCharSkip, N, 256);
171 for (unsigned i = 0; i != N-1; ++i)
172 BadCharSkip[(uint8_t)Str[i]] = N-1-i;
173
174 do {
175 uint8_t Last = Start[N - 1];
176 if (LLVM_UNLIKELY(Last == (uint8_t)Needle[N - 1]))
177 if (std::memcmp(Start, Needle, N - 1) == 0)
178 return Start - data();
179
180 // Otherwise skip the appropriate number of bytes.
181 Start += BadCharSkip[Last];
182 } while (Start < Stop);
183
184 return npos;
185}
186
187size_t StringRef::find_insensitive(StringRef Str, size_t From) const {
188 StringRef This = substr(From);
189 while (This.size() >= Str.size()) {
190 if (This.starts_with_insensitive(Str))
191 return From;
192 This = This.drop_front();
193 ++From;
194 }
195 return npos;
196}
197
198// Returns the index of the last C in Data[0, End), or npos if it is not found.
199// Written to be vectorizable.
201 size_t End, char C) {
202 constexpr size_t VectorWidth = 16;
203 size_t I = End;
204 for (; I >= VectorWidth; I -= VectorWidth) {
205 const char *Chunk = Data + I - VectorWidth;
206 unsigned char Any = 0;
207 for (size_t J = 0; J != VectorWidth; ++J)
208 Any |= Chunk[J] == C;
209 if (Any)
210 break;
211 }
212 while (I) {
213 --I;
214 if (Data[I] == C)
215 return I;
216 }
217 return StringRef::npos;
218}
219
220size_t StringRef::rfind(char C, size_t From) const {
221 return rfindByte(data(), std::min(From, size()), C);
222}
223
224size_t StringRef::rfind_insensitive(char C, size_t From) const {
225 From = std::min(From, size());
226 size_t i = From;
227 while (i != 0) {
228 --i;
229 if (toLower(data()[i]) == toLower(C))
230 return i;
231 }
232 return npos;
233}
234
235/// rfind - Search for the last string \arg Str in the string.
236///
237/// \return - The index of the last occurrence of \arg Str, or npos if not
238/// found.
239size_t StringRef::rfind(StringRef Str) const {
240 size_t N = Str.size();
241 if (N > size())
242 return npos;
243 if (N == 0)
244 return size();
245 for (size_t I = size() - N + 1; (I = rfindByte(data(), I, Str[0])) != npos;)
246 if (std::memcmp(data() + I + 1, Str.data() + 1, N - 1) == 0)
247 return I;
248 return npos;
249}
250
252 size_t N = Str.size();
253 if (N > size())
254 return npos;
255 for (size_t i = size() - N + 1, e = 0; i != e;) {
256 --i;
257 if (substr(i, N).equals_insensitive(Str))
258 return i;
259 }
260 return npos;
261}
262
263/// find_first_of - Find the first character in the string that is in \arg
264/// Chars, or npos if not found.
265///
266/// Note: O(size() + Chars.size())
268 size_t From) const {
269 std::bitset<1 << CHAR_BIT> CharBits;
270 for (char C : Chars)
271 CharBits.set((unsigned char)C);
272
273 for (size_type i = std::min(From, size()), e = size(); i != e; ++i)
274 if (CharBits.test((unsigned char)data()[i]))
275 return i;
276 return npos;
277}
278
279/// find_first_not_of - Find the first character in the string that is not
280/// \arg C or npos if not found.
282 return std::string_view(*this).find_first_not_of(C, From);
283}
284
285/// find_first_not_of - Find the first character in the string that is not
286/// in the string \arg Chars, or npos if not found.
287///
288/// Note: O(size() + Chars.size())
290 size_t From) const {
291 std::bitset<1 << CHAR_BIT> CharBits;
292 for (char C : Chars)
293 CharBits.set((unsigned char)C);
294
295 for (size_type i = std::min(From, size()), e = size(); i != e; ++i)
296 if (!CharBits.test((unsigned char)data()[i]))
297 return i;
298 return npos;
299}
300
301/// find_last_of - Find the last character in the string that is in \arg C,
302/// or npos if not found.
303///
304/// Note: O(size() + Chars.size())
306 size_t From) const {
307 std::bitset<1 << CHAR_BIT> CharBits;
308 for (char C : Chars)
309 CharBits.set((unsigned char)C);
310
311 for (size_type i = std::min(From, size()) - 1, e = -1; i != e; --i)
312 if (CharBits.test((unsigned char)data()[i]))
313 return i;
314 return npos;
315}
316
317/// find_last_not_of - Find the last character in the string that is not
318/// \arg C, or npos if not found.
320 for (size_type i = std::min(From, size()) - 1, e = -1; i != e; --i)
321 if (data()[i] != C)
322 return i;
323 return npos;
324}
325
326/// find_last_not_of - Find the last character in the string that is not in
327/// \arg Chars, or npos if not found.
328///
329/// Note: O(size() + Chars.size())
331 size_t From) const {
332 std::bitset<1 << CHAR_BIT> CharBits;
333 for (char C : Chars)
334 CharBits.set((unsigned char)C);
335
336 for (size_type i = std::min(From, size()) - 1, e = -1; i != e; --i)
337 if (!CharBits.test((unsigned char)data()[i]))
338 return i;
339 return npos;
340}
341
343 StringRef Separator, int MaxSplit,
344 bool KeepEmpty) const {
345 StringRef S = *this;
346
347 // Count down from MaxSplit. When MaxSplit is -1, this will just split
348 // "forever". This doesn't support splitting more than 2^31 times
349 // intentionally; if we ever want that we can make MaxSplit a 64-bit integer
350 // but that seems unlikely to be useful.
351 while (MaxSplit-- != 0) {
352 size_t Idx = S.find(Separator);
353 if (Idx == npos)
354 break;
355
356 // Push this split.
357 if (KeepEmpty || Idx > 0)
358 A.push_back(S.slice(0, Idx));
359
360 // Jump forward.
361 S = S.substr(Idx + Separator.size());
362 }
363
364 // Push the tail.
365 if (KeepEmpty || !S.empty())
366 A.push_back(S);
367}
368
370 int MaxSplit, bool KeepEmpty) const {
371 StringRef S = *this;
372
373 // Count down from MaxSplit. When MaxSplit is -1, this will just split
374 // "forever". This doesn't support splitting more than 2^31 times
375 // intentionally; if we ever want that we can make MaxSplit a 64-bit integer
376 // but that seems unlikely to be useful.
377 while (MaxSplit-- != 0) {
378 size_t Idx = S.find(Separator);
379 if (Idx == npos)
380 break;
381
382 // Push this split.
383 if (KeepEmpty || Idx > 0)
384 A.push_back(S.slice(0, Idx));
385
386 // Jump forward.
387 S = S.substr(Idx + 1);
388 }
389
390 // Push the tail.
391 if (KeepEmpty || !S.empty())
392 A.push_back(S);
393}
394
395//===----------------------------------------------------------------------===//
396// Helpful Algorithms
397//===----------------------------------------------------------------------===//
398
399/// count - Return the number of non-overlapped occurrences of \arg Str in
400/// the string.
401size_t StringRef::count(StringRef Str) const {
402 size_t Count = 0;
403 size_t Pos = 0;
404 size_t N = Str.size();
405 // TODO: For an empty `Str` we return 0 for legacy reasons. Consider changing
406 // this to `Length + 1` which is more in-line with the function
407 // description.
408 if (!N)
409 return 0;
410 while ((Pos = find(Str, Pos)) != npos) {
411 ++Count;
412 Pos += N;
413 }
414 return Count;
415}
416
418 if (Str.empty())
419 return 10;
420
421 if (Str.consume_front_insensitive("0x"))
422 return 16;
423
424 if (Str.consume_front_insensitive("0b"))
425 return 2;
426
427 if (Str.consume_front("0o"))
428 return 8;
429
430 if (Str[0] == '0' && Str.size() > 1 && isDigit(Str[1])) {
431 Str = Str.substr(1);
432 return 8;
433 }
434
435 return 10;
436}
437
438bool llvm::consumeUnsignedInteger(StringRef &Str, unsigned Radix,
439 unsigned long long &Result) {
440 // Autosense radix if not specified.
441 if (Radix == 0)
442 Radix = getAutoSenseRadix(Str);
443
444 // Empty strings (after the radix autosense) are invalid.
445 if (Str.empty()) return true;
446
447 // Parse all the bytes of the string given this radix. Watch for overflow.
448 StringRef Str2 = Str;
449 Result = 0;
450 while (!Str2.empty()) {
451 unsigned CharVal;
452 if (Str2[0] >= '0' && Str2[0] <= '9')
453 CharVal = Str2[0] - '0';
454 else if (Str2[0] >= 'a' && Str2[0] <= 'z')
455 CharVal = Str2[0] - 'a' + 10;
456 else if (Str2[0] >= 'A' && Str2[0] <= 'Z')
457 CharVal = Str2[0] - 'A' + 10;
458 else
459 break;
460
461 // If the parsed value is larger than the integer radix, we cannot
462 // consume any more characters.
463 if (CharVal >= Radix)
464 break;
465
466 // Add in this character.
467 unsigned long long PrevResult = Result;
468 Result = Result * Radix + CharVal;
469
470 // Check for overflow by shifting back and seeing if bits were lost.
471 if (Result / Radix < PrevResult)
472 return true;
473
474 Str2 = Str2.substr(1);
475 }
476
477 // We consider the operation a failure if no characters were consumed
478 // successfully.
479 if (Str.size() == Str2.size())
480 return true;
481
482 Str = Str2;
483 return false;
484}
485
486bool llvm::consumeSignedInteger(StringRef &Str, unsigned Radix,
487 long long &Result) {
488 unsigned long long ULLVal;
489
490 // Handle positive strings first.
491 if (!Str.starts_with("-")) {
492 if (consumeUnsignedInteger(Str, Radix, ULLVal) ||
493 // Check for value so large it overflows a signed value.
494 (long long)ULLVal < 0)
495 return true;
496 Result = ULLVal;
497 return false;
498 }
499
500 // Get the positive part of the value.
501 StringRef Str2 = Str.drop_front(1);
502 if (consumeUnsignedInteger(Str2, Radix, ULLVal) ||
503 // Reject values so large they'd overflow as negative signed, but allow
504 // "-0". This negates the unsigned so that the negative isn't undefined
505 // on signed overflow.
506 (long long)-ULLVal > 0)
507 return true;
508
509 Str = Str2;
510 Result = -ULLVal;
511 return false;
512}
513
514/// GetAsUnsignedInteger - Workhorse method that converts a integer character
515/// sequence of radix up to 36 to an unsigned long long value.
516bool llvm::getAsUnsignedInteger(StringRef Str, unsigned Radix,
517 unsigned long long &Result) {
518 if (consumeUnsignedInteger(Str, Radix, Result))
519 return true;
520
521 // For getAsUnsignedInteger, we require the whole string to be consumed or
522 // else we consider it a failure.
523 return !Str.empty();
524}
525
526bool llvm::getAsSignedInteger(StringRef Str, unsigned Radix,
527 long long &Result) {
528 if (consumeSignedInteger(Str, Radix, Result))
529 return true;
530
531 // For getAsSignedInteger, we require the whole string to be consumed or else
532 // we consider it a failure.
533 return !Str.empty();
534}
535
536bool StringRef::consumeInteger(unsigned Radix, APInt &Result) {
537 StringRef Str = *this;
538
539 // Autosense radix if not specified.
540 if (Radix == 0)
541 Radix = getAutoSenseRadix(Str);
542
543 assert(Radix > 1 && Radix <= 36);
544
545 // Empty strings (after the radix autosense) are invalid.
546 if (Str.empty()) return true;
547
548 // Skip leading zeroes. This can be a significant improvement if
549 // it means we don't need > 64 bits.
550 Str = Str.ltrim('0');
551
552 // If it was nothing but zeroes....
553 if (Str.empty()) {
554 Result = APInt(64, 0);
555 *this = Str;
556 return false;
557 }
558
559 unsigned Log2Radix = 0;
560 while ((1U << Log2Radix) < Radix) Log2Radix++;
561 bool IsPowerOf2Radix = ((1U << Log2Radix) == Radix);
562
563 // Initialize Result to a reasonable starting width (at least 64 bits),
564 // but do not shrink it if it was already larger.
565 unsigned BitWidth = std::max(64U, Result.getBitWidth());
566
567 if (Result.getBitWidth() < BitWidth) {
568 Result = Result.zext(BitWidth);
569 }
570
571 APInt RadixAP, CharAP; // unused unless !IsPowerOf2Radix
572 if (!IsPowerOf2Radix) {
573 // These must have the same bit-width as Result.
574 RadixAP = APInt(BitWidth, Radix);
575 CharAP = APInt(BitWidth, 0);
576 }
577
578 // Parse all the bytes of the string given this radix.
579 Result = 0;
580 while (!Str.empty()) {
581 unsigned CharVal;
582 if (Str[0] >= '0' && Str[0] <= '9')
583 CharVal = Str[0]-'0';
584 else if (Str[0] >= 'a' && Str[0] <= 'z')
585 CharVal = Str[0]-'a'+10;
586 else if (Str[0] >= 'A' && Str[0] <= 'Z')
587 CharVal = Str[0]-'A'+10;
588 else
589 break;
590
591 // If the parsed value is larger than the integer radix, the string is
592 // invalid.
593 if (CharVal >= Radix)
594 break;
595
596 // Check if one more digit will overflow, and grow if so.
597 if (Result.getActiveBits() + Log2Radix > Result.getBitWidth()) {
598 unsigned NewWidth = Result.getBitWidth() * 2;
599
600 // Guard against overflow of the NewWidth itself
601 if (NewWidth < Result.getBitWidth())
602 return true;
603
604 Result = Result.zext(NewWidth);
605 if (!IsPowerOf2Radix) {
606 RadixAP = RadixAP.zext(NewWidth);
607 CharAP = CharAP.zext(NewWidth);
608 }
609 }
610
611 // Add in this character.
612 if (IsPowerOf2Radix) {
613 Result <<= Log2Radix;
614 Result |= CharVal;
615 } else {
616 Result *= RadixAP;
617 CharAP = CharVal;
618 Result += CharAP;
619 }
620
621 Str = Str.substr(1);
622 }
623
624 // We consider the operation a failure if no characters were consumed
625 // successfully.
626 if (size() == Str.size())
627 return true;
628
629 *this = Str;
630 return false;
631}
632
633bool StringRef::getAsInteger(unsigned Radix, APInt &Result) const {
634 StringRef Str = *this;
635 if (Str.consumeInteger(Radix, Result))
636 return true;
637
638 // For getAsInteger, we require the whole string to be consumed or else we
639 // consider it a failure.
640 return !Str.empty();
641}
642
643bool StringRef::getAsDouble(double &Result, bool AllowInexact) const {
644 APFloat F(0.0);
645 auto StatusOrErr = F.convertFromString(*this, APFloat::rmNearestTiesToEven);
646 if (errorToBool(StatusOrErr.takeError()))
647 return true;
648
649 APFloat::opStatus Status = *StatusOrErr;
650 if (Status != APFloat::opOK) {
651 if (!AllowInexact || !(Status & APFloat::opInexact))
652 return true;
653 }
654
655 Result = F.convertToDouble();
656 return false;
657}
658
659// Implementation of StringRef hashing.
661
663 return (unsigned)(hash_value(Val));
664}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_UNLIKELY(EXPR)
Definition Compiler.h:348
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
Definition Compiler.h:376
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file contains some functions that are useful when dealing with strings.
static int ascii_strncasecmp(StringRef LHS, StringRef RHS)
Definition StringRef.cpp:22
static LLVM_ATTRIBUTE_ALWAYS_INLINE size_t rfindByte(const char *Data, size_t End, char C)
Value * RHS
Value * LHS
static constexpr roundingMode rmNearestTiesToEven
Definition APFloat.h:361
opStatus
IEEE-754R 7: Default exception handling.
Definition APFloat.h:377
Class for arbitrary precision integers.
Definition APInt.h:78
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
Definition APInt.cpp:1057
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:728
LLVM_ABI 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.
static constexpr size_t npos
Definition StringRef.h:58
bool consumeInteger(unsigned Radix, T &Result)
Parse the current string as an integer of the specified radix.
Definition StringRef.h:511
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition StringRef.h:482
LLVM_ABI bool getAsDouble(double &Result, bool AllowInexact=true) const
Parse the current string as an IEEE double-precision floating point value.
size_t find_if(function_ref< bool(char)> F, size_t From=0) const
Search for the first character satisfying the predicate F.
Definition StringRef.h:304
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:589
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
LLVM_ABI size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
LLVM_ABI bool starts_with_insensitive(StringRef Prefix) const
Check if this string starts with the given Prefix, ignoring case.
Definition StringRef.cpp:41
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition StringRef.h:627
iterator begin() const
Definition StringRef.h:114
LLVM_ABI std::string upper() const
Convert the given ASCII string to uppercase.
LLVM_ABI unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
Definition StringRef.cpp:88
size_t size_type
Definition StringRef.h:62
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Definition StringRef.h:712
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
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.
Definition StringRef.h:413
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
LLVM_ABI int compare_numeric(StringRef RHS) const
Compare two strings, treating sequences of digits as numbers.
Definition StringRef.cpp:57
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.
Definition StringRef.h:388
StringRef()=default
Construct an empty string ref.
iterator end() const
Definition StringRef.h:116
StringRef take_back(size_t N=1) const
Return a StringRef equal to 'this' but with only the last N elements remaining.
Definition StringRef.h:607
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
Definition StringRef.h:598
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition StringRef.h:290
LLVM_ABI size_t rfind_insensitive(char C, size_t From=npos) const
Search for the last character C in the string, ignoring case.
LLVM_ABI std::string lower() const
LLVM_ABI size_t find_insensitive(char C, size_t From=0) const
Search for the first character C in the string, ignoring case.
Definition StringRef.cpp:51
size_t count(char C) const
Return the number of occurrences of C in the string.
Definition StringRef.h:463
bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
Definition StringRef.h:170
LLVM_ABI bool ends_with_insensitive(StringRef Suffix) const
Check if this string ends with the given Suffix, ignoring case.
Definition StringRef.cpp:46
LLVM_ABI 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_ABI int compare_insensitive(StringRef RHS) const
Compare two strings, ignoring case.
Definition StringRef.cpp:32
LLVM_ABI unsigned edit_distance_insensitive(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Definition StringRef.cpp:96
An opaque object representing a hash code.
Definition Hashing.h:77
This file defines a Levenshtein distance function that works for any two sequences,...
This is an optimization pass for GlobalISel generic memory operations.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
Definition Error.h:1129
char toLower(char x)
Returns the corresponding lowercase character if x is uppercase.
LLVM_ABI bool getAsSignedInteger(StringRef Str, unsigned Radix, long long &Result)
hash_code hash_value(const FixedPointSemantics &Val)
LLVM_ABI unsigned getAutoSenseRadix(StringRef &Str)
detail::zippy< detail::zip_first, T, U, Args... > zip_equal(T &&t, U &&u, Args &&...args)
zip iterator that assumes that all iteratees have the same length.
Definition STLExtras.h:856
mapped_iterator< ItTy, FuncTy > map_iterator(ItTy I, FuncTy F)
Definition STLExtras.h:359
LLVM_ABI bool consumeUnsignedInteger(StringRef &Str, unsigned Radix, unsigned long long &Result)
unsigned ComputeEditDistance(ArrayRef< T > FromArray, ArrayRef< T > ToArray, bool AllowReplacements=true, unsigned MaxEditDistance=0)
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
@ Other
Any other memory.
Definition ModRef.h:68
char toUpper(char x)
Returns the corresponding uppercase character if x is lowercase.
LLVM_ABI bool consumeSignedInteger(StringRef &Str, unsigned Radix, long long &Result)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr unsigned BitWidth
LLVM_ABI bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
unsigned ComputeMappedEditDistance(ArrayRef< T > FromArray, ArrayRef< T > ToArray, Functor Map, bool AllowReplacements=true, unsigned MaxEditDistance=0)
Determine the edit distance between two sequences.
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition Hashing.h:287
#define N
An information struct used to provide DenseMap with the various necessary components for a given valu...