2023-07-21 15:28:59 +08:00
|
|
|
#ifndef __TEMPLATESEGMENTRULE_H__
|
|
|
|
#define __TEMPLATESEGMENTRULE_H__
|
|
|
|
|
|
|
|
#include <boost/url/error_types.hpp>
|
|
|
|
#include <boost/url/grammar/delim_rule.hpp>
|
|
|
|
#include <boost/url/grammar/optional_rule.hpp>
|
|
|
|
#include <boost/url/grammar/range_rule.hpp>
|
|
|
|
#include <boost/url/grammar/tuple_rule.hpp>
|
|
|
|
#include <boost/url/pct_string_view.hpp>
|
2023-08-13 15:05:35 +08:00
|
|
|
#include <boost/url/string_view.hpp>
|
2023-07-21 15:28:59 +08:00
|
|
|
|
|
|
|
class TemplateSegment {
|
|
|
|
friend class TemplateSegmentRule;
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum class Modifier {
|
|
|
|
None,
|
|
|
|
Optional, // {id?}
|
|
|
|
Star, // {id*}
|
|
|
|
Plus // {id+}
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool isLiteral() const;
|
|
|
|
bool isStar() const;
|
|
|
|
bool isPlus() const;
|
|
|
|
bool isOptional() const;
|
|
|
|
bool hasModifier() const;
|
2023-12-30 00:03:40 +08:00
|
|
|
boost::core::string_view id() const;
|
|
|
|
boost::core::string_view string() const;
|
2023-07-21 15:28:59 +08:00
|
|
|
bool match(boost::urls::pct_string_view segement) const;
|
|
|
|
bool operator==(const TemplateSegment &other) const;
|
|
|
|
|
|
|
|
// segments have precedence:
|
|
|
|
// - literal
|
|
|
|
// - unique
|
|
|
|
// - optional
|
|
|
|
// - plus
|
|
|
|
// - star
|
|
|
|
bool operator<(const TemplateSegment &other) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Modifier modifier = Modifier::None;
|
|
|
|
std::string m_string;
|
|
|
|
bool m_isLiteral = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TemplateSegmentRule {
|
|
|
|
public:
|
|
|
|
using value_type = TemplateSegment;
|
|
|
|
boost::urls::result<value_type> parse(char const *&iterator, char const *end) const noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr auto templateSegmentRule = TemplateSegmentRule{};
|
|
|
|
|
|
|
|
constexpr auto templatePathRule = boost::urls::grammar::tuple_rule(
|
|
|
|
boost::urls::grammar::squelch(boost::urls::grammar::optional_rule(boost::urls::grammar::delim_rule('/'))),
|
|
|
|
boost::urls::grammar::range_rule(
|
|
|
|
templateSegmentRule,
|
|
|
|
boost::urls::grammar::tuple_rule(boost::urls::grammar::squelch(boost::urls::grammar::delim_rule('/')),
|
|
|
|
templateSegmentRule)));
|
|
|
|
|
|
|
|
#endif // __TEMPLATESEGMENTRULE_H__
|