Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
CPPHTTPLIB_NAMESPACE::detail::PathParamsMatcher Class Referencefinal
Inheritance diagram for CPPHTTPLIB_NAMESPACE::detail::PathParamsMatcher:
Collaboration diagram for CPPHTTPLIB_NAMESPACE::detail::PathParamsMatcher:

Public Member Functions

 PathParamsMatcher (const std::string &pattern)
bool match (Request &request) const override
Public Member Functions inherited from CPPHTTPLIB_NAMESPACE::detail::MatcherBase
 MatcherBase (std::string pattern)
const std::string & pattern () const

Private Attributes

std::vector< std::string > static_fragments_
std::vector< std::string > param_names_

Static Private Attributes

static constexpr char separator = '/'

Detailed Description

Captures parameters in request path and stores them in Request::path_params

Capture name is a substring of a pattern from : to /. The rest of the pattern is matched against the request path directly Parameters are captured starting from the next character after the end of the last matched static pattern fragment until the next /.

Example pattern: "/path/fragments/:capture/more/fragments/:second_capture" Static fragments: "/path/fragments/", "more/fragments/"

Given the following request path: "/path/fragments/:1/more/fragments/:2" the resulting capture will be {{"capture", "1"}, {"second_capture", "2"}}

Constructor & Destructor Documentation

◆ PathParamsMatcher()

CPPHTTPLIB_NAMESPACE::detail::PathParamsMatcher::PathParamsMatcher ( const std::string & pattern)
inline
288742 : MatcherBase(pattern) {
288743 constexpr const char marker[] = "/:";
288744
288745 // One past the last ending position of a path param substring
288746 std::size_t last_param_end = 0;
288747
288748#ifndef CPPHTTPLIB_NO_EXCEPTIONS
288749 // Needed to ensure that parameter names are unique during matcher
288750 // construction
288751 // If exceptions are disabled, only last duplicate path
288752 // parameter will be set
288753 std::unordered_set<std::string> param_name_set;
288754#endif
288755
288756 while (true) {
288757 const auto marker_pos = pattern.find(
288758 marker, last_param_end == 0 ? last_param_end : last_param_end - 1);
288759 if (marker_pos == std::string::npos) { break; }
288760
288761 static_fragments_.push_back(
288762 pattern.substr(last_param_end, marker_pos - last_param_end + 1));
288763
288764 const auto param_name_start = marker_pos + str_len(marker);
288765
288766 auto sep_pos = pattern.find(separator, param_name_start);
288767 if (sep_pos == std::string::npos) { sep_pos = pattern.length(); }
288768
288769 auto param_name =
288770 pattern.substr(param_name_start, sep_pos - param_name_start);
288771
288772#ifndef CPPHTTPLIB_NO_EXCEPTIONS
288773 if (param_name_set.find(param_name) != param_name_set.cend()) {
288774 std::string msg = "Encountered path parameter '" + param_name +
288775 "' multiple times in route pattern '" + pattern + "'.";
288776 throw std::invalid_argument(msg);
288777 }
288778#endif
288779
288780 param_names_.push_back(std::move(param_name));
288781
288782 last_param_end = sep_pos + 1;
288783 }
288784
288785 if (last_param_end < pattern.length()) {
288786 static_fragments_.push_back(pattern.substr(last_param_end));
288787 }
288788}

Member Function Documentation

◆ match()

bool CPPHTTPLIB_NAMESPACE::detail::PathParamsMatcher::match ( Request & request) const
inlineoverridevirtual

Implements CPPHTTPLIB_NAMESPACE::detail::MatcherBase.

288790 {
288791 request.matches = Match();
288792 request.path_params.clear();
288793 request.path_params.reserve(param_names_.size());
288794
288795 // One past the position at which the path matched the pattern last time
288796 std::size_t starting_pos = 0;
288797 for (size_t i = 0; i < static_fragments_.size(); ++i) {
288798 const auto &fragment = static_fragments_[i];
288799
288800 if (starting_pos + fragment.length() > request.path.length()) {
288801 return false;
288802 }
288803
288804 // Avoid unnecessary allocation by using strncmp instead of substr +
288805 // comparison
288806 if (std::strncmp(request.path.c_str() + starting_pos, fragment.c_str(),
288807 fragment.length()) != 0) {
288808 return false;
288809 }
288810
288811 starting_pos += fragment.length();
288812
288813 // Should only happen when we have a static fragment after a param
288814 // Example: '/users/:id/subscriptions'
288815 // The 'subscriptions' fragment here does not have a corresponding param
288816 if (i >= param_names_.size()) { continue; }
288817
288818 auto sep_pos = request.path.find(separator, starting_pos);
288819 if (sep_pos == std::string::npos) { sep_pos = request.path.length(); }
288820
288821 const auto &param_name = param_names_[i];
288822
288823 request.path_params.emplace(
288824 param_name, request.path.substr(starting_pos, sep_pos - starting_pos));
288825
288826 // Mark everything up to '/' as matched
288827 starting_pos = sep_pos + 1;
288828 }
288829 // Returns false if the path is longer than the pattern
288830 return starting_pos >= request.path.length();
288831}
Match(int x, int y, float similarity, const String &class_id, int template_id)

The documentation for this class was generated from the following file: