34 #ifndef GRPCXX_IMPL_CODEGEN_STRING_REF_H 35 #define GRPCXX_IMPL_CODEGEN_STRING_REF_H 68 : data_(other.data_), length_(other.length_) {}
71 length_ = rhs.length_;
75 string_ref(
const char* s) : data_(s), length_(strlen(s)) {}
76 string_ref(
const char* s,
size_t l) : data_(s), length_(l) {}
80 const_iterator
begin()
const {
return data_; }
81 const_iterator
end()
const {
return data_ + length_; }
82 const_iterator
cbegin()
const {
return data_; }
83 const_iterator
cend()
const {
return data_ + length_; }
84 const_reverse_iterator
rbegin()
const {
87 const_reverse_iterator
rend()
const {
93 const_reverse_iterator
crend()
const {
98 size_t size()
const {
return length_; }
99 size_t length()
const {
return length_; }
101 bool empty()
const {
return length_ == 0; }
104 const char*
data()
const {
return data_; }
108 size_t min_size = length_ < x.length_ ? length_ : x.length_;
109 int r = memcmp(data_, x.data_, min_size);
110 if (r < 0)
return -1;
112 if (length_ < x.length_)
return -1;
113 if (length_ > x.length_)
return 1;
118 return length_ >= x.length_ && (memcmp(data_, x.data_, x.length_) == 0);
122 return length_ >= x.length_ &&
123 (memcmp(data_ + (length_ - x.length_), x.data_, x.length_) == 0);
128 return it ==
cend() ? npos : std::distance(
cbegin(), it);
133 return it ==
cend() ? npos : std::distance(
cbegin(), it);
137 if (pos > length_) pos = length_;
138 if (n > (length_ - pos)) n = length_ - pos;
161 #endif // GRPCXX_IMPL_CODEGEN_STRING_REF_H size_t max_size() const
Definition: string_ref.h:100
const_iterator cend() const
Definition: string_ref.h:83
const_reverse_iterator crend() const
Definition: string_ref.h:93
const_iterator cbegin() const
Definition: string_ref.h:82
std::string string
Definition: config.h:118
size_t find(char c) const
Definition: string_ref.h:131
size_t size() const
Definition: string_ref.h:98
string_ref(const string_ref &other)
Definition: string_ref.h:67
size_t find(string_ref s) const
Definition: string_ref.h:126
const_reverse_iterator crbegin() const
Definition: string_ref.h:90
const char * const_iterator
Definition: string_ref.h:59
string_ref(const char *s)
Definition: string_ref.h:75
const_reverse_iterator rbegin() const
Definition: string_ref.h:84
string_ref(const char *s, size_t l)
Definition: string_ref.h:76
string_ref(const grpc::string &s)
Definition: string_ref.h:77
const char * data() const
Definition: string_ref.h:104
const_iterator end() const
Definition: string_ref.h:81
std::ostream & operator<<(std::ostream &out, const string_ref &string)
Definition: string_ref.h:155
string_ref()
Definition: string_ref.h:66
bool operator<(string_ref x, string_ref y)
Definition: string_ref.h:150
string_ref & operator=(const string_ref &rhs)
Definition: string_ref.h:69
static const size_t npos
Definition: string_ref.h:63
bool operator<=(string_ref x, string_ref y)
Definition: string_ref.h:151
bool operator>(string_ref x, string_ref y)
Definition: string_ref.h:152
const_reverse_iterator rend() const
Definition: string_ref.h:87
This class is a non owning reference to a string.
Definition: string_ref.h:56
bool starts_with(string_ref x) const
Definition: string_ref.h:117
bool empty() const
Definition: string_ref.h:101
bool operator==(string_ref x, string_ref y)
Definition: string_ref.h:148
bool ends_with(string_ref x) const
Definition: string_ref.h:121
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: string_ref.h:60
const_iterator begin() const
Definition: string_ref.h:80
bool operator!=(string_ref x, string_ref y)
Definition: string_ref.h:149
string_ref substr(size_t pos, size_t n=npos) const
Definition: string_ref.h:136
bool operator>=(string_ref x, string_ref y)
Definition: string_ref.h:153
int compare(string_ref x) const
Definition: string_ref.h:107
size_t length() const
Definition: string_ref.h:99