14 #ifndef LLVM_ADT_STRINGEXTRAS_H
15 #define LLVM_ADT_STRINGEXTRAS_H
31 template<
typename T>
class SmallVectorImpl;
36 static inline char hexdigit(
unsigned X,
bool LowerCase =
false) {
37 const char HexChar = LowerCase ?
'a' :
'A';
38 return X < 10 ?
'0' + X : HexChar + X - 10;
56 if (C >=
'0' && C <=
'9')
return C-
'0';
57 if (C >=
'a' && C <=
'f')
return C-
'a'+10U;
58 if (C >=
'A' && C <=
'F')
return C-
'A'+10U;
62 static inline std::string
utohexstr(uint64_t
X,
bool LowerCase =
false) {
66 if (X == 0) *--BufPtr =
'0';
69 unsigned char Mod =
static_cast<unsigned char>(
X) & 15;
70 *--BufPtr =
hexdigit(Mod, LowerCase);
74 return std::string(BufPtr,
std::end(Buffer));
80 static const char *
const LUT =
"0123456789ABCDEF";
81 size_t Length = Input.
size();
84 Output.reserve(2 * Length);
85 for (
size_t i = 0; i < Length; ++i) {
86 const unsigned char c = Input[i];
87 Output.push_back(LUT[c >> 4]);
88 Output.push_back(LUT[c & 15]);
100 assert(U1 != -1U && U2 != -1U);
102 return static_cast<uint8_t
>((U1 << 4) | U2);
109 return std::string();
112 Output.reserve((Input.
size() + 1) / 2);
113 if (Input.
size() % 2 == 1) {
119 while (!Input.
empty()) {
121 Output.push_back(Hex);
135 template <
typename N>
160 static inline std::string
utostr(uint64_t
X,
bool isNeg =
false) {
164 if (X == 0) *--BufPtr =
'0';
167 *--BufPtr =
'0' +
char(X % 10);
171 if (isNeg) *--BufPtr =
'-';
172 return std::string(BufPtr,
std::end(Buffer));
177 return utostr(static_cast<uint64_t>(-X),
true);
179 return utostr(static_cast<uint64_t>(X));
194 StringRef Delimiters =
" \t\n\v\f\r");
199 SmallVectorImpl<StringRef> &OutFragments,
200 StringRef Delimiters =
" \t\n\v\f\r");
211 Result = Result * 33 + (
unsigned char)Str[i];
229 default:
return "th";
240 template <
typename IteratorT>
248 while (++Begin != End) {
255 template <
typename IteratorT>
262 size_t Len = (std::distance(Begin, End) - 1) * Separator.
size();
263 for (IteratorT
I = Begin;
I !=
End; ++
I)
264 Len += (*Begin).size();
267 while (++Begin != End) {
274 template <
typename Sep>
277 template <
typename Sep,
typename Arg>
283 template <
typename Sep,
typename Arg1,
typename...
Args>
303 template <
typename A1,
typename...
Args>
312 template <
typename IteratorT>
314 using tag =
typename std::iterator_traits<IteratorT>::iterator_category;
320 template <
typename Range>
329 template <
typename Sep,
typename...
Args>
332 if (
sizeof...(Items) == 0)
337 Result.reserve(NI + (
sizeof...(Items) - 1) * NS + 1);
344 #endif // LLVM_ADT_STRINGEXTRAS_H
bool to_float(const Twine &T, N &Num, N(*StrTo)(const char *, char **))
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::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.
std::string join_items(Sep Separator, Args &&...Items)
Joins the strings in the parameter pack Items, adding Separator between the elements.
const_iterator end(StringRef path)
Get end iterator over path.
static unsigned HashString(StringRef Str, unsigned Result=0)
HashString - Hash function for strings.
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.
void PrintEscapedString(StringRef Name, raw_ostream &Out)
PrintEscapedString - Print each character of the specified string, escaping it if it is not printable...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
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 ...
std::string join(IteratorT Begin, IteratorT End, StringRef Separator)
Joins the strings in the range [Begin, End), adding Separator between the elements.
bool to_float(const Twine &T, float &Num)
static std::string utostr(uint64_t X, bool isNeg=false)
LLVM_NODISCARD char front() const
front - Get the first character in the string.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
static StringRef getOrdinalSuffix(unsigned Val)
Returns the English suffix for an ordinal integer (-st, -nd, -rd, -th).
size_t size() const
size - Get the array size.
void join_items_impl(std::string &Result, Sep Separator)
static uint8_t hexFromNibbles(char MSB, char LSB)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static const unsigned End
static std::string itostr(int64_t X)
size_t join_one_item_size(char C)
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, appending the result fragments to the output list.
static const char * Separator
std::string toHex(StringRef Input)
Convert buffer Input to its hexadecimal representation.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
static StringRef toStringRef(bool B)
Construct a string ref from a boolean.
static char hexdigit(unsigned X, bool LowerCase=false)
hexdigit - Return the hexadecimal character for the given number X (which should be less than 16)...
static std::string fromHex(StringRef Input)
Convert hexadecimal string Input to its binary representation.
StringRef::size_type StrInStrNoCase(StringRef s1, StringRef s2)
StrInStrNoCase - Portable version of strcasestr.
static std::string utohexstr(uint64_t X, bool LowerCase=false)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef toNullTerminatedStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single null terminated StringRef if it can be represented as such...
static unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
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).
StringRef - Represent a constant reference to a string, i.e.
std::string join_impl(IteratorT Begin, IteratorT End, StringRef Separator, std::input_iterator_tag)