Go to the documentation of this file.
141 #ifndef GOOGLE_PROTOBUF_STUBS_STRINGPIECE_H_
142 #define GOOGLE_PROTOBUF_STUBS_STRINGPIECE_H_
151 #if defined(__cpp_lib_string_view)
152 #include <string_view>
155 #include <google/protobuf/stubs/hash.h>
157 #include <google/protobuf/port_def.inc>
161 namespace stringpiece_internal {
186 #if !defined(NDEBUG) || defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
187 if (PROTOBUF_PREDICT_FALSE(
size > kMaxSize)) {
190 LogFatalSizeTooBig(
size,
"string length exceeds max size");
197 static void LogFatalSizeTooBig(size_type
size,
const char*
details);
210 if (
str !=
nullptr) {
211 length_ = CheckSize(strlen(
str));
215 template <
class Allocator>
217 const std::basic_string<
char, std::char_traits<char>, Allocator>&
str)
219 length_ = CheckSize(
str.size());
222 #if defined(__cpp_lib_string_view)
226 length_ = CheckSize(
str.size());
240 bool empty()
const {
return length_ == 0; }
248 assert(length_ >=
n);
254 assert(length_ >=
n);
260 size_type min_size = length_ <
x.length_ ? length_ :
x.length_;
261 int r = memcmp(
ptr_,
x.ptr_,
static_cast<size_t>(min_size));
262 if (
r < 0)
return -1;
264 if (length_ <
x.length_)
return -1;
265 if (length_ >
x.length_)
return 1;
276 if (
ptr_ ==
nullptr)
return "";
286 return (length_ >=
x.length_) &&
287 (memcmp(
ptr_,
x.ptr_,
static_cast<size_t>(
x.length_)) == 0);
291 return ((length_ >=
x.length_) &&
292 (memcmp(
ptr_ + (length_-
x.length_),
x.ptr_,
293 static_cast<size_t>(
x.length_)) == 0));
317 size_type
copy(
char*
buf, size_type n, size_type
pos = 0)
const;
322 size_type
find(
char c, size_type
pos = 0)
const;
324 size_type rfind(
char c, size_type
pos = npos)
const;
330 size_type find_first_not_of(
StringPiece s, size_type
pos = 0)
const;
331 size_type find_first_not_of(
char c, size_type
pos = 0)
const;
332 size_type find_last_of(
StringPiece s, size_type
pos = npos)
const;
334 return rfind(c,
pos);
336 size_type find_last_not_of(
StringPiece s, size_type
pos = npos)
const;
337 size_type find_last_not_of(
char c, size_type
pos = npos)
const;
347 if (
len !=
y.size()) {
351 return x.data() ==
y.data() ||
len <= 0 ||
352 memcmp(
x.data(),
y.data(),
static_cast<size_t>(
len)) == 0;
361 x.size() <
y.size() ?
x.size() :
y.size();
362 const int r = memcmp(
x.data(),
y.data(),
static_cast<size_t>(min_size));
363 return (
r < 0) || (
r == 0 &&
x.size() <
y.size());
383 using ::google::protobuf::stringpiece_internal::StringPiece;
389 template<>
struct hash<StringPiece> {
400 #include <google/protobuf/port_undef.inc>
402 #endif // STRINGS_STRINGPIECE_H_
std::ptrdiff_t difference_type
std::char_traits< char > traits_type
size_t operator()(const StringPiece &s) const
bool operator<=(StringPiece x, StringPiece y)
std::string ToString() const
static void ** find(grpc_chttp2_stream_map *map, uint32_t key)
bool starts_with(StringPiece x) const
const_pointer data() const
static int copy(grpc_slice_buffer *input, grpc_slice_buffer *output)
void remove_prefix(size_type n)
const_iterator end() const
void Consume(CordRep *rep, ConsumeFn consume_fn)
#define GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END
const_reverse_iterator rend() const
bool operator>=(StringPiece x, StringPiece y)
bool operator<(StringPiece x, StringPiece y)
#define GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_START
bool ends_with(StringPiece x) const
StringPiece(const std::basic_string< char, std::char_traits< char >, Allocator > &str)
char operator[](size_type i) const
std::string ToString(const grpc::string_ref &r)
int compare(StringPiece x) const
const_iterator begin() const
size_type max_size() const
bool operator==(StringPiece x, StringPiece y)
const char * const_pointer
static grpc_slice details
bool operator!=(StringPiece x, StringPiece y)
bool operator>(StringPiece x, StringPiece y)
size_type find_last_of(char c, size_type pos=npos) const
std::ostream & operator<<(std::ostream &o, StringPiece piece)
StringPiece(const char *str)
const char & const_reference
absl::string_view string_view
std::reverse_iterator< const_iterator > const_reverse_iterator
void remove_suffix(size_type n)
static size_type CheckSize(size_type size)
const_reverse_iterator reverse_iterator
const char * const_iterator
static int contains(grpc_timer_heap *pq, grpc_timer *el)
const_reverse_iterator rbegin() const
StringPiece(const char *offset, size_type len)
static const size_type npos
size_type capacity() const
size_type find_first_of(char c, size_type pos=0) const
std::string as_string() const
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:22