llvm.org GIT mirror llvm / a49d65c
[StringExtras] overload toHex for ArrayRef<uint8_t> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305411 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 2 years ago
1 changed file(s) with 11 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
1313 #ifndef LLVM_ADT_STRINGEXTRAS_H
1414 #define LLVM_ADT_STRINGEXTRAS_H
1515
16 #include "llvm/ADT/ArrayRef.h"
1617 #include "llvm/ADT/StringRef.h"
1718 #include
1819 #include
3738 /// Construct a string ref from a boolean.
3839 static inline StringRef toStringRef(bool B) {
3940 return StringRef(B ? "true" : "false");
41 }
42
43 /// Construct a string ref from an array ref of unsigned chars.
44 static inline StringRef toStringRef(ArrayRef Input) {
45 return StringRef(reinterpret_cast(Input.begin()), Input.size());
4046 }
4147
4248 /// Interpret the given character \p C as a hexadecimal digit and return its
6773
6874 /// Convert buffer \p Input to its hexadecimal representation.
6975 /// The returned string is double the size of \p Input.
70 static inline std::string toHex(StringRef Input) {
76 inline std::string toHex(StringRef Input) {
7177 static const char *const LUT = "0123456789ABCDEF";
7278 size_t Length = Input.size();
7379
7985 Output.push_back(LUT[c & 15]);
8086 }
8187 return Output;
88 }
89
90 inline std::string toHex(ArrayRef Input) {
91 return toHex(toStringRef(Input));
8292 }
8393
8494 static inline uint8_t hexFromNibbles(char MSB, char LSB) {