give smallstring some methods to do 'itoa'.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49765 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2008-04-16 04:05:02 +00:00
parent 171c11ec93
commit c0814dc606

View File

@ -53,6 +53,47 @@ public:
this->push_back(C);
return *this;
}
SmallString &append_uint_32(uint32_t N) {
char Buffer[20];
char *BufPtr = Buffer+19;
if (N == 0) *--BufPtr = '0'; // Handle special case.
while (N) {
*--BufPtr = '0' + char(N % 10);
N /= 10;
}
this->append(BufPtr, Buffer+20);
return *this;
}
SmallString &append_uint(uint64_t N) {
if (N == uint32_t(N))
return append_uint_32(uint32_t(N));
char Buffer[40];
char *BufPtr = Buffer+39;
if (N == 0) *--BufPtr = '0'; // Handle special case...
while (N) {
*--BufPtr = '0' + char(N % 10);
N /= 10;
}
this->append(BufPtr, Buffer+40);
return *this;
}
SmallString &append_sint(int64_t N) {
// TODO, wrong for minint64.
if (N < 0) {
this->push_back('-');
N = -N;
}
return append_uint(N);
}
};