[llvm-commits] [llvm] r49765 - /llvm/trunk/include/llvm/ADT/SmallString.h
Chris Lattner
sabre at nondot.org
Tue Apr 15 21:05:02 PDT 2008
Author: lattner
Date: Tue Apr 15 23:05:02 2008
New Revision: 49765
URL: http://llvm.org/viewvc/llvm-project?rev=49765&view=rev
Log:
give smallstring some methods to do 'itoa'.
Modified:
llvm/trunk/include/llvm/ADT/SmallString.h
Modified: llvm/trunk/include/llvm/ADT/SmallString.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallString.h?rev=49765&r1=49764&r2=49765&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallString.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallString.h Tue Apr 15 23:05:02 2008
@@ -53,6 +53,47 @@
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);
+ }
};
More information about the llvm-commits
mailing list