[llvm-commits] [llvm] r57536 - /llvm/trunk/include/llvm/ADT/StringExtras.h
Daniel Dunbar
daniel at zuster.org
Tue Oct 14 16:26:20 PDT 2008
Author: ddunbar
Date: Tue Oct 14 18:26:20 2008
New Revision: 57536
URL: http://llvm.org/viewvc/llvm-project?rev=57536&view=rev
Log:
Add llvm::hexdigit to StringExtras (number -> hexadecimal char)
Modified:
llvm/trunk/include/llvm/ADT/StringExtras.h
Modified: llvm/trunk/include/llvm/ADT/StringExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringExtras.h?rev=57536&r1=57535&r2=57536&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringExtras.h (original)
+++ llvm/trunk/include/llvm/ADT/StringExtras.h Tue Oct 14 18:26:20 2008
@@ -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 @@
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);
More information about the llvm-commits
mailing list