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());
73 StringRef substr(
size_t pos,
size_t n=std::string::npos)
const
75 if (n==std::string::npos) {
76 assert(pos>=0 && begin_+pos<=end_);
77 return StringRef(begin_+pos, this->length()-pos);
79 assert(pos>=0 && begin_+pos+n<=end_);
83 std::string str()
const
85 return std::string(begin_, end_-begin_);
89 assert(!this->empty());
93 const char&
operator[](
int index)
const {
return begin_[index]; }
96 return this->length()==rhs.
length() &&
97 !memcmp(rhs.
data(), this->data(), this->size());
106 while(--s>begin_ && isspace(*s)) {
112 const char* s=begin_;
113 while(s<end_ && isspace(*s)) {
120 return this->rtrim().
ltrim();
127 std::pair<bool, int> to_int()
const;
133 std::pair<bool, float> to_float()
const;
135 bool empty()
const {
return begin_==end_; }
138 std::vector<StringRef> split(
char p)
const;