LLVM API Documentation
00001 //===- llvm/ADT/SmallString.h - 'Normally small' strings --------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the SmallString class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_ADT_SMALLSTRING_H 00015 #define LLVM_ADT_SMALLSTRING_H 00016 00017 #include "llvm/ADT/SmallVector.h" 00018 #include "llvm/ADT/StringRef.h" 00019 #include "llvm/Support/DataTypes.h" 00020 #include <cstring> 00021 00022 namespace llvm { 00023 00024 /// SmallString - A SmallString is just a SmallVector with methods and accessors 00025 /// that make it work better as a string (e.g. operator+ etc). 00026 template<unsigned InternalLen> 00027 class SmallString : public SmallVector<char, InternalLen> { 00028 public: 00029 // Default ctor - Initialize to empty. 00030 SmallString() {} 00031 00032 // Initialize with a range. 00033 template<typename ItTy> 00034 SmallString(ItTy S, ItTy E) : SmallVector<char, InternalLen>(S, E) {} 00035 00036 // Copy ctor. 00037 SmallString(const SmallString &RHS) : SmallVector<char, InternalLen>(RHS) {} 00038 00039 00040 // Extra methods. 00041 StringRef str() const { return StringRef(this->begin(), this->size()); } 00042 00043 // Extra operators. 00044 const SmallString &operator=(StringRef RHS) { 00045 this->clear(); 00046 return *this += RHS; 00047 } 00048 00049 SmallString &operator+=(StringRef RHS) { 00050 this->append(RHS.begin(), RHS.end()); 00051 return *this; 00052 } 00053 SmallString &operator+=(char C) { 00054 this->push_back(C); 00055 return *this; 00056 } 00057 }; 00058 00059 00060 } 00061 00062 #endif