RAVENNAKIT
Loading...
Searching...
No Matches
rav::PathMatcher Class Reference

A simple path matcher that matches paths against patterns. More...

#include <path_matcher.hpp>

Classes

class  Parameters
 Contains parameters extracted from a path with convenience functions to convert to integers. More...

Public Types

enum class  Error { invalid_recursive_wildcard , invalid_argument }

Static Public Member Functions

static boost::system::result< bool, Error > match (const std::string_view path, const std::string_view pattern, Parameters *parameters=nullptr)
 Match a path against a pattern.

Static Public Attributes

static constexpr auto k_loop_upper_bound = 100'000

Detailed Description

A simple path matcher that matches paths against patterns.

For example, it can be used to match URLs against patterns like "/user/{id}" or "/user/ **".

Path parameters are enclosed in curly braces, e.g. "/user/{id}" and fed into an instance of Parameters. The single wildcard "*" matches any single path segment. It must appear without additional characters. The double wildcard "**" matches any path below the current level. It can only appear at the end of the pattern.

Look at the unit tests for examples of usage.

Definition at line 45 of file path_matcher.hpp.

Member Enumeration Documentation

◆ Error

enum class rav::PathMatcher::Error
strong
Enumerator
invalid_recursive_wildcard 
invalid_argument 

Definition at line 49 of file path_matcher.hpp.

Member Function Documentation

◆ match()

boost::system::result< bool, Error > rav::PathMatcher::match ( const std::string_view path,
const std::string_view pattern,
Parameters * parameters = nullptr )
inlinestaticnodiscard

Match a path against a pattern.

Note: if the pattern contains a parameter, the parameter argument must not be null, otherwise the function will return false.

Parameters
pathThe path to match (e.g. "/user/123").
patternThe pattern to match against (e.g. "/user/{id}").
parametersThe parameters to fill with the extracted values from the path.
Returns
True if the path matches the pattern, false otherwise, or an error if the pattern or arguments are invalid.

Definition at line 134 of file path_matcher.hpp.

Member Data Documentation

◆ k_loop_upper_bound

auto rav::PathMatcher::k_loop_upper_bound = 100'000
staticconstexpr

Definition at line 47 of file path_matcher.hpp.


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