Add llvm::hexdigit to StringExtras (number -> hexadecimal char)

llvm-svn: 57536
This commit is contained in:
Daniel Dunbar 2008-10-14 23:26:20 +00:00
parent c11b40f6e1
commit 6cba0ebe6b
1 changed files with 7 additions and 4 deletions

View File

@ -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);