1 //===-- Support/StringExtras.h - Useful string functions ---------*- C++ -*--=//
3 // This file contains some functions that are useful when dealing with strings.
5 //===----------------------------------------------------------------------===//
7 #ifndef SUPPORT_STRING_EXTRAS_H
8 #define SUPPORT_STRING_EXTRAS_H
10 #include "Support/DataTypes.h"
14 static inline std::string utostr(uint64_t X, bool isNeg = false) {
16 char *BufPtr = Buffer+39;
18 *BufPtr = 0; // Null terminate buffer...
19 if (X == 0) *--BufPtr = '0'; // Handle special case...
22 *--BufPtr = '0' + (X % 10);
26 if (isNeg) *--BufPtr = '-'; // Add negative sign...
28 return std::string(BufPtr);
31 static inline std::string itostr(int64_t X) {
33 return utostr((uint64_t)-X, true);
35 return utostr((uint64_t)X);
39 static inline std::string utostr(unsigned X, bool isNeg = false) {
41 char *BufPtr = Buffer+19;
43 *BufPtr = 0; // Null terminate buffer...
44 if (X == 0) *--BufPtr = '0'; // Handle special case...
47 *--BufPtr = '0' + (X % 10);
51 if (isNeg) *--BufPtr = '-'; // Add negative sign...
53 return std::string(BufPtr);
56 static inline std::string itostr(int X) {
58 return utostr((unsigned)-X, true);
60 return utostr((unsigned)X);
63 static inline std::string ftostr(double V) {
65 snprintf(Buffer, 200, "%e", V);