Go to the documentation of this file.
141 #ifndef GOOGLE_PROTOBUF_STUBS_STRINGPIECE_H_
142 #define GOOGLE_PROTOBUF_STUBS_STRINGPIECE_H_
154 #include <google/protobuf/port_def.inc>
173 #define STRINGPIECE_CHECK_SIZE 1
174 #elif defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
175 #define STRINGPIECE_CHECK_SIZE 1
177 #define STRINGPIECE_CHECK_SIZE 0
188 #if STRINGPIECE_CHECK_SIZE > 0
192 if (
size >
static_cast<size_t>(
193 std::numeric_limits<stringpiece_ssize_type>::max())) {
196 LogFatalSizeTooBig(
size,
"size_t to int conversion");
203 static void LogFatalSizeTooBig(
size_t size,
const char* details);
215 : ptr_(
str), length_(0) {
216 if (
str !=
nullptr) {
217 length_ = CheckedSsizeTFromSizeT(strlen(
str));
221 template <
class Allocator>
223 const std::basic_string<
char, std::char_traits<char>, Allocator>&
str)
224 : ptr_(
str.
data()), length_(0) {
225 length_ = CheckedSsizeTFromSizeT(
str.size());
247 const char*
data()
const {
return ptr_; }
250 bool empty()
const {
return length_ == 0; }
266 length_ = CheckedSsizeTFromSizeT(strlen(
str));
272 ptr_ =
reinterpret_cast<const char*
>(
data);
283 assert(length_ >=
n);
289 assert(length_ >=
n);
296 length_ <
x.length_ ? length_ :
x.length_;
297 int r = memcmp(ptr_,
x.ptr_,
static_cast<size_t>(min_size));
298 if (
r < 0)
return -1;
300 if (length_ <
x.length_)
return -1;
301 if (length_ >
x.length_)
return 1;
314 if (ptr_ ==
nullptr)
return string();
322 void CopyToString(
string*
target)
const;
323 void AppendToString(
string*
target)
const;
326 return (length_ >=
x.length_) &&
327 (memcmp(ptr_,
x.ptr_,
static_cast<size_t>(
x.length_)) == 0);
331 return ((length_ >=
x.length_) &&
332 (memcmp(ptr_ + (length_-
x.length_),
x.ptr_,
333 static_cast<size_t>(
x.length_)) == 0));
355 iterator
begin()
const {
return ptr_; }
356 iterator
end()
const {
return ptr_ + length_; }
381 size_type pos = 0)
const;
384 size_type pos = npos)
const;
386 return rfind(c, pos);
389 size_type pos = npos)
const;
392 StringPiece substr(size_type pos, size_type
n = npos)
const;
400 if (
len !=
y.size()) {
404 return x.data() ==
y.data() ||
len <= 0 ||
405 memcmp(
x.data(),
y.data(),
static_cast<size_t>(
len)) == 0;
414 x.size() <
y.size() ?
x.size() :
y.size();
415 const int r = memcmp(
x.data(),
y.data(),
static_cast<size_t>(min_size));
416 return (
r < 0) || (
r == 0 &&
x.size() <
y.size());
432 extern std::ostream&
operator<<(std::ostream& o, StringPiece piece);
481 template<>
struct hash<StringPiece> {
485 result = 5 * result +
static_cast<size_t>(*str);
492 #include <google/protobuf/port_undef.inc>
494 #endif // STRINGS_STRINGPIECE_H_
static StringPiecePod CreateFromStringPiece(StringPiece str)
stringpiece_ssize_type size_
size_t operator()(const StringPiece &s) const
StringPiece(const std::basic_string< char, std::char_traits< char >, Allocator > &str)
bool operator>=(StringPiece x, StringPiece y)
stringpiece_ssize_type length() const
string::difference_type stringpiece_ssize_type
stringpiece_ssize_type find_first_of(char c, size_type pos=0) const
#define GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END
const char * data() const
bool ends_with(StringPiece x) const
stringpiece_ssize_type max_size() const
const typedef char * const_iterator
GLsizei const GLchar *const * string
StringPiece(const char *offset, stringpiece_ssize_type len)
stringpiece_ssize_type find_last_of(char c, size_type pos=npos) const
const typedef char * iterator
bool operator>(StringPiece x, StringPiece y)
static const size_type npos
void set(const char *data, stringpiece_ssize_type len)
const char * data() const
int compare(StringPiece x) const
char operator[](stringpiece_ssize_type i) const
std::reverse_iterator< iterator > reverse_iterator
void set(const char *str)
#define GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_START
ptrdiff_t difference_type
const_reverse_iterator rend() const
bool starts_with(StringPiece x) const
const typedef char & const_reference
bool operator<=(StringPiece x, StringPiece y)
static stringpiece_ssize_type CheckedSsizeTFromSizeT(size_t size)
std::string ToString() const
std::ostream & operator<<(std::ostream &o, const uint128 &b)
GLenum GLuint GLenum GLsizei const GLchar * buf
void remove_prefix(stringpiece_ssize_type n)
stringpiece_ssize_type capacity() const
StringPiece(const char *str)
stringpiece_ssize_type length_
void remove_suffix(stringpiece_ssize_type n)
void set(const void *data, stringpiece_ssize_type len)
const typedef char * pointer
const typedef char & reference
bool operator==(const uint128 &lhs, const uint128 &rhs)
bool operator!=(const uint128 &lhs, const uint128 &rhs)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLsizei const GLfloat * value
stringpiece_ssize_type size() const
char operator[](stringpiece_ssize_type i) const
bool operator<(StringPiece x, StringPiece y)
stringpiece_ssize_type size() const
const_reverse_iterator rbegin() const
std::reverse_iterator< const_iterator > const_reverse_iterator
bool operator==(const char *value) const
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59