Skip to content

Commit 2178d43

Browse files
committed
implement getters
1 parent 7a5838b commit 2178d43

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

include/ada/url_pattern-inl.h

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,37 @@ inline const std::vector<std::string>& URLPattern::Component::get_names()
2626
return names;
2727
}
2828

29-
inline const URLPattern::Component& URLPattern::get_protocol() const
30-
ada_lifetime_bound {
31-
return protocol;
29+
inline std::string_view URLPattern::get_protocol() const ada_lifetime_bound {
30+
// Return this's associated URL pattern's protocol component's pattern string.
31+
return protocol.get_pattern();
3232
}
33-
inline const URLPattern::Component& URLPattern::get_username() const
34-
ada_lifetime_bound {
35-
return username;
33+
inline std::string_view URLPattern::get_username() const ada_lifetime_bound {
34+
// Return this's associated URL pattern's username component's pattern string.
35+
return username.get_pattern();
3636
}
37-
inline const URLPattern::Component& URLPattern::get_password() const
38-
ada_lifetime_bound {
39-
return password;
37+
inline std::string_view URLPattern::get_password() const ada_lifetime_bound {
38+
// Return this's associated URL pattern's password component's pattern string.
39+
return password.get_pattern();
4040
}
41-
inline const URLPattern::Component& URLPattern::get_port() const
42-
ada_lifetime_bound {
43-
return port;
41+
inline std::string_view URLPattern::get_hostname() const ada_lifetime_bound {
42+
// Return this's associated URL pattern's hostname component's pattern string.
43+
return hostname.get_pattern();
4444
}
45-
inline const URLPattern::Component& URLPattern::get_pathname() const
46-
ada_lifetime_bound {
47-
return pathname;
45+
inline std::string_view URLPattern::get_port() const ada_lifetime_bound {
46+
// Return this's associated URL pattern's port component's pattern string.
47+
return port.get_pattern();
4848
}
49-
inline const URLPattern::Component& URLPattern::get_search() const
50-
ada_lifetime_bound {
51-
return search;
49+
inline std::string_view URLPattern::get_pathname() const ada_lifetime_bound {
50+
// Return this's associated URL pattern's pathname component's pattern string.
51+
return pathname.get_pattern();
5252
}
53-
inline const URLPattern::Component& URLPattern::get_hash() const
54-
ada_lifetime_bound {
55-
return hash;
53+
inline std::string_view URLPattern::get_search() const ada_lifetime_bound {
54+
// Return this's associated URL pattern's search component's pattern string.
55+
return search.get_pattern();
56+
}
57+
inline std::string_view URLPattern::get_hash() const ada_lifetime_bound {
58+
// Return this's associated URL pattern's hash component's pattern string.
59+
return hash.get_pattern();
5660
}
5761

5862
inline bool URLPattern::case_ignored() const ada_lifetime_bound {
@@ -61,4 +65,4 @@ inline bool URLPattern::case_ignored() const ada_lifetime_bound {
6165

6266
} // namespace ada
6367

64-
#endif
68+
#endif

include/ada/url_pattern.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,22 @@ class URLPattern {
136136
bool test(std::optional<Input> input,
137137
std::optional<std::string_view> base_url);
138138

139-
const Component& get_protocol() const ada_lifetime_bound;
140-
const Component& get_username() const ada_lifetime_bound;
141-
const Component& get_password() const ada_lifetime_bound;
142-
const Component& get_port() const ada_lifetime_bound;
143-
const Component& get_pathname() const ada_lifetime_bound;
144-
const Component& get_search() const ada_lifetime_bound;
145-
const Component& get_hash() const ada_lifetime_bound;
139+
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-protocol
140+
std::string_view get_protocol() const ada_lifetime_bound;
141+
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-username
142+
std::string_view get_username() const ada_lifetime_bound;
143+
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-password
144+
std::string_view get_password() const ada_lifetime_bound;
145+
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-hostname
146+
std::string_view get_hostname() const ada_lifetime_bound;
147+
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-port
148+
std::string_view get_port() const ada_lifetime_bound;
149+
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-pathname
150+
std::string_view get_pathname() const ada_lifetime_bound;
151+
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-search
152+
std::string_view get_search() const ada_lifetime_bound;
153+
// @see https://urlpattern.spec.whatwg.org/#dom-urlpattern-hash
154+
std::string_view get_hash() const ada_lifetime_bound;
146155

147156
// If ignoreCase is true, the JavaScript regular expression created for each
148157
// pattern must use the `vi` flag. Otherwise, they must use the `v` flag.
@@ -152,6 +161,7 @@ class URLPattern {
152161
Component protocol;
153162
Component username;
154163
Component password;
164+
Component hostname;
155165
Component port;
156166
Component pathname;
157167
Component search;

0 commit comments

Comments
 (0)