2006-10-30 03:39:20 +00:00
|
|
|
//===- llvm/ADT/SmallString.h - 'Normally small' strings --------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-10-30 03:39:20 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the SmallString class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ADT_SMALLSTRING_H
|
|
|
|
#define LLVM_ADT_SMALLSTRING_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
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) {}
|
|
|
|
|
|
|
|
// Copy ctor.
|
|
|
|
SmallString(const SmallString &RHS) : SmallVector<char, InternalLen>(RHS) {}
|
|
|
|
|
|
|
|
|
|
|
|
// Extra methods.
|
|
|
|
const char *c_str() const {
|
|
|
|
SmallString *This = const_cast<SmallString*>(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();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extra operators.
|
|
|
|
SmallString &operator+=(const char *RHS) {
|
|
|
|
this->append(RHS, RHS+strlen(RHS));
|
|
|
|
return *this;
|
|
|
|
}
|
2007-04-23 20:58:14 +00:00
|
|
|
SmallString &operator+=(char C) {
|
|
|
|
this->push_back(C);
|
|
|
|
return *this;
|
|
|
|
}
|
2008-04-16 04:05:02 +00:00
|
|
|
|
|
|
|
SmallString &append_uint_32(uint32_t N) {
|
|
|
|
char Buffer[20];
|
2008-04-16 04:10:37 +00:00
|
|
|
char *BufPtr = Buffer+20;
|
2008-04-16 04:05:02 +00:00
|
|
|
|
|
|
|
if (N == 0) *--BufPtr = '0'; // Handle special case.
|
|
|
|
|
|
|
|
while (N) {
|
|
|
|
*--BufPtr = '0' + char(N % 10);
|
|
|
|
N /= 10;
|
|
|
|
}
|
|
|
|
this->append(BufPtr, Buffer+20);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallString &append_uint(uint64_t N) {
|
|
|
|
if (N == uint32_t(N))
|
|
|
|
return append_uint_32(uint32_t(N));
|
|
|
|
|
|
|
|
char Buffer[40];
|
2008-04-16 04:10:37 +00:00
|
|
|
char *BufPtr = Buffer+40;
|
2008-04-16 04:05:02 +00:00
|
|
|
|
|
|
|
if (N == 0) *--BufPtr = '0'; // Handle special case...
|
|
|
|
|
|
|
|
while (N) {
|
|
|
|
*--BufPtr = '0' + char(N % 10);
|
|
|
|
N /= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->append(BufPtr, Buffer+40);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallString &append_sint(int64_t N) {
|
|
|
|
// TODO, wrong for minint64.
|
|
|
|
if (N < 0) {
|
|
|
|
this->push_back('-');
|
|
|
|
N = -N;
|
|
|
|
}
|
|
|
|
return append_uint(N);
|
|
|
|
}
|
2007-04-23 20:58:14 +00:00
|
|
|
|
2006-10-30 03:39:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|