SmallString.h revision dddfd34e32ff081409e5a1c95b991a898d63dff2
1//===- llvm/ADT/SmallString.h - 'Normally small' strings --------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the SmallString class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ADT_SMALLSTRING_H
15#define LLVM_ADT_SMALLSTRING_H
16
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/DataTypes.h"
20#include <cstring>
21
22namespace llvm {
23
24/// SmallString - A SmallString is just a SmallVector with methods and accessors
25/// that make it work better as a string (e.g. operator+ etc).
26template<unsigned InternalLen>
27class SmallString : public SmallVector<char, InternalLen> {
28public:
29  // Default ctor - Initialize to empty.
30  SmallString() {}
31
32  // Initialize with a range.
33  template<typename ItTy>
34  SmallString(ItTy S, ItTy E) : SmallVector<char, InternalLen>(S, E) {}
35
36  // Copy ctor.
37  SmallString(const SmallString &RHS) : SmallVector<char, InternalLen>(RHS) {}
38
39
40  // Extra methods.
41  StringRef str() const { return StringRef(this->begin(), this->size()); }
42
43  // Extra operators.
44  const SmallString &operator=(const char *RHS) {
45    this->clear();
46    return *this += RHS;
47  }
48
49  SmallString &operator+=(const char *RHS) {
50    this->append(RHS, RHS+strlen(RHS));
51    return *this;
52  }
53  SmallString &operator+=(char C) {
54    this->push_back(C);
55    return *this;
56  }
57};
58
59
60}
61
62#endif
63