Skip to content

Commit 207e129

Browse files
committed
add ada::parse_url_pattern function
1 parent 524cb73 commit 207e129

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

include/ada/parser.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
#include <optional>
99
#include <string_view>
10+
#include <variant>
1011

1112
#include "ada/encoding_type.h"
1213
#include "ada/expected.h"
1314
#include "ada/state.h"
15+
#include "ada/url_pattern.h"
1416

1517
/**
1618
* @private
@@ -44,10 +46,16 @@ template <typename result_type = ada::url_aggregator, bool store_values = true>
4446
result_type parse_url_impl(std::string_view user_input,
4547
const result_type* base_url = nullptr);
4648

49+
tl::expected<ada::URLPattern, ada::url_pattern::errors> parse_url_pattern(
50+
std::variant<std::string_view, URLPattern::Init> input,
51+
const std::string_view* base_url = nullptr,
52+
const ada::URLPattern::Options* options = nullptr);
53+
4754
extern template url_aggregator parse_url_impl<url_aggregator>(
4855
std::string_view user_input, const url_aggregator* base_url);
4956
extern template url parse_url_impl<url>(std::string_view user_input,
5057
const url* base_url);
58+
5159
} // namespace ada::parser
5260

5361
#endif // ADA_PARSER_H

include/ada/url_pattern.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace ada {
1313

1414
namespace url_pattern {
1515

16+
enum class errors { type_error };
17+
1618
// @see https://wicg.github.io/urlpattern/#canonicalize-a-username
1719
std::optional<std::string> canonicalize_username(std::string_view input);
1820

src/implementation.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include <string_view>
2+
#include <variant>
23

34
#include "ada.h"
45
#include "ada/common_defs.h"
56
#include "ada/parser.h"
67
#include "ada/url.h"
78
#include "ada/url_aggregator.h"
9+
#include "ada/url_pattern.h"
810

911
namespace ada {
1012

@@ -19,6 +21,12 @@ ada_warn_unused tl::expected<result_type, ada::errors> parse(
1921
return u;
2022
}
2123

24+
ada_warn_unused tl::expected<ada::URLPattern, ada::url_pattern::errors>
25+
parse_url_pattern(std::variant<std::string_view, URLPattern::Init> input,
26+
const std::string_view* base_url,
27+
const ada::URLPattern::Options* options) {
28+
return ada::parser::parse_url_pattern(input, base_url, options);
29+
}
2230
template ada::result<url> parse<url>(std::string_view input,
2331
const url* base_url = nullptr);
2432
template ada::result<url_aggregator> parse<url_aggregator>(

src/parser.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,13 @@ result_type parse_url_impl(std::string_view user_input,
904904
return url;
905905
}
906906

907+
tl::expected<ada::URLPattern, ada::url_pattern::errors> parse_url_pattern(
908+
std::variant<std::string_view, URLPattern::Init> input,
909+
const std::string_view* base_url, const ada::URLPattern::Options* options) {
910+
// TODO: Implement parser here.
911+
return tl::unexpected(url_pattern::errors::type_error);
912+
}
913+
907914
template url parse_url_impl(std::string_view user_input,
908915
const url* base_url = nullptr);
909916
template url_aggregator parse_url_impl(

0 commit comments

Comments
 (0)