#ifndef __TEMPLATESEGMENTRULE_H__ #define __TEMPLATESEGMENTRULE_H__ #include #include #include #include #include #include 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; boost::urls::string_view id() const; boost::urls::string_view string() const; 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 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__