X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FSmallString.h;h=da264164821f2a9bcf209e4641dae75a6e8aa8da;hb=152096275ad45bb13d5652f7019f48be5ccd67f8;hp=c7a292d8b9098b08f93d2ab51b9fe290e2ea31a9;hpb=dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0;p=oota-llvm.git diff --git a/include/llvm/ADT/SmallString.h b/include/llvm/ADT/SmallString.h index c7a292d8b90..da264164821 100644 --- a/include/llvm/ADT/SmallString.h +++ b/include/llvm/ADT/SmallString.h @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by Chris Lattner and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -15,7 +15,7 @@ #define LLVM_ADT_SMALLSTRING_H #include "llvm/ADT/SmallVector.h" -#include +#include "llvm/ADT/StringRef.h" namespace llvm { @@ -27,31 +27,46 @@ public: // Default ctor - Initialize to empty. SmallString() {} + // Initialize from a StringRef. + SmallString(StringRef S) : SmallVector(S.begin(), S.end()) {} + // Initialize with a range. template SmallString(ItTy S, ItTy E) : SmallVector(S, E) {} - + // Copy ctor. SmallString(const SmallString &RHS) : SmallVector(RHS) {} - + // Extra methods. - const char *c_str() const { - SmallString *This = const_cast(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()); } + + // TODO: Make this const, if it's safe... + const char* c_str() { + this->push_back(0); + this->pop_back(); + return this->data(); } - + + // Implicit conversion to StringRef. + operator StringRef() const { return str(); } + // Extra operators. - SmallString &operator+=(const char *RHS) { - this->append(RHS, RHS+strlen(RHS)); + const SmallString &operator=(StringRef RHS) { + this->clear(); + return *this += RHS; + } + + SmallString &operator+=(StringRef RHS) { + this->append(RHS.begin(), RHS.end()); + return *this; + } + SmallString &operator+=(char C) { + this->push_back(C); return *this; } }; - - + } #endif