LLVM 22.0.0git
StringExtras.h
Go to the documentation of this file.
1//===- llvm/ADT/StringExtras.h - Useful string functions --------*- C++ -*-===//
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///
9/// \file
10/// This file contains some functions that are useful when dealing with strings.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ADT_STRINGEXTRAS_H
15#define LLVM_ADT_STRINGEXTRAS_H
16
17#include "llvm/ADT/APSInt.h"
18#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/ADT/Twine.h"
23#include <cassert>
24#include <cstddef>
25#include <cstdint>
26#include <cstdlib>
27#include <cstring>
28#include <iterator>
29#include <string>
30#include <utility>
31
32namespace llvm {
33
34class raw_ostream;
35
36/// hexdigit - Return the hexadecimal character for the
37/// given number \p X (which should be less than 16).
38inline char hexdigit(unsigned X, bool LowerCase = false) {
39 assert(X < 16);
40 static const char LUT[] = "0123456789ABCDEF";
41 const uint8_t Offset = LowerCase ? 32 : 0;
42 return LUT[X] | Offset;
43}
44
45/// Given an array of c-style strings terminated by a null pointer, construct
46/// a vector of StringRefs representing the same strings without the terminating
47/// null string.
48inline std::vector<StringRef> toStringRefArray(const char *const *Strings) {
49 std::vector<StringRef> Result;
50 while (*Strings)
51 Result.push_back(*Strings++);
52 return Result;
53}
54
55/// Construct a string ref from a boolean.
56inline StringRef toStringRef(bool B) { return StringRef(B ? "true" : "false"); }
57
58/// Construct a string ref from an array ref of unsigned chars.
60 return StringRef(reinterpret_cast<const char *>(Input.begin()), Input.size());
61}
63 return StringRef(Input.begin(), Input.size());
64}
65
66/// Construct a string ref from an array ref of unsigned chars.
67template <class CharT = uint8_t>
69 static_assert(std::is_same<CharT, char>::value ||
70 std::is_same<CharT, unsigned char>::value ||
71 std::is_same<CharT, signed char>::value,
72 "Expected byte type");
73 return ArrayRef<CharT>(reinterpret_cast<const CharT *>(Input.data()),
74 Input.size());
75}
76
77/// Interpret the given character \p C as a hexadecimal digit and return its
78/// value.
79///
80/// If \p C is not a valid hex digit, -1U is returned.
81inline unsigned hexDigitValue(char C) {
82 /* clang-format off */
83 static const int16_t LUT[256] = {
84 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
85 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
86 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
87 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, // '0'..'9'
88 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 'A'..'F'
89 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
90 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 'a'..'f'
91 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
92 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
93 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
94 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
95 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
96 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
97 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
98 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
99 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
100 };
101 /* clang-format on */
102 return LUT[static_cast<unsigned char>(C)];
103}
104
105/// Checks if character \p C is one of the 10 decimal digits.
106inline bool isDigit(char C) { return C >= '0' && C <= '9'; }
107
108/// Checks if character \p C is a hexadecimal numeric character.
109inline bool isHexDigit(char C) { return hexDigitValue(C) != ~0U; }
110
111/// Checks if character \p C is a lowercase letter as classified by "C" locale.
112inline bool isLower(char C) { return 'a' <= C && C <= 'z'; }
113
114/// Checks if character \p C is a uppercase letter as classified by "C" locale.
115inline bool isUpper(char C) { return 'A' <= C && C <= 'Z'; }
116
117/// Checks if character \p C is a valid letter as classified by "C" locale.
118inline bool isAlpha(char C) { return isLower(C) || isUpper(C); }
119
120/// Checks whether character \p C is either a decimal digit or an uppercase or
121/// lowercase letter as classified by "C" locale.
122inline bool isAlnum(char C) { return isAlpha(C) || isDigit(C); }
123
124/// Checks whether character \p C is valid ASCII (high bit is zero).
125inline bool isASCII(char C) { return static_cast<unsigned char>(C) <= 127; }
126
127/// Checks whether all characters in S are ASCII.
128inline bool isASCII(llvm::StringRef S) {
129 for (char C : S)
130 if (LLVM_UNLIKELY(!isASCII(C)))
131 return false;
132 return true;
133}
134
135/// Checks whether character \p C is printable.
136///
137/// Locale-independent version of the C standard library isprint whose results
138/// may differ on different platforms.
139inline bool isPrint(char C) {
140 unsigned char UC = static_cast<unsigned char>(C);
141 return (0x20 <= UC) && (UC <= 0x7E);
142}
143
144/// Checks whether character \p C is a punctuation character.
145///
146/// Locale-independent version of the C standard library ispunct. The list of
147/// punctuation characters can be found in the documentation of std::ispunct:
148/// https://en.cppreference.com/w/cpp/string/byte/ispunct.
149inline bool isPunct(char C) {
150 static constexpr StringLiteral Punctuations =
151 R"(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)";
152 return Punctuations.contains(C);
153}
154
155/// Checks whether character \p C is whitespace in the "C" locale.
156///
157/// Locale-independent version of the C standard library isspace.
158inline bool isSpace(char C) {
159 return C == ' ' || C == '\f' || C == '\n' || C == '\r' || C == '\t' ||
160 C == '\v';
161}
162
163/// Returns the corresponding lowercase character if \p x is uppercase.
164inline char toLower(char x) {
165 if (isUpper(x))
166 return x - 'A' + 'a';
167 return x;
168}
169
170/// Returns the corresponding uppercase character if \p x is lowercase.
171inline char toUpper(char x) {
172 if (isLower(x))
173 return x - 'a' + 'A';
174 return x;
175}
176
177inline std::string utohexstr(uint64_t X, bool LowerCase = false,
178 unsigned Width = 0) {
179 char Buffer[17];
180 char *BufPtr = std::end(Buffer);
181
182 if (X == 0 && !Width)
183 *--BufPtr = '0';
184
185 for (unsigned i = 0; Width ? (i < Width) : X; ++i) {
186 unsigned char Mod = static_cast<unsigned char>(X) & 15;
187 *--BufPtr = hexdigit(Mod, LowerCase);
188 X >>= 4;
189 }
190
191 return std::string(BufPtr, std::end(Buffer));
192}
193
194/// Convert buffer \p Input to its hexadecimal representation.
195/// The returned string is double the size of \p Input.
196inline void toHex(ArrayRef<uint8_t> Input, bool LowerCase,
197 SmallVectorImpl<char> &Output) {
198 const size_t Length = Input.size();
199 Output.resize_for_overwrite(Length * 2);
200
201 for (size_t i = 0; i < Length; i++) {
202 const uint8_t c = Input[i];
203 Output[i * 2 ] = hexdigit(c >> 4, LowerCase);
204 Output[i * 2 + 1] = hexdigit(c & 15, LowerCase);
205 }
206}
207
208inline std::string toHex(ArrayRef<uint8_t> Input, bool LowerCase = false) {
209 SmallString<16> Output;
210 toHex(Input, LowerCase, Output);
211 return std::string(Output);
212}
213
214inline std::string toHex(StringRef Input, bool LowerCase = false) {
215 return toHex(arrayRefFromStringRef(Input), LowerCase);
216}
217
218/// Store the binary representation of the two provided values, \p MSB and
219/// \p LSB, that make up the nibbles of a hexadecimal digit. If \p MSB or \p LSB
220/// do not correspond to proper nibbles of a hexadecimal digit, this method
221/// returns false. Otherwise, returns true.
222inline bool tryGetHexFromNibbles(char MSB, char LSB, uint8_t &Hex) {
223 unsigned U1 = hexDigitValue(MSB);
224 unsigned U2 = hexDigitValue(LSB);
225 if (U1 == ~0U || U2 == ~0U)
226 return false;
227
228 Hex = static_cast<uint8_t>((U1 << 4) | U2);
229 return true;
230}
231
232/// Return the binary representation of the two provided values, \p MSB and
233/// \p LSB, that make up the nibbles of a hexadecimal digit.
234inline uint8_t hexFromNibbles(char MSB, char LSB) {
235 uint8_t Hex = 0;
236 bool GotHex = tryGetHexFromNibbles(MSB, LSB, Hex);
237 (void)GotHex;
238 assert(GotHex && "MSB and/or LSB do not correspond to hex digits");
239 return Hex;
240}
241
242/// Convert hexadecimal string \p Input to its binary representation and store
243/// the result in \p Output. Returns true if the binary representation could be
244/// converted from the hexadecimal string. Returns false if \p Input contains
245/// non-hexadecimal digits. The output string is half the size of \p Input.
246inline bool tryGetFromHex(StringRef Input, std::string &Output) {
247 if (Input.empty())
248 return true;
249
250 // If the input string is not properly aligned on 2 nibbles we pad out the
251 // front with a 0 prefix; e.g. `ABC` -> `0ABC`.
252 Output.resize((Input.size() + 1) / 2);
253 char *OutputPtr = const_cast<char *>(Output.data());
254 if (Input.size() % 2 == 1) {
255 uint8_t Hex = 0;
256 if (!tryGetHexFromNibbles('0', Input.front(), Hex))
257 return false;
258 *OutputPtr++ = Hex;
259 Input = Input.drop_front();
260 }
261
262 // Convert the nibble pairs (e.g. `9C`) into bytes (0x9C).
263 // With the padding above we know the input is aligned and the output expects
264 // exactly half as many bytes as nibbles in the input.
265 size_t InputSize = Input.size();
266 assert(InputSize % 2 == 0);
267 const char *InputPtr = Input.data();
268 for (size_t OutputIndex = 0; OutputIndex < InputSize / 2; ++OutputIndex) {
269 uint8_t Hex = 0;
270 if (!tryGetHexFromNibbles(InputPtr[OutputIndex * 2 + 0], // MSB
271 InputPtr[OutputIndex * 2 + 1], // LSB
272 Hex))
273 return false;
274 OutputPtr[OutputIndex] = Hex;
275 }
276 return true;
277}
278
279/// Convert hexadecimal string \p Input to its binary representation.
280/// The return string is half the size of \p Input.
281inline std::string fromHex(StringRef Input) {
282 std::string Hex;
283 bool GotHex = tryGetFromHex(Input, Hex);
284 (void)GotHex;
285 assert(GotHex && "Input contains non hex digits");
286 return Hex;
287}
288
289/// Convert the string \p S to an integer of the specified type using
290/// the radix \p Base. If \p Base is 0, auto-detects the radix.
291/// Returns true if the number was successfully converted, false otherwise.
292template <typename N> bool to_integer(StringRef S, N &Num, unsigned Base = 0) {
293 return !S.getAsInteger(Base, Num);
294}
295
296namespace detail {
297template <typename N>
298inline bool to_float(const Twine &T, N &Num, N (*StrTo)(const char *, char **)) {
299 SmallString<32> Storage;
300 StringRef S = T.toNullTerminatedStringRef(Storage);
301 char *End;
302 N Temp = StrTo(S.data(), &End);
303 if (*End != '\0')
304 return false;
305 Num = Temp;
306 return true;
307}
308}
309
310inline bool to_float(const Twine &T, float &Num) {
311 return detail::to_float(T, Num, strtof);
312}
313
314inline bool to_float(const Twine &T, double &Num) {
315 return detail::to_float(T, Num, strtod);
316}
317
318inline bool to_float(const Twine &T, long double &Num) {
319 return detail::to_float(T, Num, strtold);
320}
321
322inline std::string utostr(uint64_t X, bool isNeg = false) {
323 char Buffer[21];
324 char *BufPtr = std::end(Buffer);
325
326 if (X == 0) *--BufPtr = '0'; // Handle special case...
327
328 while (X) {
329 *--BufPtr = '0' + char(X % 10);
330 X /= 10;
331 }
332
333 if (isNeg) *--BufPtr = '-'; // Add negative sign...
334 return std::string(BufPtr, std::end(Buffer));
335}
336
337inline std::string itostr(int64_t X) {
338 if (X < 0)
339 return utostr(static_cast<uint64_t>(1) + ~static_cast<uint64_t>(X), true);
340 else
341 return utostr(static_cast<uint64_t>(X));
342}
343
344inline std::string toString(const APInt &I, unsigned Radix, bool Signed,
345 bool formatAsCLiteral = false,
346 bool UpperCase = true,
347 bool InsertSeparators = false) {
349 I.toString(S, Radix, Signed, formatAsCLiteral, UpperCase, InsertSeparators);
350 return std::string(S);
351}
352
353inline std::string toString(const APSInt &I, unsigned Radix) {
354 return toString(I, Radix, I.isSigned());
355}
356
357/// StrInStrNoCase - Portable version of strcasestr. Locates the first
358/// occurrence of string 's1' in string 's2', ignoring case. Returns
359/// the offset of s2 in s1 or npos if s2 cannot be found.
360LLVM_ABI StringRef::size_type StrInStrNoCase(StringRef s1, StringRef s2);
361
362/// getToken - This function extracts one token from source, ignoring any
363/// leading characters that appear in the Delimiters string, and ending the
364/// token at any of the characters that appear in the Delimiters string. If
365/// there are no tokens in the source string, an empty string is returned.
366/// The function returns a pair containing the extracted token and the
367/// remaining tail string.
368LLVM_ABI std::pair<StringRef, StringRef>
369getToken(StringRef Source, StringRef Delimiters = " \t\n\v\f\r");
370
371/// SplitString - Split up the specified string according to the specified
372/// delimiters, appending the result fragments to the output list.
373LLVM_ABI void SplitString(StringRef Source,
374 SmallVectorImpl<StringRef> &OutFragments,
375 StringRef Delimiters = " \t\n\v\f\r");
376
377/// Returns the English suffix for an ordinal integer (-st, -nd, -rd, -th).
378inline StringRef getOrdinalSuffix(unsigned Val) {
379 // It is critically important that we do this perfectly for
380 // user-written sequences with over 100 elements.
381 switch (Val % 100) {
382 case 11:
383 case 12:
384 case 13:
385 return "th";
386 default:
387 switch (Val % 10) {
388 case 1: return "st";
389 case 2: return "nd";
390 case 3: return "rd";
391 default: return "th";
392 }
393 }
394}
395
396/// Print each character of the specified string, escaping it if it is not
397/// printable or if it is an escape char.
398LLVM_ABI void printEscapedString(StringRef Name, raw_ostream &Out);
399
400/// Print each character of the specified string, escaping HTML special
401/// characters.
402LLVM_ABI void printHTMLEscaped(StringRef String, raw_ostream &Out);
403
404/// printLowerCase - Print each character as lowercase if it is uppercase.
405LLVM_ABI void printLowerCase(StringRef String, raw_ostream &Out);
406
407/// Converts a string from camel-case to snake-case by replacing all uppercase
408/// letters with '_' followed by the letter in lowercase, except if the
409/// uppercase letter is the first character of the string.
410LLVM_ABI std::string convertToSnakeFromCamelCase(StringRef input);
411
412/// Converts a string from snake-case to camel-case by replacing all occurrences
413/// of '_' followed by a lowercase letter with the letter in uppercase.
414/// Optionally allow capitalization of the first letter (if it is a lowercase
415/// letter)
416LLVM_ABI std::string convertToCamelFromSnakeCase(StringRef input,
417 bool capitalizeFirst = false);
418
419namespace detail {
420
421template <typename IteratorT>
422inline std::string join_impl(IteratorT Begin, IteratorT End,
423 StringRef Separator, std::input_iterator_tag) {
424 std::string S;
425 if (Begin == End)
426 return S;
427
428 S += (*Begin);
429 while (++Begin != End) {
430 S += Separator;
431 S += (*Begin);
432 }
433 return S;
434}
435
436template <typename IteratorT>
437inline std::string join_impl(IteratorT Begin, IteratorT End,
438 StringRef Separator, std::forward_iterator_tag) {
439 std::string S;
440 if (Begin == End)
441 return S;
442
443 size_t Len = (std::distance(Begin, End) - 1) * Separator.size();
444 for (IteratorT I = Begin; I != End; ++I)
445 Len += StringRef(*I).size();
446 S.reserve(Len);
447 size_t PrevCapacity = S.capacity();
448 (void)PrevCapacity;
449 S += (*Begin);
450 while (++Begin != End) {
451 S += Separator;
452 S += (*Begin);
453 }
454 assert(PrevCapacity == S.capacity() && "String grew during building");
455 return S;
456}
457
458template <typename Sep>
459inline void join_items_impl(std::string &Result, Sep Separator) {}
460
461template <typename Sep, typename Arg>
462inline void join_items_impl(std::string &Result, Sep Separator,
463 const Arg &Item) {
464 Result += Item;
465}
466
467template <typename Sep, typename Arg1, typename... Args>
468inline void join_items_impl(std::string &Result, Sep Separator, const Arg1 &A1,
469 Args &&... Items) {
470 Result += A1;
471 Result += Separator;
472 join_items_impl(Result, Separator, std::forward<Args>(Items)...);
473}
474
475inline size_t join_one_item_size(char) { return 1; }
476inline size_t join_one_item_size(const char *S) { return S ? ::strlen(S) : 0; }
477
478template <typename T> inline size_t join_one_item_size(const T &Str) {
479 return Str.size();
480}
481
482template <typename... Args> inline size_t join_items_size(Args &&...Items) {
483 return (0 + ... + join_one_item_size(std::forward<Args>(Items)));
484}
485
486} // end namespace detail
487
488/// Joins the strings in the range [Begin, End), adding Separator between
489/// the elements.
490template <typename IteratorT>
491inline std::string join(IteratorT Begin, IteratorT End, StringRef Separator) {
492 using tag = typename std::iterator_traits<IteratorT>::iterator_category;
493 return detail::join_impl(Begin, End, Separator, tag());
494}
495
496/// Joins the strings in the range [R.begin(), R.end()), adding Separator
497/// between the elements.
498template <typename Range>
499inline std::string join(Range &&R, StringRef Separator) {
500 return join(R.begin(), R.end(), Separator);
501}
502
503/// Joins the strings in the parameter pack \p Items, adding \p Separator
504/// between the elements. All arguments must be implicitly convertible to
505/// std::string, or there should be an overload of std::string::operator+=()
506/// that accepts the argument explicitly.
507template <typename Sep, typename... Args>
508inline std::string join_items(Sep Separator, Args &&... Items) {
509 std::string Result;
510 if (sizeof...(Items) == 0)
511 return Result;
512
513 size_t NS = detail::join_one_item_size(Separator);
514 size_t NI = detail::join_items_size(std::forward<Args>(Items)...);
515 Result.reserve(NI + (sizeof...(Items) - 1) * NS + 1);
516 detail::join_items_impl(Result, Separator, std::forward<Args>(Items)...);
517 return Result;
518}
519
520/// A helper class to return the specified delimiter string after the first
521/// invocation of operator StringRef(). Used to generate a comma-separated
522/// list from a loop like so:
523///
524/// \code
525/// ListSeparator LS;
526/// for (auto &I : C)
527/// OS << LS << I.getName();
528/// \end
530 bool First = true;
531 StringRef Separator;
532
533public:
534 ListSeparator(StringRef Separator = ", ") : Separator(Separator) {}
535 operator StringRef() {
536 if (First) {
537 First = false;
538 return {};
539 }
540 return Separator;
541 }
542};
543
544/// A forward iterator over partitions of string over a separator.
546 : public iterator_facade_base<SplittingIterator, std::forward_iterator_tag,
547 StringRef> {
548 char SeparatorStorage;
549 StringRef Current;
550 StringRef Next;
551 StringRef Separator;
552
553public:
555 : Next(Str), Separator(Separator) {
556 ++*this;
557 }
558
559 SplittingIterator(StringRef Str, char Separator)
560 : SeparatorStorage(Separator), Next(Str),
561 Separator(&SeparatorStorage, 1) {
562 ++*this;
563 }
564
566 : SeparatorStorage(R.SeparatorStorage), Current(R.Current), Next(R.Next),
567 Separator(R.Separator) {
568 if (R.Separator.data() == &R.SeparatorStorage)
569 Separator = StringRef(&SeparatorStorage, 1);
570 }
571
573 if (this == &R)
574 return *this;
575
576 SeparatorStorage = R.SeparatorStorage;
577 Current = R.Current;
578 Next = R.Next;
579 Separator = R.Separator;
580 if (R.Separator.data() == &R.SeparatorStorage)
581 Separator = StringRef(&SeparatorStorage, 1);
582 return *this;
583 }
584
585 bool operator==(const SplittingIterator &R) const {
586 assert(Separator == R.Separator);
587 return Current.data() == R.Current.data();
588 }
589
590 const StringRef &operator*() const { return Current; }
591
592 StringRef &operator*() { return Current; }
593
595 std::tie(Current, Next) = Next.split(Separator);
596 return *this;
597 }
598};
599
600/// Split the specified string over a separator and return a range-compatible
601/// iterable over its partitions. Used to permit conveniently iterating
602/// over separated strings like so:
603///
604/// \code
605/// for (StringRef x : llvm::split("foo,bar,baz", ","))
606/// ...;
607/// \end
608///
609/// Note that the passed string must remain valid throuhgout lifetime
610/// of the iterators.
612 return {SplittingIterator(Str, Separator),
613 SplittingIterator(StringRef(), Separator)};
614}
615
617 return {SplittingIterator(Str, Separator),
618 SplittingIterator(StringRef(), Separator)};
619}
620
621} // end namespace llvm
622
623#endif // LLVM_ADT_STRINGEXTRAS_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_UNLIKELY(EXPR)
Definition Compiler.h:336
#define LLVM_ABI
Definition Compiler.h:213
static bool isNeg(Value *V)
Returns true if the operation is a negation of V, and it works for both integers and floats.
#define I(x, y, z)
Definition MD5.cpp:58
#define T
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file defines the SmallString class.
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
static const char LUT[]
The Input class is used to parse a yaml document into in-memory structs and vectors.
Class for arbitrary precision integers.
Definition APInt.h:78
An arbitrary precision integer that knows its signedness.
Definition APSInt.h:24
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
ListSeparator(StringRef Separator=", ")
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void resize_for_overwrite(size_type N)
Like resize, but T is POD, the new values won't be initialized.
A forward iterator over partitions of string over a separator.
const StringRef & operator*() const
SplittingIterator(StringRef Str, char Separator)
SplittingIterator(StringRef Str, StringRef Separator)
bool operator==(const SplittingIterator &R) const
SplittingIterator & operator=(const SplittingIterator &R)
SplittingIterator & operator++()
SplittingIterator(const SplittingIterator &R)
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:862
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition StringRef.h:480
size_t size_type
Definition StringRef.h:61
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:154
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:148
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition StringRef.h:434
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterator.h:80
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
bool to_float(const Twine &T, N &Num, N(*StrTo)(const char *, char **))
std::string join_impl(IteratorT Begin, IteratorT End, StringRef Separator, std::input_iterator_tag)
size_t join_one_item_size(char)
size_t join_items_size(Args &&...Items)
void join_items_impl(std::string &Result, Sep Separator)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
@ Length
Definition DWP.cpp:477
LLVM_ABI StringRef::size_type StrInStrNoCase(StringRef s1, StringRef s2)
StrInStrNoCase - Portable version of strcasestr. Locates the first occurrence of string 's1' in strin...
char toLower(char x)
Returns the corresponding lowercase character if x is uppercase.
std::string fromHex(StringRef Input)
Convert hexadecimal string Input to its binary representation. The return string is half the size of ...
LLVM_ABI void printHTMLEscaped(StringRef String, raw_ostream &Out)
Print each character of the specified string, escaping HTML special characters.
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
LLVM_ABI void printLowerCase(StringRef String, raw_ostream &Out)
printLowerCase - Print each character as lowercase if it is uppercase.
LLVM_ABI std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
bool isLower(char C)
Checks if character C is a lowercase letter as classified by "C" locale.
bool tryGetFromHex(StringRef Input, std::string &Output)
Convert hexadecimal string Input to its binary representation and store the result in Output....
std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)
std::string utostr(uint64_t X, bool isNeg=false)
LLVM_ABI void printEscapedString(StringRef Name, raw_ostream &Out)
Print each character of the specified string, escaping it if it is not printable or if it is an escap...
LLVM_ABI void SplitString(StringRef Source, SmallVectorImpl< StringRef > &OutFragments, StringRef Delimiters=" \t\n\v\f\r")
SplitString - Split up the specified string according to the specified delimiters,...
bool to_float(const Twine &T, float &Num)
bool isAlpha(char C)
Checks if character C is a valid letter as classified by "C" locale.
bool tryGetHexFromNibbles(char MSB, char LSB, uint8_t &Hex)
Store the binary representation of the two provided values, MSB and LSB, that make up the nibbles of ...
LLVM_ABI std::string convertToSnakeFromCamelCase(StringRef input)
Converts a string from camel-case to snake-case by replacing all uppercase letters with '_' followed ...
bool isUpper(char C)
Checks if character C is a uppercase letter as classified by "C" locale.
uint8_t hexFromNibbles(char MSB, char LSB)
Return the binary representation of the two provided values, MSB and LSB, that make up the nibbles of...
char hexdigit(unsigned X, bool LowerCase=false)
hexdigit - Return the hexadecimal character for the given number X (which should be less than 16).
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
bool isAlnum(char C)
Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classifie...
iterator_range< SplittingIterator > split(StringRef Str, StringRef Separator)
Split the specified string over a separator and return a range-compatible iterable over its partition...
@ Mod
The access may modify the value stored in memory.
Definition ModRef.h:34
std::string join(IteratorT Begin, IteratorT End, StringRef Separator)
Joins the strings in the range [Begin, End), adding Separator between the elements.
char toUpper(char x)
Returns the corresponding uppercase character if x is lowercase.
StringRef getOrdinalSuffix(unsigned Val)
Returns the English suffix for an ordinal integer (-st, -nd, -rd, -th).
std::vector< StringRef > toStringRefArray(const char *const *Strings)
Given an array of c-style strings terminated by a null pointer, construct a vector of StringRefs repr...
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
LLVM_ABI std::string convertToCamelFromSnakeCase(StringRef input, bool capitalizeFirst=false)
Converts a string from snake-case to camel-case by replacing all occurrences of '_' followed by a low...
void toHex(ArrayRef< uint8_t > Input, bool LowerCase, SmallVectorImpl< char > &Output)
Convert buffer Input to its hexadecimal representation. The returned string is double the size of Inp...
std::string join_items(Sep Separator, Args &&... Items)
Joins the strings in the parameter pack Items, adding Separator between the elements....
bool isASCII(char C)
Checks whether character C is valid ASCII (high bit is zero).
bool isPrint(char C)
Checks whether character C is printable.
bool isSpace(char C)
Checks whether character C is whitespace in the "C" locale.
bool isHexDigit(char C)
Checks if character C is a hexadecimal numeric character.
bool to_integer(StringRef S, N &Num, unsigned Base=0)
Convert the string S to an integer of the specified type using the radix Base. If Base is 0,...
bool isPunct(char C)
Checks whether character C is a punctuation character.
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
std::string itostr(int64_t X)
#define N