Go to the documentation of this file.
19 #ifndef GRPCPP_SUPPORT_STRING_REF_H
20 #define GRPCPP_SUPPORT_STRING_REF_H
52 : data_(other.data_), length_(other.length_) {}
56 length_ = rhs.length_;
61 string_ref(
const char* s) : data_(s), length_(strlen(s)) {}
62 string_ref(
const char* s,
size_t l) : data_(s), length_(l) {}
85 size_t size()
const {
return length_; }
86 size_t length()
const {
return length_; }
88 bool empty()
const {
return length_ == 0; }
91 const char*
data()
const {
return data_; }
95 size_t min_size = length_ < x.length_ ? length_ : x.length_;
96 int r = memcmp(data_, x.data_, min_size);
99 if (length_ < x.length_)
return -1;
100 if (length_ > x.length_)
return 1;
105 return length_ >= x.length_ && (memcmp(data_, x.data_, x.length_) == 0);
109 return length_ >= x.length_ &&
110 (memcmp(data_ + (length_ - x.length_), x.data_, x.length_) == 0);
124 if (pos > length_) pos = length_;
125 if (n > (length_ - pos)) n = length_ - pos;
143 return out << std::string(
string.begin(),
string.end());
148 #endif // GRPCPP_SUPPORT_STRING_REF_H
bool ends_with(string_ref x) const
Definition: string_ref.h:108
This class is a non owning reference to a string.
Definition: string_ref.h:40
string_ref(const char *s, size_t l)
Definition: string_ref.h:62
bool operator==(string_ref x, string_ref y)
Comparison operators.
Definition: string_ref.h:135
const typedef char * const_iterator
types
Definition: string_ref.h:43
bool empty() const
Definition: string_ref.h:88
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
bool starts_with(string_ref x) const
Definition: string_ref.h:104
string_ref & operator=(const string_ref &rhs)
Definition: string_ref.h:54
int compare(string_ref x) const
string operations
Definition: string_ref.h:94
size_t find(string_ref s) const
Definition: string_ref.h:113
const_iterator cend() const
Definition: string_ref.h:70
bool operator>=(string_ref x, string_ref y)
Definition: string_ref.h:140
bool operator<(string_ref x, string_ref y)
Definition: string_ref.h:137
string_ref(const string_ref &other)
Definition: string_ref.h:51
bool operator<=(string_ref x, string_ref y)
Definition: string_ref.h:138
string_ref(const char *s)
Definition: string_ref.h:61
const_reverse_iterator rbegin() const
Definition: string_ref.h:71
string_ref substr(size_t pos, size_t n=npos) const
Definition: string_ref.h:123
bool operator>(string_ref x, string_ref y)
Definition: string_ref.h:139
const_iterator end() const
Definition: string_ref.h:68
size_t length() const
Definition: string_ref.h:86
const_iterator begin() const
iterators
Definition: string_ref.h:67
string_ref()
construct/copy.
Definition: string_ref.h:50
bool operator!=(string_ref x, string_ref y)
Definition: string_ref.h:136
const char * data() const
element access
Definition: string_ref.h:91
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: string_ref.h:44
const_iterator cbegin() const
Definition: string_ref.h:69
string_ref(const std::string &s)
Definition: string_ref.h:64
const_reverse_iterator crbegin() const
Definition: string_ref.h:77
const_reverse_iterator rend() const
Definition: string_ref.h:74
size_t size() const
capacity
Definition: string_ref.h:85
size_t find(char c) const
Definition: string_ref.h:118
const_reverse_iterator crend() const
Definition: string_ref.h:80
std::ostream & operator<<(std::ostream &out, const string_ref &string)
Definition: string_ref.h:142
const static size_t npos
constants
Definition: string_ref.h:47
size_t max_size() const
Definition: string_ref.h:87