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());
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;
convenient datatype for referencing character data
StringRef(const char *begin, size_t len)
const char * begin() const
bool DLLEXPORT_OST_GEOM operator==(const Line2 &l1, const Line2 &l2)
const char * const_iterator
bool operator!=(const StringRef &rhs) const
pointer_it< T > begin(const std::vector< T > &values)
StringRef rtrim() const
strip space characters on the right
StringRef substr(size_t pos, size_t n=std::string::npos) const
returns a substring of the string
const char & operator[](int index) const
const_iterator find(char p) const
find character in StringRef
bool operator==(const StringRef &rhs) const
DLLEXPORT_OST_BASE std::ostream & operator<<(std::ostream &stream, const StringRef &strref)
#define DLLEXPORT_OST_BASE
const char * data() const
StringRef ltrim() const
strip space characters on the left
StringRef trim() const
strip space characters on the left and the right