Skip to content

Commit 2fbdd48

Browse files
committed
reorg the headers for a cleaning design
1 parent ed0a1b3 commit 2fbdd48

File tree

5 files changed

+110
-79
lines changed

5 files changed

+110
-79
lines changed

include/ada/errors.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @file errors.h
3+
* @brief Definitions for the errors.
4+
*/
5+
#ifndef ADA_ERRORS_H
6+
#define ADA_ERRORS_H
7+
8+
#include <cstdint>
9+
namespace ada {
10+
enum class errors : uint8_t { type_error };
11+
} // namespace ada
12+
#endif // ADA_ERRORS_H

include/ada/implementation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
#include "ada/url.h"
1313
#include "ada/common_defs.h"
14+
#include "ada/errors.h"
15+
#include "ada/url_pattern_init.h"
1416

1517
namespace ada {
16-
enum class errors : uint8_t { type_error };
1718

1819
template <class result_type = ada::url_aggregator>
1920
using result = tl::expected<result_type, ada::errors>;

include/ada/parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "ada/expected.h"
1212
#include "ada/url_pattern_regex.h"
13+
#include "ada/url_pattern_init.h"
1314

1415
/**
1516
* @private
@@ -20,7 +21,6 @@ struct url;
2021
template <url_pattern_regex::regex_concept regex_provider>
2122
class url_pattern;
2223
struct url_pattern_options;
23-
struct url_pattern_init;
2424
enum class errors : uint8_t;
2525
} // namespace ada
2626

include/ada/url_pattern.h

Lines changed: 4 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -18,88 +18,13 @@
1818
#endif // ADA_TESTING
1919

2020
namespace ada {
21-
2221
namespace parser {
2322
template <typename result_type, typename url_pattern_init,
2423
typename url_pattern_options, typename regex_provider>
2524
tl::expected<result_type, errors> parse_url_pattern_impl(
2625
std::variant<std::string_view, url_pattern_init> input,
2726
const std::string_view* base_url, const url_pattern_options* options);
28-
}
29-
30-
// Important: C++20 allows us to use concept rather than `using` or `typedef
31-
// and allows functions with second argument, which is optional (using either
32-
// std::nullopt or a parameter with default value)
33-
template <typename F>
34-
concept url_pattern_encoding_callback = requires(F f, std::string_view sv) {
35-
{ f(sv) } -> std::same_as<tl::expected<std::string, errors>>;
36-
};
37-
38-
// A structure providing matching patterns for individual components
39-
// of a URL. When a URLPattern is created, or when a URLPattern is
40-
// used to match or test against a URL, the input can be given as
41-
// either a string or a URLPatternInit struct. If a string is given,
42-
// it will be parsed to create a URLPatternInit. The URLPatternInit
43-
// API is defined as part of the URLPattern specification.
44-
struct url_pattern_init {
45-
// @see https://urlpattern.spec.whatwg.org/#process-a-urlpatterninit
46-
static tl::expected<url_pattern_init, errors> process(
47-
url_pattern_init init, std::string_view type,
48-
std::optional<std::string_view> protocol = std::nullopt,
49-
std::optional<std::string_view> username = std::nullopt,
50-
std::optional<std::string_view> password = std::nullopt,
51-
std::optional<std::string_view> hostname = std::nullopt,
52-
std::optional<std::string_view> port = std::nullopt,
53-
std::optional<std::string_view> pathname = std::nullopt,
54-
std::optional<std::string_view> search = std::nullopt,
55-
std::optional<std::string_view> hash = std::nullopt);
56-
57-
// @see https://urlpattern.spec.whatwg.org/#process-protocol-for-init
58-
static tl::expected<std::string, errors> process_protocol(
59-
std::string_view value, std::string_view type);
60-
61-
// @see https://urlpattern.spec.whatwg.org/#process-username-for-init
62-
static tl::expected<std::string, errors> process_username(
63-
std::string_view value, std::string_view type);
64-
65-
// @see https://urlpattern.spec.whatwg.org/#process-password-for-init
66-
static tl::expected<std::string, errors> process_password(
67-
std::string_view value, std::string_view type);
68-
69-
// @see https://urlpattern.spec.whatwg.org/#process-hostname-for-init
70-
static tl::expected<std::string, errors> process_hostname(
71-
std::string_view value, std::string_view type);
72-
73-
// @see https://urlpattern.spec.whatwg.org/#process-port-for-init
74-
static tl::expected<std::string, errors> process_port(
75-
std::string_view port, std::string_view protocol, std::string_view type);
76-
77-
// @see https://urlpattern.spec.whatwg.org/#process-pathname-for-init
78-
static tl::expected<std::string, errors> process_pathname(
79-
std::string_view value, std::string_view protocol, std::string_view type);
80-
81-
// @see https://urlpattern.spec.whatwg.org/#process-search-for-init
82-
static tl::expected<std::string, errors> process_search(
83-
std::string_view value, std::string_view type);
84-
85-
// @see https://urlpattern.spec.whatwg.org/#process-hash-for-init
86-
static tl::expected<std::string, errors> process_hash(std::string_view value,
87-
std::string_view type);
88-
89-
[[nodiscard]] std::string to_string() const;
90-
91-
bool operator==(const url_pattern_init&) const;
92-
93-
std::optional<std::string> protocol{};
94-
std::optional<std::string> username{};
95-
std::optional<std::string> password{};
96-
std::optional<std::string> hostname{};
97-
std::optional<std::string> port{};
98-
std::optional<std::string> pathname{};
99-
std::optional<std::string> search{};
100-
std::optional<std::string> hash{};
101-
std::optional<std::string> base_url{};
102-
};
27+
} // namespace parser
10328

10429
enum class url_pattern_part_type : uint8_t {
10530
// The part represents a simple fixed text string.
@@ -330,12 +255,14 @@ class url_pattern {
330255
bool ignore_case_ = false;
331256

332257
template <typename result_type, typename url_pattern_init,
333-
typename url_pattern_options>
258+
typename url_pattern_options, typename regex_provider>
334259
friend tl::expected<result_type, errors> parser::parse_url_pattern_impl(
335260
std::variant<std::string_view, url_pattern_init> input,
336261
const std::string_view* base_url, const url_pattern_options* options);
337262
};
338263

264+
265+
339266
} // namespace ada
340267

341268
#endif

include/ada/url_pattern_init.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* @file url_pattern_init.h
3+
* @brief Declaration for the url_pattern_init implementation.
4+
*/
5+
#ifndef ADA_URL_PATTERN_INIT_H
6+
#define ADA_URL_PATTERN_INIT_H
7+
8+
#include "ada/expected.h"
9+
#include "ada/errors.h"
10+
#include <string_view>
11+
#include <string>
12+
#include <optional>
13+
14+
namespace ada {
15+
16+
// Important: C++20 allows us to use concept rather than `using` or `typedef
17+
// and allows functions with second argument, which is optional (using either
18+
// std::nullopt or a parameter with default value)
19+
template <typename F>
20+
concept url_pattern_encoding_callback = requires(F f, std::string_view sv) {
21+
{ f(sv) } -> std::same_as<tl::expected<std::string, errors>>;
22+
};
23+
24+
// A structure providing matching patterns for individual components
25+
// of a URL. When a URLPattern is created, or when a URLPattern is
26+
// used to match or test against a URL, the input can be given as
27+
// either a string or a URLPatternInit struct. If a string is given,
28+
// it will be parsed to create a URLPatternInit. The URLPatternInit
29+
// API is defined as part of the URLPattern specification.
30+
struct url_pattern_init {
31+
// @see https://urlpattern.spec.whatwg.org/#process-a-urlpatterninit
32+
static tl::expected<url_pattern_init, errors> process(
33+
url_pattern_init init, std::string_view type,
34+
std::optional<std::string_view> protocol = std::nullopt,
35+
std::optional<std::string_view> username = std::nullopt,
36+
std::optional<std::string_view> password = std::nullopt,
37+
std::optional<std::string_view> hostname = std::nullopt,
38+
std::optional<std::string_view> port = std::nullopt,
39+
std::optional<std::string_view> pathname = std::nullopt,
40+
std::optional<std::string_view> search = std::nullopt,
41+
std::optional<std::string_view> hash = std::nullopt);
42+
43+
// @see https://urlpattern.spec.whatwg.org/#process-protocol-for-init
44+
static tl::expected<std::string, errors> process_protocol(
45+
std::string_view value, std::string_view type);
46+
47+
// @see https://urlpattern.spec.whatwg.org/#process-username-for-init
48+
static tl::expected<std::string, errors> process_username(
49+
std::string_view value, std::string_view type);
50+
51+
// @see https://urlpattern.spec.whatwg.org/#process-password-for-init
52+
static tl::expected<std::string, errors> process_password(
53+
std::string_view value, std::string_view type);
54+
55+
// @see https://urlpattern.spec.whatwg.org/#process-hostname-for-init
56+
static tl::expected<std::string, errors> process_hostname(
57+
std::string_view value, std::string_view type);
58+
59+
// @see https://urlpattern.spec.whatwg.org/#process-port-for-init
60+
static tl::expected<std::string, errors> process_port(
61+
std::string_view port, std::string_view protocol, std::string_view type);
62+
63+
// @see https://urlpattern.spec.whatwg.org/#process-pathname-for-init
64+
static tl::expected<std::string, errors> process_pathname(
65+
std::string_view value, std::string_view protocol, std::string_view type);
66+
67+
// @see https://urlpattern.spec.whatwg.org/#process-search-for-init
68+
static tl::expected<std::string, errors> process_search(
69+
std::string_view value, std::string_view type);
70+
71+
// @see https://urlpattern.spec.whatwg.org/#process-hash-for-init
72+
static tl::expected<std::string, errors> process_hash(std::string_view value,
73+
std::string_view type);
74+
75+
[[nodiscard]] std::string to_string() const;
76+
77+
bool operator==(const url_pattern_init&) const;
78+
79+
std::optional<std::string> protocol{};
80+
std::optional<std::string> username{};
81+
std::optional<std::string> password{};
82+
std::optional<std::string> hostname{};
83+
std::optional<std::string> port{};
84+
std::optional<std::string> pathname{};
85+
std::optional<std::string> search{};
86+
std::optional<std::string> hash{};
87+
std::optional<std::string> base_url{};
88+
};
89+
} // namespace ada
90+
91+
#endif // ADA_URL_PATTERN_INIT_H

0 commit comments

Comments
 (0)