61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
#ifndef MARISA_QUERY_H_
|
|
#define MARISA_QUERY_H_
|
|
|
|
#include <string>
|
|
|
|
#include "base.h"
|
|
|
|
namespace marisa {
|
|
|
|
class Query {
|
|
public:
|
|
Query(const char *ptr, std::size_t length) : ptr_(ptr), length_(length) {}
|
|
Query(const Query &query) : ptr_(query.ptr_), length_(query.length_) {}
|
|
|
|
void insert(std::string *str) const {
|
|
str->insert(0, ptr_, length_);
|
|
}
|
|
|
|
UInt8 operator[](std::size_t i) const {
|
|
MARISA_DEBUG_IF(i >= length_, MARISA_PARAM_ERROR);
|
|
return ptr_[i];
|
|
}
|
|
bool ends_at(std::size_t i) const {
|
|
MARISA_DEBUG_IF(i > length_, MARISA_PARAM_ERROR);
|
|
return i == length_;
|
|
}
|
|
|
|
private:
|
|
const char *ptr_;
|
|
std::size_t length_;
|
|
|
|
// Disallows assignment.
|
|
Query &operator=(const Query &query);
|
|
};
|
|
|
|
class CQuery {
|
|
public:
|
|
explicit CQuery(const char *str) : str_(str) {}
|
|
CQuery(const CQuery &query) : str_(query.str_) {}
|
|
|
|
void insert(std::string *str) const {
|
|
str->insert(0, str_);
|
|
}
|
|
|
|
UInt8 operator[](std::size_t i) const {
|
|
return str_[i];
|
|
}
|
|
bool ends_at(std::size_t i) const {
|
|
return str_[i] == '\0';
|
|
}
|
|
|
|
private:
|
|
const char *str_;
|
|
|
|
// Disallows assignment.
|
|
CQuery &operator=(const CQuery &);
|
|
};
|
|
|
|
} // namespace marisa
|
|
|
|
#endif // MARISA_QUERY_H_
|