diff options
| author | Zachary Turner <zturner@google.com> | 2017-06-14 20:11:46 +0000 |
|---|---|---|
| committer | Zachary Turner <zturner@google.com> | 2017-06-14 20:11:46 +0000 |
| commit | 7ac5450237cf639f1ff799cce94ff988be52a035 (patch) | |
| tree | ec8ebdad40dfccc22b84c7b53e0670a80a260e3b | |
| parent | 8b086e38789796b575be2cc875dd8d67cd714338 (diff) | |
| download | bcm5719-llvm-7ac5450237cf639f1ff799cce94ff988be52a035.tar.gz bcm5719-llvm-7ac5450237cf639f1ff799cce94ff988be52a035.zip | |
[StringExtras] overload toHex for ArrayRef<uint8_t>
llvm-svn: 305411
| -rw-r--r-- | llvm/include/llvm/ADT/StringExtras.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/include/llvm/ADT/StringExtras.h b/llvm/include/llvm/ADT/StringExtras.h index bbea8619a67..ffcf998a3d3 100644 --- a/llvm/include/llvm/ADT/StringExtras.h +++ b/llvm/include/llvm/ADT/StringExtras.h @@ -14,6 +14,7 @@ #ifndef LLVM_ADT_STRINGEXTRAS_H #define LLVM_ADT_STRINGEXTRAS_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include <cassert> #include <cstddef> @@ -40,6 +41,11 @@ static inline StringRef toStringRef(bool B) { return StringRef(B ? "true" : "false"); } +/// Construct a string ref from an array ref of unsigned chars. +static inline StringRef toStringRef(ArrayRef<uint8_t> Input) { + return StringRef(reinterpret_cast<const char *>(Input.begin()), Input.size()); +} + /// Interpret the given character \p C as a hexadecimal digit and return its /// value. /// @@ -68,7 +74,7 @@ static inline std::string utohexstr(uint64_t X, bool LowerCase = false) { /// Convert buffer \p Input to its hexadecimal representation. /// The returned string is double the size of \p Input. -static inline std::string toHex(StringRef Input) { +inline std::string toHex(StringRef Input) { static const char *const LUT = "0123456789ABCDEF"; size_t Length = Input.size(); @@ -82,6 +88,10 @@ static inline std::string toHex(StringRef Input) { return Output; } +inline std::string toHex(ArrayRef<uint8_t> Input) { + return toHex(toStringRef(Input)); +} + static inline uint8_t hexFromNibbles(char MSB, char LSB) { unsigned U1 = hexDigitValue(MSB); unsigned U2 = hexDigitValue(LSB); |

