19#ifndef OST_STRING_REF_HH
20#define OST_STRING_REF_HH
46 StringRef(
const char* begin,
size_t len): begin_(begin), end_(begin+len) { }
50 const char*
begin()
const {
return begin_; }
51 const char*
end()
const {
return end_; }
52 const char*
data()
const {
return begin_; }
54 size_t size()
const {
return end_-begin_; }
55 size_t length()
const {
return this->size(); }
59 assert(!this->empty());
86 if (n==std::string::npos) {
87 assert(begin_+pos<=end_);
88 return StringRef(begin_+pos, this->length()-pos);
90 assert(begin_+pos+n<=end_);
94 std::string
str()
const
96 return std::string(begin_, end_-begin_);
100 assert(!this->empty());
104 const char&
operator[](
int index)
const {
return begin_[index]; }
107 return this->length()==rhs.
length() &&
108 !memcmp(rhs.
data(), this->data(), this->size());
112 return !this->operator==(rhs);
117 while(--s>=begin_ && isspace(*s)) {
123 const char* s=begin_;
124 while(s<end_ && isspace(*s)) {
131 return this->rtrim().
ltrim();
146 bool empty()
const {
return begin_==end_; }
149 std::vector<StringRef>
split(
char p)
const;
152 std::vector<StringRef>
split()
const;
convenient datatype for referencing character data
bool operator==(const StringRef &rhs) const
const char * begin() const
const char * const_iterator
const_iterator find(char p) const
find character in StringRef
std::pair< bool, float > to_float() const
convert to float
StringRef trim() const
strip space characters on the left and the right
std::vector< StringRef > split(char p) const
split string into chunks delimited by p
StringRef substr(size_t pos, size_t n=std::string::npos) const
returns a substring of the string
const char * data() const
std::string str_no_whitespace() const
returns a new string with all whitespace removed from this StringRef
std::pair< bool, int > to_int() const
convert to integer
StringRef rtrim() const
strip space characters on the right
std::vector< StringRef > split() const
split string into chunks delimited by whitespace
bool operator!=(const StringRef &rhs) const
StringRef ltrim() const
strip space characters on the left
const char & operator[](int index) const
StringRef(const char *begin, size_t len)
#define DLLEXPORT_OST_BASE
DLLEXPORT_OST_BASE std::ostream & operator<<(std::ostream &stream, const StringRef &strref)