14 #ifndef LLVM_ADT_STRINGEXTRAS_H
15 #define LLVM_ADT_STRINGEXTRAS_H
18 #include "llvm/Support/DataTypes.h"
23 template<
typename T>
class SmallVectorImpl;
27 static inline char hexdigit(
unsigned X,
bool LowerCase =
false) {
28 const char HexChar = LowerCase ?
'a' :
'A';
29 return X < 10 ?
'0' + X : HexChar + X - 10;
42 if (C >=
'0' && C <=
'9')
return C-
'0';
43 if (C >=
'a' && C <=
'f')
return C-
'a'+10U;
44 if (C >=
'A' && C <=
'F')
return C-
'A'+10U;
48 static inline std::string
utohexstr(uint64_t
X,
bool LowerCase =
false) {
52 if (X == 0) *--BufPtr =
'0';
55 unsigned char Mod =
static_cast<unsigned char>(
X) & 15;
56 *--BufPtr =
hexdigit(Mod, LowerCase);
60 return std::string(BufPtr,
std::end(Buffer));
66 static const char *
const LUT =
"0123456789ABCDEF";
67 size_t Length = Input.
size();
70 Output.reserve(2 * Length);
71 for (
size_t i = 0;
i < Length; ++
i) {
72 const unsigned char c = Input[
i];
73 Output.push_back(LUT[c >> 4]);
74 Output.push_back(LUT[c & 15]);
79 static inline std::string
utostr(uint64_t
X,
bool isNeg =
false) {
83 if (X == 0) *--BufPtr =
'0';
86 *--BufPtr =
'0' + char(X % 10);
90 if (isNeg) *--BufPtr =
'-';
91 return std::string(BufPtr,
std::end(Buffer));
95 static inline std::string
itostr(int64_t
X) {
97 return utostr(static_cast<uint64_t>(-X),
true);
99 return utostr(static_cast<uint64_t>(X));
114 StringRef Delimiters =
" \t\n\v\f\r");
119 SmallVectorImpl<StringRef> &OutFragments,
120 StringRef Delimiters =
" \t\n\v\f\r");
131 Result = Result * 33 + (
unsigned char)Str[
i];
149 default:
return "th";
160 template <
typename IteratorT>
168 while (++Begin != End) {
175 template <
typename IteratorT>
182 size_t Len = (std::distance(Begin, End) - 1) * Separator.
size();
183 for (IteratorT
I = Begin;
I !=
End; ++
I)
184 Len += (*Begin).size();
187 while (++Begin != End) {
194 template <
typename Sep>
197 template <
typename Sep,
typename Arg>
203 template <
typename Sep,
typename Arg1,
typename...
Args>
223 template <
typename A1,
typename...
Args>
231 template <
typename IteratorT>
233 typedef typename std::iterator_traits<IteratorT>::iterator_category tag;
241 template <
typename Sep,
typename...
Args>
244 if (
sizeof...(Items) == 0)
249 Result.reserve(NI + (
sizeof...(Items) - 1) * NS + 1);
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.
void PrintEscapedString(StringRef Name, raw_ostream &Out)
PrintEscapedString - Print each character of the specified string, escaping it if it is not printable...
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.
static std::string toHex(StringRef Input)
Convert buffer Input to its hexadecimal representation.
static std::string utostr(uint64_t X, bool isNeg=false)
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
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).
void join_items_impl(std::string &Result, Sep Separator)
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
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
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)...
StringRef::size_type StrInStrNoCase(StringRef s1, StringRef s2)
StrInStrNoCase - Portable version of strcasestr.
static std::string utohexstr(uint64_t X, bool LowerCase=false)
static unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
StringRef - Represent a constant reference to a string, i.e.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
std::string join_impl(IteratorT Begin, IteratorT End, StringRef Separator, std::input_iterator_tag)