19 #ifndef OST_STRING_REF_HH
20 #define OST_STRING_REF_HH
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());
84 StringRef substr(
size_t pos,
size_t n=std::string::npos)
const
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());
117 while(--s>begin_ && isspace(*s)) {
123 const char* s=begin_;
124 while(s<end_ && isspace(*s)) {
131 return this->rtrim().
ltrim();
138 std::pair<bool, int> to_int()
const;
144 std::pair<bool, float> to_float()
const;
146 bool empty()
const {
return begin_==end_; }
149 std::vector<StringRef> split(
char p)
const;
152 std::vector<StringRef> split()
const;
156 std::string str_no_whitespace()
const;