aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/ADT/StringExtras.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/ADT/StringExtras.h')
-rw-r--r--include/llvm/ADT/StringExtras.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h
index 87b8ba6596..872c8451bf 100644
--- a/include/llvm/ADT/StringExtras.h
+++ b/include/llvm/ADT/StringExtras.h
@@ -23,6 +23,12 @@
namespace llvm {
+/// hexdigit - Return the (uppercase) hexadecimal character for the
+/// given number \arg X (which should be less than 16).
+static inline char hexdigit(unsigned X) {
+ return X < 10 ? '0' + X : 'A' + X - 10;
+}
+
static inline std::string utohexstr(uint64_t X) {
char Buffer[40];
char *BufPtr = Buffer+39;
@@ -32,10 +38,7 @@ static inline std::string utohexstr(uint64_t X) {
while (X) {
unsigned char Mod = static_cast<unsigned char>(X) & 15;
- if (Mod < 10)
- *--BufPtr = '0' + Mod;
- else
- *--BufPtr = 'A' + Mod-10;
+ *--BufPtr = hexdigit(Mod);
X >>= 4;
}
return std::string(BufPtr);