2006-10-30 04:39:20 +01:00
|
|
|
//===- llvm/ADT/SmallString.h - 'Normally small' strings --------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-10-30 04:39:20 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the SmallString class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ADT_SMALLSTRING_H
|
|
|
|
#define LLVM_ADT_SMALLSTRING_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-08-19 21:57:55 +02:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2006-10-30 04:39:20 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
/// SmallString - A SmallString is just a SmallVector with methods and accessors
|
|
|
|
/// that make it work better as a string (e.g. operator+ etc).
|
|
|
|
template<unsigned InternalLen>
|
|
|
|
class SmallString : public SmallVector<char, InternalLen> {
|
|
|
|
public:
|
|
|
|
// Default ctor - Initialize to empty.
|
|
|
|
SmallString() {}
|
|
|
|
|
|
|
|
// Initialize with a range.
|
|
|
|
template<typename ItTy>
|
|
|
|
SmallString(ItTy S, ItTy E) : SmallVector<char, InternalLen>(S, E) {}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2006-10-30 04:39:20 +01:00
|
|
|
// Copy ctor.
|
|
|
|
SmallString(const SmallString &RHS) : SmallVector<char, InternalLen>(RHS) {}
|
|
|
|
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2006-10-30 04:39:20 +01:00
|
|
|
// Extra methods.
|
2009-08-19 21:57:55 +02:00
|
|
|
StringRef str() const { return StringRef(this->begin(), this->size()); }
|
|
|
|
|
2009-11-21 03:01:24 +01:00
|
|
|
// Implicit conversion to StringRef.
|
|
|
|
operator StringRef() const { return str(); }
|
|
|
|
|
2009-09-20 01:57:31 +02:00
|
|
|
const char *c_str() {
|
|
|
|
this->push_back(0);
|
|
|
|
this->pop_back();
|
|
|
|
return this->data();
|
|
|
|
}
|
2009-11-21 03:01:24 +01:00
|
|
|
|
2006-10-30 04:39:20 +01:00
|
|
|
// Extra operators.
|
2009-08-22 08:06:46 +02:00
|
|
|
const SmallString &operator=(StringRef RHS) {
|
2008-11-20 08:09:17 +01:00
|
|
|
this->clear();
|
|
|
|
return *this += RHS;
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2009-08-22 08:06:46 +02:00
|
|
|
SmallString &operator+=(StringRef RHS) {
|
|
|
|
this->append(RHS.begin(), RHS.end());
|
2006-10-30 04:39:20 +01:00
|
|
|
return *this;
|
|
|
|
}
|
2007-04-23 22:58:14 +02:00
|
|
|
SmallString &operator+=(char C) {
|
|
|
|
this->push_back(C);
|
|
|
|
return *this;
|
|
|
|
}
|
2006-10-30 04:39:20 +01:00
|
|
|
};
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2006-10-30 04:39:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|