Home | History | Annotate | Download | only in stubs

Lines Matching defs:StringPiece

31 // A StringPiece points to part or all of a string, Cord, double-quoted string
32 // literal, or other string-like object. A StringPiece does *not* own the
33 // string to which it points. A StringPiece is not null-terminated.
35 // You can use StringPiece as a function or method parameter. A StringPiece
37 // char*" argument, a string argument, or a StringPiece argument with no data
38 // copying. Systematic use of StringPiece for arguments reduces data
42 // void MyFunction(StringPiece arg);
44 // void MyFunction(const StringPiece& arg); // not preferred
49 // StringPiece is also suitable for local variables if you know that
51 // of your StringPiece variable.
53 // Beware of binding a StringPiece to a temporary:
54 // StringPiece sp = obj.MethodReturningString(); // BAD: lifetime problem
58 // StringPiece sp(str); // GOOD, because str outlives sp
60 // StringPiece is sometimes a poor choice for a return value and usually a poor
61 // choice for a data member. If you do use a StringPiece this way, it is your
62 // responsibility to ensure that the object pointed to by the StringPiece
63 // outlives the StringPiece.
65 // A StringPiece may represent just part of a string; thus the name "Piece".
66 // For example, when splitting a string, vector<StringPiece> is a natural data
69 // that iteratively provides StringPiece objects that point to the
72 // A StringPiece is not null-terminated. If you write code that scans a
73 // StringPiece, you must check its length before reading any characters.
75 // StringPiece objects.
77 // There are several ways to create a null StringPiece:
78 // StringPiece()
79 // StringPiece(NULL)
80 // StringPiece(NULL, 0)
82 // and sp.empty() == true. Also, if you create a StringPiece with
87 // Thus, you can use StringPiece(NULL) to signal an out-of-band value
88 // that is different from other StringPiece values. This is similar
92 // There are many ways to create an empty StringPiece:
93 // StringPiece()
94 // StringPiece(NULL)
95 // StringPiece(NULL, 0)
96 // StringPiece("")
97 // StringPiece("", 0)
98 // StringPiece("abcdef", 0)
99 // StringPiece("abcdef"+6, 0)
101 // For some empty StringPiece values, sp.data() will be NULL.
102 // For some empty StringPiece values, sp.data() will not be NULL.
104 // Be careful not to confuse: null StringPiece and empty StringPiece.
106 // That is, every null StringPiece is an empty StringPiece,
109 // All empty StringPiece values compare equal to each other.
110 // Even a null StringPieces compares equal to a non-null empty StringPiece:
111 // StringPiece() == StringPiece("", 0)
112 // StringPiece(NULL) == StringPiece("abc", 0)
113 // StringPiece(NULL, 0) == StringPiece("abcdef"+6, 0)
116 // StringPiece("") == NULL
117 // True or false? TRUE, because StringPiece::operator== converts
118 // the right-hand side from NULL to StringPiece(NULL),
123 // bool TestWhat?(StringPiece sp) { return sp == NULL; } // BAD
125 // bool TestNull(StringPiece sp) { return sp.data() == NULL; }
126 // bool TestEmpty(StringPiece sp) { return sp.empty(); }
131 // TestEmpty is good to test for an empty StringPiece.
135 // must be longer than the lifetime of the StringPiece.
137 // StringPiece data.
138 // (3) A null StringPiece is empty.
139 // An empty StringPiece may or may not be a null StringPiece.
156 // StringPiece has *two* size types.
157 // StringPiece::size_type
178 class LIBPROTOBUF_EXPORT StringPiece {
205 // in a "const char*" or a "string" wherever a "StringPiece" is
210 StringPiece() : ptr_(NULL), length_(0) {}
212 StringPiece(const char* str) // NOLINT(runtime/explicit)
220 StringPiece( // NOLINT(runtime/explicit)
227 StringPiece( // NOLINT(runtime/explicit)
234 StringPiece(const char* offset, stringpiece_ssize_type len)
239 // Substring of another StringPiece.
241 StringPiece(StringPiece x, stringpiece_ssize_type pos);
242 // Substring of another StringPiece.
245 StringPiece(StringPiece x,
300 int compare(StringPiece x) const {
317 // for a StringPiece be called "as_string()". We also leave the
331 bool starts_with(StringPiece x) const {
335 bool ends_with(StringPiece x) const {
340 // Checks whether StringPiece starts with x and if so advances the beginning
343 bool Consume(StringPiece x);
345 bool ConsumeFromEnd(StringPiece x);
373 bool contains(StringPiece s) const;
375 stringpiece_ssize_type find(StringPiece s, size_type pos = 0) const;
377 stringpiece_ssize_type rfind(StringPiece s, size_type pos = npos) const;
380 stringpiece_ssize_type find_first_of(StringPiece s, size_type pos = 0) const;
384 stringpiece_ssize_type find_first_not_of(StringPiece s,
387 stringpiece_ssize_type find_last_of(StringPiece s,
392 stringpiece_ssize_type find_last_not_of(StringPiece s,
396 StringPiece substr(size_type pos, size_type n = npos) const;
402 inline bool operator==(StringPiece x, StringPiece y) {
412 inline bool operator!=(StringPiece x, StringPiece y) {
416 inline bool operator<(StringPiece x, StringPiece y) {
423 inline bool operator>(StringPiece x, StringPiece y) {
427 inline bool operator<=(StringPiece x, StringPiece y) {
431 inline bool operator>=(StringPiece x, StringPiece y) {
435 // allow StringPiece to be logged
436 extern std::ostream& operator<<(std::ostream& o, StringPiece piece);
439 // StringPiece
442 // Create from a StringPiece.
443 static StringPiecePod CreateFromStringPiece(StringPiece str) {
450 // Cast to StringPiece.
451 operator StringPiece() const { return StringPiece(data_, size_); }
454 return StringPiece(data_, size_) == StringPiece(value);
480 template<> struct hash<StringPiece> {
481 size_t operator()(const StringPiece& s) const {