Ada 4.1.1
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
url_pattern_list_compiler.h
Go to the documentation of this file.
1
11#ifndef ADA_URL_PATTERN_LIST_COMPILER_H
12#define ADA_URL_PATTERN_LIST_COMPILER_H
13
14#include "ada/common_defs.h"
15#include "ada/url_pattern.h"
17
18#include <cstddef>
19#include <cstdint>
20#include <string>
21#include <vector>
22
23#if ADA_INCLUDE_URL_PATTERN
24namespace ada::url_pattern_list_compiler {
25
31inline constexpr uint32_t max_dispatch_table_entries = 254;
32
43inline constexpr uint32_t max_direct_children = 8;
44
50enum class segment_kind : uint8_t {
51 literal = 0,
52 param = 1,
53 wildcard = 2,
54};
55
61struct route_segment {
62 segment_kind kind = segment_kind::literal;
63 std::string text{};
64};
65
75struct route_info {
76 std::vector<route_segment> segments{};
77 // Capture group names, in capture order (params left to right, then the
78 // wildcard group). Regexp-mode routes: filled from the compiled component.
79 std::vector<std::string> group_names{};
80 uint64_t kind_sequence = 0;
81 uint8_t kind_length = 0;
82 url_pattern_list_detail::route_mode mode =
83 url_pattern_list_detail::route_mode::sequential;
84 bool has_wildcard = false;
85 bool all_literal = false;
86};
87
94bool classify_parts(const std::vector<url_pattern_part>& parts,
95 std::vector<route_segment>& segments,
96 std::vector<std::string>& group_names);
97
104void finalize_route(route_info& route) noexcept;
105
114void approximate_kind_sequence(const std::vector<url_pattern_part>& parts,
115 route_info& route);
116
120constexpr bool route_outranks(const route_info& a, size_t a_index,
121 const route_info& b, size_t b_index) noexcept {
122 return url_pattern_list_detail::outranks(a.kind_sequence, a.kind_length,
123 a_index, b.kind_sequence,
124 b.kind_length, b_index);
125}
126
136tl::expected<url_pattern_list_detail::compiled_routes, errors>
137compile_route_set(std::vector<route_info>& routes);
138
139} // namespace ada::url_pattern_list_compiler
140#endif // ADA_INCLUDE_URL_PATTERN
141#endif // ADA_URL_PATTERN_LIST_COMPILER_H
Cross-platform compiler macros and common definitions.
URLPattern API implementation.
Compiled set-level matching over URLPattern pathname patterns.