mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-04 09:37:20 +00:00
split out the functionality of utohexstr into a new utohex_buffer
helper. This allows us to convert numbers to hex without necessarily needing to make a std::string to hold the result. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58961 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
497a7a81a8
commit
886645a3c3
@ -29,19 +29,34 @@ static inline char hexdigit(unsigned X) {
|
|||||||
return X < 10 ? '0' + X : 'A' + X - 10;
|
return X < 10 ? '0' + X : 'A' + X - 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline std::string utohexstr(uint64_t X) {
|
/// utohex_buffer - Emit the specified number into the buffer specified by
|
||||||
char Buffer[40];
|
/// BufferEnd, returning a pointer to the start of the string. This can be used
|
||||||
char *BufPtr = Buffer+39;
|
/// like this: (note that the buffer must be large enough to handle any number):
|
||||||
|
/// char Buffer[40];
|
||||||
*BufPtr = 0; // Null terminate buffer...
|
/// printf("0x%s", utohex_buffer(X, Buffer+40));
|
||||||
if (X == 0) *--BufPtr = '0'; // Handle special case...
|
///
|
||||||
|
/// This should only be used with unsigned types.
|
||||||
|
///
|
||||||
|
template<typename IntTy>
|
||||||
|
static inline char *utohex_buffer(IntTy X, char *BufferEnd) {
|
||||||
|
char *BufPtr = BufferEnd;
|
||||||
|
*--BufPtr = 0; // Null terminate buffer.
|
||||||
|
if (X == 0) {
|
||||||
|
*--BufPtr = '0'; // Handle special case.
|
||||||
|
return BufPtr;
|
||||||
|
}
|
||||||
|
|
||||||
while (X) {
|
while (X) {
|
||||||
unsigned char Mod = static_cast<unsigned char>(X) & 15;
|
unsigned char Mod = static_cast<unsigned char>(X) & 15;
|
||||||
*--BufPtr = hexdigit(Mod);
|
*--BufPtr = hexdigit(Mod);
|
||||||
X >>= 4;
|
X >>= 4;
|
||||||
}
|
}
|
||||||
return std::string(BufPtr);
|
return BufPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline std::string utohexstr(uint64_t X) {
|
||||||
|
char Buffer[40];
|
||||||
|
return utohex_buffer(X, Buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline std::string utostr_32(uint32_t X, bool isNeg = false) {
|
static inline std::string utostr_32(uint32_t X, bool isNeg = false) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user