| 37 | namespace re2 { |
| 38 | |
| 39 | class StringPiece { |
| 40 | public: |
| 41 | typedef std::char_traits<char> traits_type; |
| 42 | typedef char value_type; |
| 43 | typedef char* pointer; |
| 44 | typedef const char* const_pointer; |
| 45 | typedef char& reference; |
| 46 | typedef const char& const_reference; |
| 47 | typedef const char* const_iterator; |
| 48 | typedef const_iterator iterator; |
| 49 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 50 | typedef const_reverse_iterator reverse_iterator; |
| 51 | typedef size_t size_type; |
| 52 | typedef ptrdiff_t difference_type; |
| 53 | static const size_type npos = static_cast<size_type>(-1); |
| 54 | |
| 55 | // We provide non-explicit singleton constructors so users can pass |
| 56 | // in a "const char*" or a "string" wherever a "StringPiece" is |
| 57 | // expected. |
| 58 | StringPiece() |
| 59 | : data_(NULL), size_(0) {} |
| 60 | #if __has_include(<string_view>) && __cplusplus >= 201703L |
| 61 | StringPiece(const std::string_view& str) |
| 62 | : data_(str.data()), size_(str.size()) {} |
| 63 | #endif |
| 64 | StringPiece(const std::string& str) |
| 65 | : data_(str.data()), size_(str.size()) {} |
| 66 | StringPiece(const char* str) |
| 67 | : data_(str), size_(str == NULL ? 0 : strlen(str)) {} |
| 68 | StringPiece(const char* str, size_type len) |
| 69 | : data_(str), size_(len) {} |
| 70 | |
| 71 | const_iterator begin() const { return data_; } |
| 72 | const_iterator end() const { return data_ + size_; } |
| 73 | const_reverse_iterator rbegin() const { |
| 74 | return const_reverse_iterator(data_ + size_); |
| 75 | } |
| 76 | const_reverse_iterator rend() const { |
| 77 | return const_reverse_iterator(data_); |
| 78 | } |
| 79 | |
| 80 | size_type size() const { return size_; } |
| 81 | size_type length() const { return size_; } |
| 82 | bool empty() const { return size_ == 0; } |
| 83 | |
| 84 | const_reference operator[](size_type i) const { return data_[i]; } |
| 85 | const_pointer data() const { return data_; } |
| 86 | |
| 87 | void remove_prefix(size_type n) { |
| 88 | data_ += n; |
| 89 | size_ -= n; |
| 90 | } |
| 91 | |
| 92 | void remove_suffix(size_type n) { |
| 93 | size_ -= n; |
| 94 | } |
| 95 | |
| 96 | void set(const char* str) { |
no outgoing calls