1#ifndef MARISA_ALPHA_QUERY_H_ 2#define MARISA_ALPHA_QUERY_H_ 3 4#include <string> 5 6#include "base.h" 7 8namespace marisa_alpha { 9 10class Query { 11 public: 12 Query(const char *ptr, std::size_t length) : ptr_(ptr), length_(length) {} 13 Query(const Query &query) : ptr_(query.ptr_), length_(query.length_) {} 14 15 void insert(std::string *str) const { 16 str->insert(0, ptr_, length_); 17 } 18 19 UInt8 operator[](std::size_t i) const { 20 MARISA_ALPHA_DEBUG_IF(i >= length_, MARISA_ALPHA_PARAM_ERROR); 21 return ptr_[i]; 22 } 23 bool ends_at(std::size_t i) const { 24 MARISA_ALPHA_DEBUG_IF(i > length_, MARISA_ALPHA_PARAM_ERROR); 25 return i == length_; 26 } 27 28 private: 29 const char *ptr_; 30 std::size_t length_; 31 32 // Disallows assignment. 33 Query &operator=(const Query &query); 34}; 35 36class CQuery { 37 public: 38 explicit CQuery(const char *str) : str_(str) {} 39 CQuery(const CQuery &query) : str_(query.str_) {} 40 41 void insert(std::string *str) const { 42 str->insert(0, str_); 43 } 44 45 UInt8 operator[](std::size_t i) const { 46 return str_[i]; 47 } 48 bool ends_at(std::size_t i) const { 49 return str_[i] == '\0'; 50 } 51 52 private: 53 const char *str_; 54 55 // Disallows assignment. 56 CQuery &operator=(const CQuery &); 57}; 58 59} // namespace marisa_alpha 60 61#endif // MARISA_ALPHA_QUERY_H_ 62