| 25 | namespace graphlearn { |
| 26 | |
| 27 | class LiteString { |
| 28 | public: |
| 29 | typedef const char* const_iterator; |
| 30 | typedef const char* iterator; |
| 31 | |
| 32 | static const size_t npos; |
| 33 | |
| 34 | LiteString() : data_(""), size_(0) {} |
| 35 | |
| 36 | LiteString(const char* s, size_t n) : data_(s), size_(n) {} |
| 37 | |
| 38 | LiteString(const char* s) //NOLINT |
| 39 | : data_(s), size_(strlen(s)) { |
| 40 | } |
| 41 | |
| 42 | LiteString(const std::string& s) //NOLINT |
| 43 | : data_(s.data()), size_(s.size()) { |
| 44 | } |
| 45 | |
| 46 | void set(const void* data, size_t len) { |
| 47 | data_ = reinterpret_cast<const char*>(data); |
| 48 | size_ = len; |
| 49 | } |
| 50 | |
| 51 | const char* data() const { |
| 52 | return data_; |
| 53 | } |
| 54 | |
| 55 | size_t size() const { |
| 56 | return size_; |
| 57 | } |
| 58 | |
| 59 | bool empty() const { |
| 60 | return size_ == 0; |
| 61 | } |
| 62 | |
| 63 | iterator begin() const { |
| 64 | return data_; |
| 65 | } |
| 66 | |
| 67 | iterator end() const { |
| 68 | return data_ + size_; |
| 69 | } |
| 70 | |
| 71 | char operator[](size_t n) const { |
| 72 | assert(n < size()); |
| 73 | return data_[n]; |
| 74 | } |
| 75 | |
| 76 | void clear() { |
| 77 | data_ = ""; |
| 78 | size_ = 0; |
| 79 | } |
| 80 | |
| 81 | void remove_prefix(size_t n) { |
| 82 | assert(n <= size()); |
| 83 | data_ += n; |
| 84 | size_ -= n; |
no outgoing calls