1 //===- llvm/ADT/SmallString.h - 'Normally small' strings --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the SmallString class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ADT_SMALLSTRING_H
15 #define LLVM_ADT_SMALLSTRING_H
17 #include "llvm/ADT/SmallVector.h"
22 /// SmallString - A SmallString is just a SmallVector with methods and accessors
23 /// that make it work better as a string (e.g. operator+ etc).
24 template<unsigned InternalLen>
25 class SmallString : public SmallVector<char, InternalLen> {
27 // Default ctor - Initialize to empty.
30 // Initialize with a range.
31 template<typename ItTy>
32 SmallString(ItTy S, ItTy E) : SmallVector<char, InternalLen>(S, E) {}
35 SmallString(const SmallString &RHS) : SmallVector<char, InternalLen>(RHS) {}
39 const char *c_str() const {
40 SmallString *This = const_cast<SmallString*>(this);
41 // Ensure that there is a \0 at the end of the string.
42 This->reserve(this->size()+1);
48 SmallString &operator+=(const char *RHS) {
49 this->append(RHS, RHS+strlen(RHS));
52 SmallString &operator+=(char C) {