mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Use std::string_view in peg::parser
This commit is contained in:
parent
02f428ab67
commit
217d551744
35
peglib.h
35
peglib.h
@ -3955,11 +3955,12 @@ public:
|
|||||||
load_grammar(s, n, rules);
|
load_grammar(s, n, rules);
|
||||||
}
|
}
|
||||||
|
|
||||||
parser(const char *s, const Rules &rules) : parser(s, strlen(s), rules) {}
|
parser(std::string_view sv, const Rules &rules)
|
||||||
|
: parser(sv.data(), sv.size(), rules) {}
|
||||||
|
|
||||||
parser(const char *s, size_t n) : parser(s, n, Rules()) {}
|
parser(const char *s, size_t n) : parser(s, n, Rules()) {}
|
||||||
|
|
||||||
parser(const char *s) : parser(s, strlen(s), Rules()) {}
|
parser(std::string_view sv) : parser(sv.data(), sv.size(), Rules()) {}
|
||||||
|
|
||||||
operator bool() { return grammar_ != nullptr; }
|
operator bool() { return grammar_ != nullptr; }
|
||||||
|
|
||||||
@ -3972,14 +3973,12 @@ public:
|
|||||||
return load_grammar(s, n, Rules());
|
return load_grammar(s, n, Rules());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool load_grammar(const char *s, const Rules &rules) {
|
bool load_grammar(std::string_view sv, const Rules &rules) {
|
||||||
auto n = strlen(s);
|
return load_grammar(sv.data(), sv.size(), rules);
|
||||||
return load_grammar(s, n, rules);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool load_grammar(const char *s) {
|
bool load_grammar(std::string_view sv) {
|
||||||
auto n = strlen(s);
|
return load_grammar(sv.data(), sv.size());
|
||||||
return load_grammar(s, n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parse_n(const char *s, size_t n, const char *path = nullptr) const {
|
bool parse_n(const char *s, size_t n, const char *path = nullptr) const {
|
||||||
@ -3990,9 +3989,8 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parse(const char *s, const char *path = nullptr) const {
|
bool parse(std::string_view sv, const char *path = nullptr) const {
|
||||||
auto n = strlen(s);
|
return parse_n(sv.data(), sv.size(), path);
|
||||||
return parse_n(s, n, path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parse_n(const char *s, size_t n, std::any &dt,
|
bool parse_n(const char *s, size_t n, std::any &dt,
|
||||||
@ -4004,9 +4002,9 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parse(const char *s, std::any &dt, const char *path = nullptr) const {
|
bool parse(std::string_view sv, std::any &dt,
|
||||||
auto n = strlen(s);
|
const char *path = nullptr) const {
|
||||||
return parse_n(s, n, dt, path);
|
return parse_n(sv.data(), sv.size(), dt, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -4020,9 +4018,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool parse(const char *s, T &val, const char *path = nullptr) const {
|
bool parse(std::string_view sv, T &val, const char *path = nullptr) const {
|
||||||
auto n = strlen(s);
|
return parse_n(sv.data(), sv.size(), val, path);
|
||||||
return parse_n(s, n, val, path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -4077,7 +4074,9 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> std::shared_ptr<T> optimize_ast(std::shared_ptr<T> ast, bool opt_mode = true) const {
|
template <typename T>
|
||||||
|
std::shared_ptr<T> optimize_ast(std::shared_ptr<T> ast,
|
||||||
|
bool opt_mode = true) const {
|
||||||
return AstOptimizer(opt_mode, get_no_ast_opt_rules()).optimize(ast);
|
return AstOptimizer(opt_mode, get_no_ast_opt_rules()).optimize(ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user