Extend StringRef's edit-distance algorithm to permit an upper bound on the allowed...
[oota-llvm.git] / include / llvm / ADT / SmallString.h
index bbc3c0526ad4e7d76815def0f70c09e218533eb8..05bd8a42c67f650c967e3212298deb3dda111b9a 100644 (file)
@@ -15,8 +15,7 @@
 #define LLVM_ADT_SMALLSTRING_H
 
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/DataTypes.h"
-#include <cstring>
+#include "llvm/ADT/StringRef.h"
 
 namespace llvm {
 
@@ -37,72 +36,33 @@ public:
 
 
   // Extra methods.
-  const char *c_str() const {
-    SmallString *This = const_cast<SmallString*>(this);
-    // Ensure that there is a \0 at the end of the string.
-    This->reserve(this->size()+1);
-    This->End[0] = 0;
-    return this->begin();
+  StringRef str() const { return StringRef(this->begin(), this->size()); }
+
+  // Implicit conversion to StringRef.
+  operator StringRef() const { return str(); }
+
+  const char *c_str() {
+    this->push_back(0);
+    this->pop_back();
+    return this->data();
   }
 
   // Extra operators.
-  const SmallString &operator=(const char *RHS) {
+  const SmallString &operator=(StringRef RHS) {
     this->clear();
     return *this += RHS;
   }
 
-  SmallString &operator+=(const char *RHS) {
-    this->append(RHS, RHS+strlen(RHS));
+  SmallString &operator+=(StringRef RHS) {
+    this->append(RHS.begin(), RHS.end());
     return *this;
   }
   SmallString &operator+=(char C) {
     this->push_back(C);
     return *this;
   }
-
-  SmallString &append_uint_32(uint32_t N) {
-    char Buffer[20];
-    char *BufPtr = Buffer+20;
-
-    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+40;
-
-    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) {
-    if (N < 0) {
-      this->push_back('-');
-      N = -N;
-    }
-    return append_uint((uint64_t)N);
-  }
-
 };
 
-
 }
 
 #endif