diff options
author | Chris Lattner <sabre@nondot.org> | 2002-04-07 08:36:19 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-04-07 08:36:19 +0000 |
commit | 2e183b5c44470b0bb0baf34b1935dff927f78aa6 (patch) | |
tree | 0c14876ad0a1999171cfa72f8a15954ba6da8891 /llvm/include/Support/StringExtras.h | |
parent | b99f479f71cdc322e5ea4cbd0f8a1d090bdd395b (diff) | |
download | bcm5719-llvm-2e183b5c44470b0bb0baf34b1935dff927f78aa6.tar.gz bcm5719-llvm-2e183b5c44470b0bb0baf34b1935dff927f78aa6.zip |
Add new function utohexstr.
llvm-svn: 2140
Diffstat (limited to 'llvm/include/Support/StringExtras.h')
-rw-r--r-- | llvm/include/Support/StringExtras.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/include/Support/StringExtras.h b/llvm/include/Support/StringExtras.h index 46e2c5aaf0b..529d86caa20 100644 --- a/llvm/include/Support/StringExtras.h +++ b/llvm/include/Support/StringExtras.h @@ -11,6 +11,24 @@ #include <string> #include <stdio.h> +static inline std::string utohexstr(uint64_t X) { + char Buffer[40]; + char *BufPtr = Buffer+39; + + *BufPtr = 0; // Null terminate buffer... + if (X == 0) *--BufPtr = '0'; // Handle special case... + + while (X) { + unsigned Mod = X & 15; + if (Mod < 10) + *--BufPtr = '0' + Mod; + else + *--BufPtr = 'A' + Mod-10; + X >>= 4; + } + return std::string(BufPtr); +} + static inline std::string utostr(uint64_t X, bool isNeg = false) { char Buffer[40]; char *BufPtr = Buffer+39; |