77
88// NOLINTBEGIN(misc-include-cleaner)
99#include < sourcemeta/core/uritemplate_error.h>
10+ #include < sourcemeta/core/uritemplate_token.h>
1011// NOLINTEND(misc-include-cleaner)
1112
1213#include < cstddef> // std::size_t
13- #include < cstdint> // std::uint64_t, std::uint16_t
14+ #include < cstdint> // std::uint64_t
1415#include < functional> // std::function
1516#include < optional> // std::optional
1617#include < string> // std::string
1718#include < string_view> // std::string_view
1819#include < tuple> // std::tuple
1920#include < type_traits> // std::void_t
20- #include < variant> // std::variant
2121#include < vector> // std::vector
2222
2323// / @defgroup uritemplate URI Template
@@ -36,167 +36,12 @@ namespace sourcemeta::core {
3636using URITemplateValue = std::optional<
3737 std::tuple<std::string_view, std::optional<std::string_view>, bool >>;
3838
39- #ifndef DOXYGEN
40- struct URITemplateTokenLiteral ;
41- struct URITemplateTokenVariable ;
42- struct URITemplateTokenReservedExpansion ;
43- struct URITemplateTokenFragmentExpansion ;
44- struct URITemplateTokenLabelExpansion ;
45- struct URITemplateTokenPathExpansion ;
46- struct URITemplateTokenPathParameterExpansion ;
47- struct URITemplateTokenQueryExpansion ;
48- struct URITemplateTokenQueryContinuationExpansion ;
49- #endif
50-
51- // / @ingroup uritemplate
52- // / A token in a parsed URI Template
53- using URITemplateToken = std::variant<
54- URITemplateTokenLiteral, URITemplateTokenVariable,
55- URITemplateTokenReservedExpansion, URITemplateTokenFragmentExpansion,
56- URITemplateTokenLabelExpansion, URITemplateTokenPathExpansion,
57- URITemplateTokenPathParameterExpansion, URITemplateTokenQueryExpansion,
58- URITemplateTokenQueryContinuationExpansion>;
59-
6039// / @ingroup uritemplate
6140// / The result of parsing a token: the token and how many characters were
6241// / consumed
6342using URITemplateParseResult =
6443 std::optional<std::pair<URITemplateToken, std::size_t >>;
6544
66- // Exporting symbols that depends on the standard C++ library is considered
67- // safe.
68- // https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
69- #if defined(_MSC_VER)
70- #pragma warning(push)
71- #pragma warning(disable : 4251)
72- #endif
73-
74- // / @ingroup uritemplate
75- // / A literal string segment in a URI Template
76- struct SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateTokenLiteral {
77- std::string_view value;
78- [[nodiscard]] auto match (std::string_view uri, std::size_t position,
79- char delimiter) const noexcept -> std::size_t;
80- };
81-
82- // / @ingroup uritemplate
83- // / A variable specification within a URI Template expression
84- struct SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateVariableSpecification {
85- std::string_view name;
86- // As per the RFC, the range is 1-9999. 0 means "no prefix length"
87- std::uint16_t length{0 };
88- bool explode{false };
89- };
90-
91- // / @ingroup uritemplate
92- // / A simple string variable expansion {var} in a URI Template (Level 1)
93- struct SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateTokenVariable {
94- std::vector<URITemplateVariableSpecification> variables;
95- static constexpr char separator = ' ,' ;
96- static constexpr bool named = false ;
97- static constexpr bool allow_reserved = false ;
98- [[nodiscard]] auto match (std::string_view uri, std::size_t position,
99- char delimiter) const noexcept -> std::size_t;
100- };
101-
102- // / @ingroup uritemplate
103- // / A reserved expansion {+var} in a URI Template (Level 2)
104- struct SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateTokenReservedExpansion {
105- std::vector<URITemplateVariableSpecification> variables;
106- static constexpr char op = ' +' ;
107- static constexpr char separator = ' ,' ;
108- static constexpr bool named = false ;
109- static constexpr bool allow_reserved = true ;
110- [[nodiscard]] auto match (std::string_view uri, std::size_t position,
111- char delimiter) const noexcept -> std::size_t;
112- };
113-
114- // / @ingroup uritemplate
115- // / A fragment expansion {#var} in a URI Template (Level 2)
116- struct SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateTokenFragmentExpansion {
117- std::vector<URITemplateVariableSpecification> variables;
118- static constexpr char op = ' #' ;
119- static constexpr char separator = ' ,' ;
120- static constexpr char prefix = ' #' ;
121- static constexpr bool named = false ;
122- static constexpr bool allow_reserved = true ;
123- [[nodiscard]] auto match (std::string_view uri, std::size_t position,
124- char delimiter) const noexcept -> std::size_t;
125- };
126-
127- // / @ingroup uritemplate
128- // / A label expansion {.var} in a URI Template (Level 3)
129- struct SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateTokenLabelExpansion {
130- std::vector<URITemplateVariableSpecification> variables;
131- static constexpr char op = ' .' ;
132- static constexpr char separator = ' .' ;
133- static constexpr char prefix = ' .' ;
134- static constexpr bool named = false ;
135- static constexpr bool allow_reserved = false ;
136- [[nodiscard]] auto match (std::string_view uri, std::size_t position,
137- char delimiter) const noexcept -> std::size_t;
138- };
139-
140- // / @ingroup uritemplate
141- // / A path expansion {/var} in a URI Template (Level 3)
142- struct SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateTokenPathExpansion {
143- std::vector<URITemplateVariableSpecification> variables;
144- static constexpr char op = ' /' ;
145- static constexpr char separator = ' /' ;
146- static constexpr char prefix = ' /' ;
147- static constexpr bool named = false ;
148- static constexpr bool allow_reserved = false ;
149- [[nodiscard]] auto match (std::string_view uri, std::size_t position,
150- char delimiter) const noexcept -> std::size_t;
151- };
152-
153- // / @ingroup uritemplate
154- // / A path parameter expansion {;var} in a URI Template (Level 3)
155- struct SOURCEMETA_CORE_URITEMPLATE_EXPORT
156- URITemplateTokenPathParameterExpansion {
157- std::vector<URITemplateVariableSpecification> variables;
158- static constexpr char op = ' ;' ;
159- static constexpr char separator = ' ;' ;
160- static constexpr char prefix = ' ;' ;
161- static constexpr bool named = true ;
162- static constexpr bool allow_reserved = false ;
163- [[nodiscard]] auto match (std::string_view uri, std::size_t position,
164- char delimiter) const noexcept -> std::size_t;
165- };
166-
167- // / @ingroup uritemplate
168- // / A query expansion {?var} in a URI Template (Level 3)
169- struct SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplateTokenQueryExpansion {
170- std::vector<URITemplateVariableSpecification> variables;
171- static constexpr char op = ' ?' ;
172- static constexpr char separator = ' &' ;
173- static constexpr char prefix = ' ?' ;
174- static constexpr bool named = true ;
175- static constexpr bool allow_reserved = false ;
176- static constexpr char empty_suffix = ' =' ;
177- [[nodiscard]] auto match (std::string_view uri, std::size_t position,
178- char delimiter) const noexcept -> std::size_t;
179- };
180-
181- // / @ingroup uritemplate
182- // / A query continuation expansion {&var} in a URI Template (Level 3)
183- struct SOURCEMETA_CORE_URITEMPLATE_EXPORT
184- URITemplateTokenQueryContinuationExpansion {
185- std::vector<URITemplateVariableSpecification> variables;
186- static constexpr char op = ' &' ;
187- static constexpr char separator = ' &' ;
188- static constexpr char prefix = ' &' ;
189- static constexpr bool named = true ;
190- static constexpr bool allow_reserved = false ;
191- static constexpr char empty_suffix = ' =' ;
192- [[nodiscard]] auto match (std::string_view uri, std::size_t position,
193- char delimiter) const noexcept -> std::size_t;
194- };
195-
196- #if defined(_MSC_VER)
197- #pragma warning(pop)
198- #endif
199-
20045// / @ingroup uritemplate
20146// / A parsed URI Template per RFC 6570. This class behaves like a view. The
20247// / source string must outlive the template
@@ -219,7 +64,10 @@ class SOURCEMETA_CORE_URITEMPLATE_EXPORT URITemplate {
21964 [[nodiscard]] auto empty () const noexcept -> bool;
22065
22166 // / Get the token at the given index
222- [[nodiscard]] auto at (std::size_t index) const -> const URITemplateToken &;
67+ [[nodiscard]] auto at (std::size_t index) const & -> const URITemplateToken &;
68+
69+ // / Get the token at the given index (move overload)
70+ [[nodiscard]] auto at (std::size_t index) && -> URITemplateToken;
22371
22472 // / Iterator to the beginning of the tokens
22573 [[nodiscard]] auto begin () const noexcept
0 commit comments