14 #ifndef LLVM_ADT_STRINGEXTRAS_H 15 #define LLVM_ADT_STRINGEXTRAS_H 32 template<
typename T>
class SmallVectorImpl;
37 inline char hexdigit(
unsigned X,
bool LowerCase =
false) {
38 const char HexChar = LowerCase ?
'a' :
'A';
39 return X < 10 ?
'0' +
X : HexChar + X - 10;
46 std::vector<StringRef> Result;
48 Result.push_back(*Strings++);
70 if (C >=
'0' && C <=
'9')
return C-
'0';
71 if (C >=
'a' && C <=
'f')
return C-
'a'+10U;
72 if (C >=
'A' && C <=
'F')
return C-
'A'+10U;
77 inline bool isDigit(
char C) {
return C >=
'0' && C <=
'9'; }
84 return (
'a' <= C && C <=
'z') || (
'A' <= C && C <=
'Z');
92 inline bool isASCII(
char C) {
return static_cast<unsigned char>(
C) <= 127; }
107 unsigned char UC =
static_cast<unsigned char>(
C);
108 return (0x20 <= UC) && (UC <= 0x7E);
113 if (x >=
'A' && x <=
'Z')
114 return x -
'A' +
'a';
120 if (x >=
'a' && x <=
'z')
121 return x -
'a' +
'A';
125 inline std::string
utohexstr(uint64_t
X,
bool LowerCase =
false) {
129 if (X == 0) *--BufPtr =
'0';
132 unsigned char Mod =
static_cast<unsigned char>(
X) & 15;
133 *--BufPtr =
hexdigit(Mod, LowerCase);
137 return std::string(BufPtr,
std::end(Buffer));
143 static const char *
const LUT =
"0123456789ABCDEF";
144 const uint8_t
Offset = LowerCase ? 32 : 0;
145 size_t Length = Input.
size();
148 Output.reserve(2 * Length);
149 for (
size_t i = 0; i < Length; ++i) {
150 const unsigned char c = Input[i];
151 Output.push_back(LUT[c >> 4] | Offset);
152 Output.push_back(LUT[c & 15] | Offset);
164 assert(U1 != -1U && U2 != -1U);
166 return static_cast<uint8_t
>((U1 << 4) | U2);
173 return std::string();
176 Output.reserve((Input.
size() + 1) / 2);
177 if (Input.
size() % 2 == 1) {
183 while (!Input.
empty()) {
185 Output.push_back(Hex);
199 template <
typename N>
204 N Temp = StrTo(S.
data(), &End);
224 inline std::string
utostr(uint64_t
X,
bool isNeg =
false) {
228 if (X == 0) *--BufPtr =
'0';
231 *--BufPtr =
'0' +
char(X % 10);
235 if (isNeg) *--BufPtr =
'-';
236 return std::string(BufPtr,
std::end(Buffer));
241 return utostr(static_cast<uint64_t>(-X),
true);
243 return utostr(static_cast<uint64_t>(X));
280 default:
return "th";
298 template <
typename IteratorT>
299 inline std::string
join_impl(IteratorT Begin, IteratorT End,
300 StringRef Separator, std::input_iterator_tag) {
306 while (++Begin != End) {
313 template <
typename IteratorT>
314 inline std::string
join_impl(IteratorT Begin, IteratorT End,
315 StringRef Separator, std::forward_iterator_tag) {
320 size_t Len = (std::distance(Begin, End) - 1) * Separator.
size();
321 for (IteratorT
I = Begin;
I != End; ++
I)
322 Len += (*Begin).size();
325 while (++Begin != End) {
332 template <
typename Sep>
335 template <
typename Sep,
typename Arg>
341 template <
typename Sep,
typename Arg1,
typename...
Args>
361 template <
typename A1,
typename...
Args>
370 template <
typename IteratorT>
371 inline std::string
join(IteratorT Begin, IteratorT End,
StringRef Separator) {
372 using tag =
typename std::iterator_traits<IteratorT>::iterator_category;
378 template <
typename Range>
380 return join(R.begin(), R.end(), Separator);
387 template <
typename Sep,
typename...
Args>
390 if (
sizeof...(Items) == 0)
395 Result.reserve(NI + (
sizeof...(Items) - 1) * NS + 1);
402 #endif // LLVM_ADT_STRINGEXTRAS_H bool to_float(const Twine &T, N &Num, N(*StrTo)(const char *, char **))
const_iterator end(StringRef path)
Get end iterator over path.
std::string join_items(Sep Separator, Args &&... Items)
Joins the strings in the parameter pack Items, adding Separator between the elements.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
bool isPrint(char C)
Checks whether character C is printable.
This class represents lattice values for constants.
const unsigned char * bytes_end() const
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
bool isASCII(char C)
Checks whether character C is valid ASCII (high bit is zero).
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...
ArrayRef< uint8_t > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
std::string fromHex(StringRef Input)
Convert hexadecimal string Input to its binary representation.
#define LLVM_UNLIKELY(EXPR)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
bool isAlnum(char C)
Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classifie...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::string join(IteratorT Begin, IteratorT End, StringRef Separator)
Joins the strings in the range [Begin, End), adding Separator between the elements.
void SplitString(StringRef Source, SmallVectorImpl< StringRef > &OutFragments, StringRef Delimiters=" \\\)
SplitString - Split up the specified string according to the specified delimiters, appending the result fragments to the output list.
std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \\\)
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
std::string itostr(int64_t X)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
char hexdigit(unsigned X, bool LowerCase=false)
hexdigit - Return the hexadecimal character for the given number X (which should be less than 16)...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void join_items_impl(std::string &Result, Sep Separator)
size_t size() const
size - Get the array size.
bool isHexDigit(char C)
Checks if character C is a hexadecimal numeric character.
StringRef toNullTerminatedStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single null terminated StringRef if it can be represented as such...
bool isAlpha(char C)
Checks if character C is a valid letter as classified by "C" locale.
char toLower(char x)
Returns the corresponding lowercase character if x is uppercase.
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
size_t join_one_item_size(char C)
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
std::string utostr(uint64_t X, bool isNeg=false)
The access may modify the value stored in memory.
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
amdgpu Simplify well known AMD library false Value Value * Arg
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
const unsigned char * bytes_begin() const
StringRef::size_type StrInStrNoCase(StringRef s1, StringRef s2)
StrInStrNoCase - Portable version of strcasestr.
StringRef getOrdinalSuffix(unsigned Val)
Returns the English suffix for an ordinal integer (-st, -nd, -rd, -th).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
char toUpper(char x)
Returns the corresponding uppercase character if x is lowercase.
LLVM_NODISCARD char front() const
front - Get the first character in the string.
void printLowerCase(StringRef String, raw_ostream &Out)
printLowerCase - Print each character as lowercase if it is uppercase.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
uint8_t hexFromNibbles(char MSB, char LSB)
std::string toHex(StringRef Input, bool LowerCase=false)
Convert buffer Input to its hexadecimal representation.
void printHTMLEscaped(StringRef String, raw_ostream &Out)
Print each character of the specified string, escaping HTML special characters.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
std::string join_impl(IteratorT Begin, IteratorT End, StringRef Separator, std::input_iterator_tag)
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...
std::string utohexstr(uint64_t X, bool LowerCase=false)