18 #include <strings/StringPiece.h> 25 std::ostream& operator<<(std::ostream& o, StringPiece piece) {
26 o.write(piece.data(), piece.size());
30 bool StringPiece::contains(StringPiece s)
const {
31 return std::search(begin(), end(), s.begin(), s.end()) != end();
34 size_t StringPiece::find(
char c,
size_t pos)
const {
39 reinterpret_cast<const char*
>(memchr(data_ + pos, c, size_ - pos));
40 return result != NULL ? result - data_ : npos;
44 size_t StringPiece::rfind(
char c,
size_t pos)
const {
45 if (size_ == 0)
return npos;
46 for (
const char* p = data_ + std::min(pos, size_ - 1); p >= data_; p--) {
54 StringPiece StringPiece::substr(
size_t pos,
size_t n)
const {
55 if (pos > size_) pos = size_;
56 if (n > size_ - pos) n = size_ - pos;
57 return StringPiece(data_ + pos, n);
60 const StringPiece::size_type StringPiece::npos = size_type(-1);