Skip to content

Commit 8127fb5

Browse files
authored
for maximal portability, use only ASCII (#905)
1 parent 30a2aaf commit 8127fb5

File tree

10 files changed

+290
-275
lines changed

10 files changed

+290
-275
lines changed

benchmarks/percent_encode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ size_t N = 1000;
99

1010
#include <benchmark/benchmark.h>
1111

12-
std::string examples[] = {"á|", "other:9818274x1!!",
12+
std::string examples[] = {"\xE1|", "other:9818274x1!!",
1313
"ref=web-twc-ao-gbl-adsinfo&utm_source=twc&utm_",
1414
"connect_timeout=10&application_name=myapp"};
1515

include/ada/parser-inl.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
6565
return tl::unexpected(processed_init.error());
6666
}
6767

68-
// For each componentName of « "protocol", "username", "password", "hostname",
68+
// For each componentName of "protocol", "username", "password", "hostname",
6969
// "port", "pathname", "search", "hash" If processedInit[componentName] does
7070
// not exist, then set processedInit[componentName] to "*".
7171
ADA_ASSERT_TRUE(processed_init.has_value());
@@ -103,7 +103,7 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
103103
// Let urlPattern be a new URL pattern.
104104
url_pattern<regex_provider> url_pattern_{};
105105

106-
// Set urlPatterns protocol component to the result of compiling a component
106+
// Set urlPattern's protocol component to the result of compiling a component
107107
// given processedInit["protocol"], canonicalize a protocol, and default
108108
// options.
109109
auto protocol_component = url_pattern_component<regex_provider>::compile(
@@ -117,7 +117,7 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
117117
}
118118
url_pattern_.protocol_component = std::move(*protocol_component);
119119

120-
// Set urlPatterns username component to the result of compiling a component
120+
// Set urlPattern's username component to the result of compiling a component
121121
// given processedInit["username"], canonicalize a username, and default
122122
// options.
123123
auto username_component = url_pattern_component<regex_provider>::compile(
@@ -131,7 +131,7 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
131131
}
132132
url_pattern_.username_component = std::move(*username_component);
133133

134-
// Set urlPatterns password component to the result of compiling a component
134+
// Set urlPattern's password component to the result of compiling a component
135135
// given processedInit["password"], canonicalize a password, and default
136136
// options.
137137
auto password_component = url_pattern_component<regex_provider>::compile(
@@ -148,12 +148,12 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
148148
// TODO: Optimization opportunity. The following if statement can be
149149
// simplified.
150150
// If the result running hostname pattern is an IPv6 address given
151-
// processedInit["hostname"] is true, then set urlPatterns hostname component
151+
// processedInit["hostname"] is true, then set urlPattern's hostname component
152152
// to the result of compiling a component given processedInit["hostname"],
153153
// canonicalize an IPv6 hostname, and hostname options.
154154
if (url_pattern_helpers::is_ipv6_address(processed_init->hostname.value())) {
155155
ada_log("processed_init->hostname is ipv6 address");
156-
// then set urlPatterns hostname component to the result of compiling a
156+
// then set urlPattern's hostname component to the result of compiling a
157157
// component given processedInit["hostname"], canonicalize an IPv6 hostname,
158158
// and hostname options.
159159
auto hostname_component = url_pattern_component<regex_provider>::compile(
@@ -167,7 +167,7 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
167167
}
168168
url_pattern_.hostname_component = std::move(*hostname_component);
169169
} else {
170-
// Otherwise, set urlPatterns hostname component to the result of compiling
170+
// Otherwise, set urlPattern's hostname component to the result of compiling
171171
// a component given processedInit["hostname"], canonicalize a hostname, and
172172
// hostname options.
173173
auto hostname_component = url_pattern_component<regex_provider>::compile(
@@ -182,7 +182,7 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
182182
url_pattern_.hostname_component = std::move(*hostname_component);
183183
}
184184

185-
// Set urlPatterns port component to the result of compiling a component
185+
// Set urlPattern's port component to the result of compiling a component
186186
// given processedInit["port"], canonicalize a port, and default options.
187187
auto port_component = url_pattern_component<regex_provider>::compile(
188188
processed_init->port.value(), url_pattern_helpers::canonicalize_port,
@@ -203,7 +203,7 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
203203

204204
// TODO: Optimization opportunity: Simplify this if statement.
205205
// If the result of running protocol component matches a special scheme given
206-
// urlPatterns protocol component is true, then:
206+
// urlPattern's protocol component is true, then:
207207
if (url_pattern_helpers::protocol_component_matches_special_scheme<
208208
regex_provider>(url_pattern_.protocol_component)) {
209209
// Let pathCompileOptions be copy of the pathname options with the ignore
@@ -213,7 +213,7 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
213213
path_compile_options.ignore_case = options->ignore_case;
214214
}
215215

216-
// Set urlPatterns pathname component to the result of compiling a
216+
// Set urlPattern's pathname component to the result of compiling a
217217
// component given processedInit["pathname"], canonicalize a pathname, and
218218
// pathCompileOptions.
219219
auto pathname_component = url_pattern_component<regex_provider>::compile(
@@ -226,7 +226,7 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
226226
}
227227
url_pattern_.pathname_component = std::move(*pathname_component);
228228
} else {
229-
// Otherwise set urlPatterns pathname component to the result of compiling
229+
// Otherwise set urlPattern's pathname component to the result of compiling
230230
// a component given processedInit["pathname"], canonicalize an opaque
231231
// pathname, and compileOptions.
232232
auto pathname_component = url_pattern_component<regex_provider>::compile(
@@ -240,7 +240,7 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
240240
url_pattern_.pathname_component = std::move(*pathname_component);
241241
}
242242

243-
// Set urlPatterns search component to the result of compiling a component
243+
// Set urlPattern's search component to the result of compiling a component
244244
// given processedInit["search"], canonicalize a search, and compileOptions.
245245
auto search_component = url_pattern_component<regex_provider>::compile(
246246
processed_init->search.value(), url_pattern_helpers::canonicalize_search,
@@ -252,7 +252,7 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
252252
}
253253
url_pattern_.search_component = std::move(*search_component);
254254

255-
// Set urlPatterns hash component to the result of compiling a component
255+
// Set urlPattern's hash component to the result of compiling a component
256256
// given processedInit["hash"], canonicalize a hash, and compileOptions.
257257
auto hash_component = url_pattern_component<regex_provider>::compile(
258258
processed_init->hash.value(), url_pattern_helpers::canonicalize_hash,

include/ada/url_pattern-inl.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ url_pattern_component<regex_provider>::compile(
179179
}
180180

181181
// For each part of part list:
182-
// - If parts type is "regexp", then set has regexp groups to true.
182+
// - If part's type is "regexp", then set has regexp groups to true.
183183
const auto has_regexp = [](const auto& part) { return part.is_regexp(); };
184184
const bool has_regexp_groups = std::ranges::any_of(*part_list, has_regexp);
185185

@@ -326,32 +326,32 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
326326
return std::nullopt;
327327
}
328328

329-
// Set protocol to urls scheme.
329+
// Set protocol to url's scheme.
330330
// IMPORTANT: Not documented on the URLPattern spec, but protocol suffix ':'
331331
// is removed. Similar work was done on workerd:
332332
// https://github.com/cloudflare/workerd/blob/8620d14012513a6ce04d079e401d3becac3c67bd/src/workerd/jsg/url.c%2B%2B#L2038
333333
protocol = url->get_protocol().substr(0, url->get_protocol().size() - 1);
334-
// Set username to urls username.
334+
// Set username to url's username.
335335
username = url->get_username();
336-
// Set password to urls password.
336+
// Set password to url's password.
337337
password = url->get_password();
338-
// Set hostname to urls host, serialized, or the empty string if the value
338+
// Set hostname to url's host, serialized, or the empty string if the value
339339
// is null.
340340
hostname = url->get_hostname();
341-
// Set port to urls port, serialized, or the empty string if the value is
341+
// Set port to url's port, serialized, or the empty string if the value is
342342
// null.
343343
port = url->get_port();
344344
// Set pathname to the result of URL path serializing url.
345345
pathname = url->get_pathname();
346-
// Set search to urls query or the empty string if the value is null.
346+
// Set search to url's query or the empty string if the value is null.
347347
// IMPORTANT: Not documented on the URLPattern spec, but search prefix '?'
348348
// is removed. Similar work was done on workerd:
349349
// https://github.com/cloudflare/workerd/blob/8620d14012513a6ce04d079e401d3becac3c67bd/src/workerd/jsg/url.c%2B%2B#L2232
350350
if (url->has_search()) {
351351
auto view = url->get_search();
352352
search = view.starts_with("?") ? url->get_search().substr(1) : view;
353353
}
354-
// Set hash to urls fragment or the empty string if the value is null.
354+
// Set hash to url's fragment or the empty string if the value is null.
355355
// IMPORTANT: Not documented on the URLPattern spec, but hash prefix '#' is
356356
// removed. Similar work was done on workerd:
357357
// https://github.com/cloudflare/workerd/blob/8620d14012513a6ce04d079e401d3becac3c67bd/src/workerd/jsg/url.c%2B%2B#L2242
@@ -361,7 +361,7 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
361361
}
362362
}
363363

364-
// Let protocolExecResult be RegExpBuiltinExec(urlPatterns protocol
364+
// Let protocolExecResult be RegExpBuiltinExec(urlPattern's protocol
365365
// component's regular expression, protocol).
366366
auto protocol_exec_result =
367367
regex_provider::regex_search(protocol, protocol_component.regexp);
@@ -370,7 +370,7 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
370370
return std::nullopt;
371371
}
372372

373-
// Let usernameExecResult be RegExpBuiltinExec(urlPatterns username
373+
// Let usernameExecResult be RegExpBuiltinExec(urlPattern's username
374374
// component's regular expression, username).
375375
auto username_exec_result =
376376
regex_provider::regex_search(username, username_component.regexp);
@@ -379,7 +379,7 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
379379
return std::nullopt;
380380
}
381381

382-
// Let passwordExecResult be RegExpBuiltinExec(urlPatterns password
382+
// Let passwordExecResult be RegExpBuiltinExec(urlPattern's password
383383
// component's regular expression, password).
384384
auto password_exec_result =
385385
regex_provider::regex_search(password, password_component.regexp);
@@ -388,7 +388,7 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
388388
return std::nullopt;
389389
}
390390

391-
// Let hostnameExecResult be RegExpBuiltinExec(urlPatterns hostname
391+
// Let hostnameExecResult be RegExpBuiltinExec(urlPattern's hostname
392392
// component's regular expression, hostname).
393393
auto hostname_exec_result =
394394
regex_provider::regex_search(hostname, hostname_component.regexp);
@@ -397,7 +397,7 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
397397
return std::nullopt;
398398
}
399399

400-
// Let portExecResult be RegExpBuiltinExec(urlPatterns port component's
400+
// Let portExecResult be RegExpBuiltinExec(urlPattern's port component's
401401
// regular expression, port).
402402
auto port_exec_result =
403403
regex_provider::regex_search(port, port_component.regexp);
@@ -406,7 +406,7 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
406406
return std::nullopt;
407407
}
408408

409-
// Let pathnameExecResult be RegExpBuiltinExec(urlPatterns pathname
409+
// Let pathnameExecResult be RegExpBuiltinExec(urlPattern's pathname
410410
// component's regular expression, pathname).
411411
auto pathname_exec_result =
412412
regex_provider::regex_search(pathname, pathname_component.regexp);
@@ -415,7 +415,7 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
415415
return std::nullopt;
416416
}
417417

418-
// Let searchExecResult be RegExpBuiltinExec(urlPatterns search component's
418+
// Let searchExecResult be RegExpBuiltinExec(urlPattern's search component's
419419
// regular expression, search).
420420
auto search_exec_result =
421421
regex_provider::regex_search(search, search_component.regexp);
@@ -424,7 +424,7 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
424424
return std::nullopt;
425425
}
426426

427-
// Let hashExecResult be RegExpBuiltinExec(urlPatterns hash component's
427+
// Let hashExecResult be RegExpBuiltinExec(urlPattern's hash component's
428428
// regular expression, hash).
429429
auto hash_exec_result =
430430
regex_provider::regex_search(hash, hash_component.regexp);
@@ -438,42 +438,42 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
438438
// Set result["inputs"] to inputs.
439439
result.inputs = std::move(inputs);
440440
// Set result["protocol"] to the result of creating a component match result
441-
// given urlPatterns protocol component, protocol, and protocolExecResult.
441+
// given urlPattern's protocol component, protocol, and protocolExecResult.
442442
result.protocol = protocol_component.create_component_match_result(
443443
std::move(protocol), std::move(*protocol_exec_result));
444444

445445
// Set result["username"] to the result of creating a component match result
446-
// given urlPatterns username component, username, and usernameExecResult.
446+
// given urlPattern's username component, username, and usernameExecResult.
447447
result.username = username_component.create_component_match_result(
448448
std::move(username), std::move(*username_exec_result));
449449

450450
// Set result["password"] to the result of creating a component match result
451-
// given urlPatterns password component, password, and passwordExecResult.
451+
// given urlPattern's password component, password, and passwordExecResult.
452452
result.password = password_component.create_component_match_result(
453453
std::move(password), std::move(*password_exec_result));
454454

455455
// Set result["hostname"] to the result of creating a component match result
456-
// given urlPatterns hostname component, hostname, and hostnameExecResult.
456+
// given urlPattern's hostname component, hostname, and hostnameExecResult.
457457
result.hostname = hostname_component.create_component_match_result(
458458
std::move(hostname), std::move(*hostname_exec_result));
459459

460460
// Set result["port"] to the result of creating a component match result given
461-
// urlPatterns port component, port, and portExecResult.
461+
// urlPattern's port component, port, and portExecResult.
462462
result.port = port_component.create_component_match_result(
463463
std::move(port), std::move(*port_exec_result));
464464

465465
// Set result["pathname"] to the result of creating a component match result
466-
// given urlPatterns pathname component, pathname, and pathnameExecResult.
466+
// given urlPattern's pathname component, pathname, and pathnameExecResult.
467467
result.pathname = pathname_component.create_component_match_result(
468468
std::move(pathname), std::move(*pathname_exec_result));
469469

470470
// Set result["search"] to the result of creating a component match result
471-
// given urlPatterns search component, search, and searchExecResult.
471+
// given urlPattern's search component, search, and searchExecResult.
472472
result.search = search_component.create_component_match_result(
473473
std::move(search), std::move(*search_exec_result));
474474

475475
// Set result["hash"] to the result of creating a component match result given
476-
// urlPatterns hash component, hash, and hashExecResult.
476+
// urlPattern's hash component, hash, and hashExecResult.
477477
result.hash = hash_component.create_component_match_result(
478478
std::move(hash), std::move(*hash_exec_result));
479479

0 commit comments

Comments
 (0)