Skip to content

Commit b08176a

Browse files
committed
add has_regexp_groups()
1 parent 2178d43 commit b08176a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

include/ada/url_pattern-inl.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,16 @@ inline std::string_view URLPattern::get_hash() const ada_lifetime_bound {
5959
return hash.get_pattern();
6060
}
6161

62-
inline bool URLPattern::case_ignored() const ada_lifetime_bound {
63-
return ignore_case;
62+
inline bool URLPattern::ignore_case() const ada_lifetime_bound {
63+
return ignore_case_;
64+
}
65+
66+
inline bool URLPattern::has_regexp_groups() const ada_lifetime_bound {
67+
// If this's associated URL pattern's has regexp groups, then return true.
68+
return protocol.has_regexp_groups() || username.has_regexp_groups() ||
69+
password.has_regexp_groups() || hostname.has_regexp_groups() ||
70+
port.has_regexp_groups() || pathname.has_regexp_groups() ||
71+
search.has_regexp_groups() || hash.has_regexp_groups();
6472
}
6573

6674
} // namespace ada

include/ada/url_pattern.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class URLPattern {
6464
std::string_view get_regex() const noexcept ada_lifetime_bound;
6565
const std::vector<std::string>& get_names() const noexcept
6666
ada_lifetime_bound;
67+
bool has_regexp_groups() const noexcept ada_lifetime_bound;
6768

6869
private:
6970
// Disallow copy.
@@ -75,6 +76,8 @@ class URLPattern {
7576
std::string regex = "";
7677
// The list of sub-component names extracted for this component.
7778
std::vector<std::string> names{};
79+
80+
bool has_regexp_groups_ = false;
7881
};
7982

8083
// A structure providing matching patterns for individual components
@@ -155,7 +158,10 @@ class URLPattern {
155158

156159
// If ignoreCase is true, the JavaScript regular expression created for each
157160
// pattern must use the `vi` flag. Otherwise, they must use the `v` flag.
158-
bool case_ignored() const ada_lifetime_bound;
161+
bool ignore_case() const ada_lifetime_bound;
162+
163+
// @see https://urlpattern.spec.whatwg.org/#url-pattern-has-regexp-groups
164+
bool has_regexp_groups() const ada_lifetime_bound;
159165

160166
private:
161167
Component protocol;
@@ -166,7 +172,7 @@ class URLPattern {
166172
Component pathname;
167173
Component search;
168174
Component hash;
169-
bool ignore_case = false;
175+
bool ignore_case_ = false;
170176
};
171177

172178
} // namespace ada

0 commit comments

Comments
 (0)