14 #ifndef LLVM_ADT_STRINGEXTRAS_H
15 #define LLVM_ADT_STRINGEXTRAS_H
18 #include "llvm/Support/DataTypes.h"
22 template<
typename T>
class SmallVectorImpl;
26 static inline char hexdigit(
unsigned X,
bool LowerCase =
false) {
27 const char HexChar = LowerCase ?
'a' :
'A';
28 return X < 10 ?
'0' + X : HexChar + X - 10;
41 if (C >=
'0' && C <=
'9')
return C-
'0';
42 if (C >=
'a' && C <=
'f')
return C-
'a'+10U;
43 if (C >=
'A' && C <=
'F')
return C-
'A'+10U;
55 template<
typename IntTy>
56 static inline char *
utohex_buffer(IntTy
X,
char *BufferEnd,
bool LowerCase =
false) {
57 char *BufPtr = BufferEnd;
65 unsigned char Mod =
static_cast<unsigned char>(
X) & 15;
66 *--BufPtr =
hexdigit(Mod, LowerCase);
72 static inline std::string
utohexstr(uint64_t
X,
bool LowerCase =
false) {
77 static inline std::string
utostr_32(uint32_t
X,
bool isNeg =
false) {
79 char *BufPtr = Buffer+11;
81 if (X == 0) *--BufPtr =
'0';
84 *--BufPtr =
'0' + char(X % 10);
88 if (isNeg) *--BufPtr =
'-';
90 return std::string(BufPtr, Buffer+11);
93 static inline std::string
utostr(uint64_t
X,
bool isNeg =
false) {
95 char *BufPtr = Buffer+21;
97 if (X == 0) *--BufPtr =
'0';
100 *--BufPtr =
'0' + char(X % 10);
104 if (isNeg) *--BufPtr =
'-';
105 return std::string(BufPtr, Buffer+21);
111 return utostr(static_cast<uint64_t>(-X),
true);
113 return utostr(static_cast<uint64_t>(X));
128 StringRef Delimiters =
" \t\n\v\f\r");
133 SmallVectorImpl<StringRef> &OutFragments,
134 StringRef Delimiters =
" \t\n\v\f\r");
145 Result = Result * 33 + (
unsigned char)Str[i];
163 default:
return "th";
168 template <
typename IteratorT>
169 inline std::string
join_impl(IteratorT Begin, IteratorT End,
170 StringRef Separator, std::input_iterator_tag) {
176 while (++Begin != End) {
183 template <
typename IteratorT>
184 inline std::string
join_impl(IteratorT Begin, IteratorT End,
185 StringRef Separator, std::forward_iterator_tag) {
190 size_t Len = (std::distance(Begin, End) - 1) * Separator.
size();
191 for (IteratorT
I = Begin;
I != End; ++
I)
192 Len += (*Begin).size();
195 while (++Begin != End) {
204 template <
typename IteratorT>
205 inline std::string
join(IteratorT Begin, IteratorT End,
StringRef Separator) {
206 typedef typename std::iterator_traits<IteratorT>::iterator_category tag;
207 return join_impl(Begin, End, Separator, tag());
static unsigned HashString(StringRef Str, unsigned Result=0)
HashString - Hash function for strings.
size_t size() const
size - Get the string size.
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 utostr(uint64_t X, bool isNeg=false)
static StringRef getOrdinalSuffix(unsigned Val)
Returns the English suffix for an ordinal integer (-st, -nd, -rd, -th).
std::string join_impl(IteratorT Begin, IteratorT End, StringRef Separator, std::input_iterator_tag)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static std::string itostr(int64_t X)
static std::string utostr_32(uint32_t X, bool isNeg=false)
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 char * utohex_buffer(IntTy X, char *BufferEnd, bool LowerCase=false)
utohex_buffer - Emit the specified number into the buffer specified by BufferEnd, returning a pointer...
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.
C - The default llvm calling convention, compatible with C.
StringRef - Represent a constant reference to a string, i.e.