diff options
Diffstat (limited to 'llvm/include')
-rw-r--r-- | llvm/include/llvm/ADT/StringExtras.h | 16 | ||||
-rw-r--r-- | llvm/include/llvm/Support/SHA1.h | 7 |
2 files changed, 23 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/StringExtras.h b/llvm/include/llvm/ADT/StringExtras.h index 8de6fb257ce..bdbb4d3f593 100644 --- a/llvm/include/llvm/ADT/StringExtras.h +++ b/llvm/include/llvm/ADT/StringExtras.h @@ -59,6 +59,22 @@ static inline std::string utohexstr(uint64_t X, bool LowerCase = false) { return std::string(BufPtr, std::end(Buffer)); } +/// 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) { + static const char *const LUT = "0123456789ABCDEF"; + size_t Length = Input.size(); + + std::string Output; + Output.reserve(2 * Length); + for (size_t i = 0; i < Length; ++i) { + const unsigned char c = Input[i]; + Output.push_back(LUT[c >> 4]); + Output.push_back(LUT[c & 15]); + } + return Output; +} + static inline std::string utostr(uint64_t X, bool isNeg = false) { char Buffer[21]; char *BufPtr = std::end(Buffer); diff --git a/llvm/include/llvm/Support/SHA1.h b/llvm/include/llvm/Support/SHA1.h index 05892327a21..896a610eaf6 100644 --- a/llvm/include/llvm/Support/SHA1.h +++ b/llvm/include/llvm/Support/SHA1.h @@ -16,6 +16,8 @@ #ifndef LLVM_SUPPORT_SHA1_H #define LLVM_SUPPORT_SHA1_H +#include "llvm/ADT/ArrayRef.h" + #include <cstdint> namespace llvm { @@ -33,6 +35,11 @@ public: /// Digest more data. void update(ArrayRef<uint8_t> Data); + /// Digest more data. + void update(StringRef Str) { + update(ArrayRef<uint8_t>((uint8_t *)Str.data(), Str.size())); + } + /// Return a reference to the current raw 160-bits SHA1 for the digested data /// since the last call to init(). This call will add data to the internal /// state and as such is not suited for getting an intermediate result |