diff options
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/ADT/StringExtras.h | 27 | 
1 files changed, 6 insertions, 21 deletions
diff --git a/llvm/include/llvm/ADT/StringExtras.h b/llvm/include/llvm/ADT/StringExtras.h index 2366e67f2d7..519c6073ae0 100644 --- a/llvm/include/llvm/ADT/StringExtras.h +++ b/llvm/include/llvm/ADT/StringExtras.h @@ -44,34 +44,19 @@ static inline unsigned hexDigitValue(char C) {    return -1U;  } -/// utohex_buffer - Emit the specified number into the buffer specified by -/// BufferEnd, returning a pointer to the start of the string.  This can be used -/// like this: (note that the buffer must be large enough to handle any number): -///    char Buffer[40]; -///    printf("0x%s", utohex_buffer(X, Buffer+40)); -/// -/// This should only be used with unsigned types. -/// -template<typename IntTy> -static inline char *utohex_buffer(IntTy X, char *BufferEnd, bool LowerCase = false) { -  char *BufPtr = BufferEnd; -  *--BufPtr = 0;      // Null terminate buffer. -  if (X == 0) { -    *--BufPtr = '0';  // Handle special case. -    return BufPtr; -  } +static inline std::string utohexstr(uint64_t X, bool LowerCase = false) { +  char Buffer[17]; +  char *BufPtr = std::end(Buffer); + +  if (X == 0) *--BufPtr = '0';    while (X) {      unsigned char Mod = static_cast<unsigned char>(X) & 15;      *--BufPtr = hexdigit(Mod, LowerCase);      X >>= 4;    } -  return BufPtr; -} -static inline std::string utohexstr(uint64_t X, bool LowerCase = false) { -  char Buffer[17]; -  return utohex_buffer(X, std::end(Buffer), LowerCase); +  return std::string(BufPtr, std::end(Buffer));  }  static inline std::string utostr_32(uint32_t X, bool isNeg = false) {  | 

