ada-url 1.22.0__pp310-pypy310_pp73-win_amd64.whl → 1.29.0__pp310-pypy310_pp73-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ada_url/ada.h CHANGED
@@ -1,14 +1,36 @@
1
- /* auto-generated on 2025-03-30 13:24:42 -0400. Do not edit! */
1
+ /* auto-generated on 2026-01-30 13:29:04 -0500. Do not edit! */
2
2
  /* begin file include/ada.h */
3
3
  /**
4
4
  * @file ada.h
5
- * @brief Includes all definitions for Ada.
5
+ * @brief Main header for the Ada URL parser library.
6
+ *
7
+ * This is the primary entry point for the Ada URL parser library. Including
8
+ * this single header provides access to the complete Ada API, including:
9
+ *
10
+ * - URL parsing via `ada::parse()` function
11
+ * - Two URL representations: `ada::url` and `ada::url_aggregator`
12
+ * - URL search parameters via `ada::url_search_params`
13
+ * - URL pattern matching via `ada::url_pattern` (URLPattern API)
14
+ * - IDNA (Internationalized Domain Names) support
15
+ *
16
+ * @example
17
+ * ```cpp
18
+ *
19
+ * // Parse a URL
20
+ * auto url = ada::parse("https://example.com/path?query=1");
21
+ * if (url) {
22
+ * std::cout << url->get_hostname(); // "example.com"
23
+ * }
24
+ * ```
25
+ *
26
+ * @see https://url.spec.whatwg.org/ - WHATWG URL Standard
27
+ * @see https://github.com/ada-url/ada - Ada URL Parser GitHub Repository
6
28
  */
7
29
  #ifndef ADA_H
8
30
  #define ADA_H
9
31
 
10
32
  /* begin file include/ada/ada_idna.h */
11
- /* auto-generated on 2025-03-08 13:17:11 -0500. Do not edit! */
33
+ /* auto-generated on 2026-01-30 12:00:02 -0500. Do not edit! */
12
34
  /* begin file include/idna.h */
13
35
  #ifndef ADA_IDNA_H
14
36
  #define ADA_IDNA_H
@@ -188,7 +210,11 @@ bool valid_name_code_point(char32_t code_point, bool first);
188
210
  /* begin file include/ada/common_defs.h */
189
211
  /**
190
212
  * @file common_defs.h
191
- * @brief Common definitions for cross-platform compiler support.
213
+ * @brief Cross-platform compiler macros and common definitions.
214
+ *
215
+ * This header provides compiler-specific macros for optimization hints,
216
+ * platform detection, SIMD support detection, and development/debug utilities.
217
+ * It ensures consistent behavior across different compilers (GCC, Clang, MSVC).
192
218
  */
193
219
  #ifndef ADA_COMMON_DEFS_H
194
220
  #define ADA_COMMON_DEFS_H
@@ -421,6 +447,10 @@ namespace ada {
421
447
  } while (0)
422
448
  #endif
423
449
 
450
+ #if defined(__SSSE3__)
451
+ #define ADA_SSSE3 1
452
+ #endif
453
+
424
454
  #if defined(__SSE2__) || defined(__x86_64__) || defined(__x86_64) || \
425
455
  (defined(_M_AMD64) || defined(_M_X64) || \
426
456
  (defined(_M_IX86_FP) && _M_IX86_FP == 2))
@@ -431,6 +461,15 @@ namespace ada {
431
461
  #define ADA_NEON 1
432
462
  #endif
433
463
 
464
+ #if defined(__loongarch_sx)
465
+ #define ADA_LSX 1
466
+ #endif
467
+
468
+ #if defined(__riscv_v) && __riscv_v_intrinsic >= 11000
469
+ // Support RVV intrinsics v0.11 and above
470
+ #define ADA_RVV 1
471
+ #endif
472
+
434
473
  #ifndef __has_cpp_attribute
435
474
  #define ada_lifetime_bound
436
475
  #elif __has_cpp_attribute(msvc::lifetimebound)
@@ -943,7 +982,7 @@ constexpr uint8_t WWW_FORM_URLENCODED_PERCENT_ENCODE[32] = {
943
982
  // 50 51 52 53 54 55 56 57
944
983
  0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
945
984
  // 58 59 5A 5B 5C 5D 5E 5F
946
- 0x00 | 0x00 | 0x00 | 0x08 | 0x00 | 0x20 | 0x40 | 0x00,
985
+ 0x00 | 0x00 | 0x00 | 0x08 | 0x10 | 0x20 | 0x40 | 0x00,
947
986
  // 60 61 62 63 64 65 66 67
948
987
  0x01 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00,
949
988
  // 68 69 6A 6B 6C 6D 6E 6F
@@ -1003,6 +1042,140 @@ ada_really_inline constexpr bool bit_at(const uint8_t a[], const uint8_t i) {
1003
1042
 
1004
1043
  #include <bit>
1005
1044
  #include <string_view>
1045
+ /* begin file include/ada/checkers.h */
1046
+ /**
1047
+ * @file checkers.h
1048
+ * @brief Declarations for URL specific checkers used within Ada.
1049
+ */
1050
+ #ifndef ADA_CHECKERS_H
1051
+ #define ADA_CHECKERS_H
1052
+
1053
+
1054
+ #include <cstring>
1055
+ #include <string_view>
1056
+
1057
+ /**
1058
+ * These functions are not part of our public API and may
1059
+ * change at any time.
1060
+ * @private
1061
+ * @namespace ada::checkers
1062
+ * @brief Includes the definitions for validation functions
1063
+ */
1064
+ namespace ada::checkers {
1065
+
1066
+ /**
1067
+ * @private
1068
+ * Assuming that x is an ASCII letter, this function returns the lower case
1069
+ * equivalent.
1070
+ * @details More likely to be inlined by the compiler and constexpr.
1071
+ */
1072
+ constexpr char to_lower(char x) noexcept;
1073
+
1074
+ /**
1075
+ * @private
1076
+ * Returns true if the character is an ASCII letter. Equivalent to std::isalpha
1077
+ * but more likely to be inlined by the compiler.
1078
+ *
1079
+ * @attention std::isalpha is not constexpr generally.
1080
+ */
1081
+ constexpr bool is_alpha(char x) noexcept;
1082
+
1083
+ /**
1084
+ * @private
1085
+ * Check whether a string starts with 0x or 0X. The function is only
1086
+ * safe if input.size() >=2.
1087
+ *
1088
+ * @see has_hex_prefix
1089
+ */
1090
+ constexpr bool has_hex_prefix_unsafe(std::string_view input);
1091
+ /**
1092
+ * @private
1093
+ * Check whether a string starts with 0x or 0X.
1094
+ */
1095
+ constexpr bool has_hex_prefix(std::string_view input);
1096
+
1097
+ /**
1098
+ * @private
1099
+ * Check whether x is an ASCII digit. More likely to be inlined than
1100
+ * std::isdigit.
1101
+ */
1102
+ constexpr bool is_digit(char x) noexcept;
1103
+
1104
+ /**
1105
+ * @private
1106
+ * @details A string starts with a Windows drive letter if all of the following
1107
+ * are true:
1108
+ *
1109
+ * - its length is greater than or equal to 2
1110
+ * - its first two code points are a Windows drive letter
1111
+ * - its length is 2 or its third code point is U+002F (/), U+005C (\), U+003F
1112
+ * (?), or U+0023 (#).
1113
+ *
1114
+ * https://url.spec.whatwg.org/#start-with-a-windows-drive-letter
1115
+ */
1116
+ inline constexpr bool is_windows_drive_letter(std::string_view input) noexcept;
1117
+
1118
+ /**
1119
+ * @private
1120
+ * @details A normalized Windows drive letter is a Windows drive letter of which
1121
+ * the second code point is U+003A (:).
1122
+ */
1123
+ inline constexpr bool is_normalized_windows_drive_letter(
1124
+ std::string_view input) noexcept;
1125
+
1126
+ /**
1127
+ * @private
1128
+ * Returns true if an input is an ipv4 address. It is assumed that the string
1129
+ * does not contain uppercase ASCII characters (the input should have been
1130
+ * lowered cased before calling this function) and is not empty.
1131
+ */
1132
+ ada_really_inline constexpr bool is_ipv4(std::string_view view) noexcept;
1133
+
1134
+ /**
1135
+ * @private
1136
+ * Returns a bitset. If the first bit is set, then at least one character needs
1137
+ * percent encoding. If the second bit is set, a \\ is found. If the third bit
1138
+ * is set then we have a dot. If the fourth bit is set, then we have a percent
1139
+ * character.
1140
+ */
1141
+ ada_really_inline constexpr uint8_t path_signature(
1142
+ std::string_view input) noexcept;
1143
+
1144
+ /**
1145
+ * @private
1146
+ * Returns true if the length of the domain name and its labels are according to
1147
+ * the specifications. The length of the domain must be 255 octets (253
1148
+ * characters not including the last 2 which are the empty label reserved at the
1149
+ * end). When the empty label is included (a dot at the end), the domain name
1150
+ * can have 254 characters. The length of a label must be at least 1 and at most
1151
+ * 63 characters.
1152
+ * @see section 3.1. of https://www.rfc-editor.org/rfc/rfc1034
1153
+ * @see https://www.unicode.org/reports/tr46/#ToASCII
1154
+ */
1155
+ ada_really_inline constexpr bool verify_dns_length(
1156
+ std::string_view input) noexcept;
1157
+
1158
+ /**
1159
+ * @private
1160
+ * Fast-path parser for pure decimal IPv4 addresses (e.g., "192.168.1.1").
1161
+ * Returns the packed 32-bit IPv4 address on success, or a value > 0xFFFFFFFF
1162
+ * to indicate failure (caller should fall back to general parser).
1163
+ * This is optimized for the common case where the input is a well-formed
1164
+ * decimal IPv4 address with exactly 4 octets.
1165
+ */
1166
+ ada_really_inline constexpr uint64_t try_parse_ipv4_fast(
1167
+ std::string_view input) noexcept;
1168
+
1169
+ /**
1170
+ * Sentinel value indicating try_parse_ipv4_fast() did not succeed.
1171
+ * Any value > 0xFFFFFFFF indicates the fast path should not be used.
1172
+ */
1173
+ constexpr uint64_t ipv4_fast_fail = uint64_t(1) << 32;
1174
+
1175
+ } // namespace ada::checkers
1176
+
1177
+ #endif // ADA_CHECKERS_H
1178
+ /* end file include/ada/checkers.h */
1006
1179
 
1007
1180
  namespace ada::checkers {
1008
1181
 
@@ -1045,6 +1218,64 @@ constexpr bool is_normalized_windows_drive_letter(
1045
1218
  return input.size() >= 2 && (is_alpha(input[0]) && (input[1] == ':'));
1046
1219
  }
1047
1220
 
1221
+ ada_really_inline constexpr uint64_t try_parse_ipv4_fast(
1222
+ std::string_view input) noexcept {
1223
+ const char* p = input.data();
1224
+ const char* const pend = p + input.size();
1225
+
1226
+ uint32_t ipv4 = 0;
1227
+
1228
+ for (int i = 0; i < 4; ++i) {
1229
+ if (p == pend) {
1230
+ return ipv4_fast_fail;
1231
+ }
1232
+
1233
+ uint32_t val;
1234
+ char c = *p;
1235
+ if (c >= '0' && c <= '9') {
1236
+ val = c - '0';
1237
+ p++;
1238
+ } else {
1239
+ return ipv4_fast_fail;
1240
+ }
1241
+
1242
+ if (p < pend) {
1243
+ c = *p;
1244
+ if (c >= '0' && c <= '9') {
1245
+ if (val == 0) return ipv4_fast_fail;
1246
+ val = val * 10 + (c - '0');
1247
+ p++;
1248
+ if (p < pend) {
1249
+ c = *p;
1250
+ if (c >= '0' && c <= '9') {
1251
+ val = val * 10 + (c - '0');
1252
+ p++;
1253
+ if (val > 255) return ipv4_fast_fail;
1254
+ }
1255
+ }
1256
+ }
1257
+ }
1258
+
1259
+ ipv4 = (ipv4 << 8) | val;
1260
+
1261
+ if (i < 3) {
1262
+ if (p == pend || *p != '.') {
1263
+ return ipv4_fast_fail;
1264
+ }
1265
+ p++;
1266
+ }
1267
+ }
1268
+
1269
+ if (p != pend) {
1270
+ if (p == pend - 1 && *p == '.') {
1271
+ return ipv4;
1272
+ }
1273
+ return ipv4_fast_fail;
1274
+ }
1275
+
1276
+ return ipv4;
1277
+ }
1278
+
1048
1279
  } // namespace ada::checkers
1049
1280
 
1050
1281
  #endif // ADA_CHECKERS_INL_H
@@ -1098,7 +1329,11 @@ constexpr ada_really_inline void log([[maybe_unused]] Args... args) {
1098
1329
  /* begin file include/ada/encoding_type.h */
1099
1330
  /**
1100
1331
  * @file encoding_type.h
1101
- * @brief Definition for supported encoding types.
1332
+ * @brief Character encoding type definitions.
1333
+ *
1334
+ * Defines the encoding types supported for URL processing.
1335
+ *
1336
+ * @see https://encoding.spec.whatwg.org/
1102
1337
  */
1103
1338
  #ifndef ADA_ENCODING_TYPE_H
1104
1339
  #define ADA_ENCODING_TYPE_H
@@ -1108,21 +1343,25 @@ constexpr ada_really_inline void log([[maybe_unused]] Args... args) {
1108
1343
  namespace ada {
1109
1344
 
1110
1345
  /**
1111
- * This specification defines three encodings with the same names as encoding
1112
- * schemes defined in the Unicode standard: UTF-8, UTF-16LE, and UTF-16BE.
1346
+ * @brief Character encoding types for URL processing.
1347
+ *
1348
+ * Specifies the character encoding used for percent-decoding and other
1349
+ * string operations. UTF-8 is the most commonly used encoding for URLs.
1113
1350
  *
1114
1351
  * @see https://encoding.spec.whatwg.org/#encodings
1115
1352
  */
1116
1353
  enum class encoding_type {
1117
- UTF8,
1118
- UTF_16LE,
1119
- UTF_16BE,
1354
+ UTF8, /**< UTF-8 encoding (default for URLs) */
1355
+ UTF_16LE, /**< UTF-16 Little Endian encoding */
1356
+ UTF_16BE, /**< UTF-16 Big Endian encoding */
1120
1357
  };
1121
1358
 
1122
1359
  /**
1123
- * Convert a encoding_type to string.
1360
+ * Converts an encoding_type to its string representation.
1361
+ * @param type The encoding type to convert.
1362
+ * @return A string view of the encoding name.
1124
1363
  */
1125
- ada_warn_unused std::string to_string(encoding_type type);
1364
+ ada_warn_unused std::string_view to_string(encoding_type type);
1126
1365
 
1127
1366
  } // namespace ada
1128
1367
 
@@ -1139,7 +1378,11 @@ ada_warn_unused std::string to_string(encoding_type type);
1139
1378
  /* begin file include/ada/url_base.h */
1140
1379
  /**
1141
1380
  * @file url_base.h
1142
- * @brief Declaration for the basic URL definitions
1381
+ * @brief Base class and common definitions for URL types.
1382
+ *
1383
+ * This file defines the `url_base` abstract base class from which both
1384
+ * `ada::url` and `ada::url_aggregator` inherit. It also defines common
1385
+ * enumerations like `url_host_type`.
1143
1386
  */
1144
1387
  #ifndef ADA_URL_BASE_H
1145
1388
  #define ADA_URL_BASE_H
@@ -1147,7 +1390,13 @@ ada_warn_unused std::string to_string(encoding_type type);
1147
1390
  /* begin file include/ada/scheme.h */
1148
1391
  /**
1149
1392
  * @file scheme.h
1150
- * @brief Declarations for the URL scheme.
1393
+ * @brief URL scheme type definitions and utilities.
1394
+ *
1395
+ * This header defines the URL scheme types (http, https, etc.) and provides
1396
+ * functions to identify special schemes and their default ports according
1397
+ * to the WHATWG URL Standard.
1398
+ *
1399
+ * @see https://url.spec.whatwg.org/#special-scheme
1151
1400
  */
1152
1401
  #ifndef ADA_SCHEME_H
1153
1402
  #define ADA_SCHEME_H
@@ -1157,62 +1406,65 @@ ada_warn_unused std::string to_string(encoding_type type);
1157
1406
 
1158
1407
  /**
1159
1408
  * @namespace ada::scheme
1160
- * @brief Includes the scheme declarations
1409
+ * @brief URL scheme utilities and constants.
1410
+ *
1411
+ * Provides functions for working with URL schemes, including identification
1412
+ * of special schemes and retrieval of default port numbers.
1161
1413
  */
1162
1414
  namespace ada::scheme {
1163
1415
 
1164
1416
  /**
1165
- * Type of the scheme as an enum.
1166
- * Using strings to represent a scheme type is not ideal because
1167
- * checking for types involves string comparisons. It is faster to use
1168
- * a simple integer.
1169
- * In C++11, we are allowed to specify the underlying type of the enum.
1170
- * We pick an 8-bit integer (which allows up to 256 types). Specifying the
1171
- * type of the enum may help integration with other systems if the type
1172
- * variable is exposed (since its value will not depend on the compiler).
1417
+ * @brief Enumeration of URL scheme types.
1418
+ *
1419
+ * Special schemes have specific parsing rules and default ports.
1420
+ * Using an enum allows efficient scheme comparisons without string operations.
1421
+ *
1422
+ * Default ports:
1423
+ * - HTTP: 80
1424
+ * - HTTPS: 443
1425
+ * - WS: 80
1426
+ * - WSS: 443
1427
+ * - FTP: 21
1428
+ * - FILE: (none)
1173
1429
  */
1174
1430
  enum type : uint8_t {
1175
- HTTP = 0,
1176
- NOT_SPECIAL = 1,
1177
- HTTPS = 2,
1178
- WS = 3,
1179
- FTP = 4,
1180
- WSS = 5,
1181
- FILE = 6
1431
+ HTTP = 0, /**< http:// scheme (port 80) */
1432
+ NOT_SPECIAL = 1, /**< Non-special scheme (no default port) */
1433
+ HTTPS = 2, /**< https:// scheme (port 443) */
1434
+ WS = 3, /**< ws:// WebSocket scheme (port 80) */
1435
+ FTP = 4, /**< ftp:// scheme (port 21) */
1436
+ WSS = 5, /**< wss:// secure WebSocket scheme (port 443) */
1437
+ FILE = 6 /**< file:// scheme (no default port) */
1182
1438
  };
1183
1439
 
1184
1440
  /**
1185
- * A special scheme is an ASCII string that is listed in the first column of the
1186
- * following table. The default port for a special scheme is listed in the
1187
- * second column on the same row. The default port for any other ASCII string is
1188
- * null.
1189
- *
1190
- * @see https://url.spec.whatwg.org/#url-miscellaneous
1191
- * @param scheme
1192
- * @return If scheme is a special scheme
1441
+ * Checks if a scheme string is a special scheme.
1442
+ * @param scheme The scheme string to check (e.g., "http", "https").
1443
+ * @return `true` if the scheme is special, `false` otherwise.
1444
+ * @see https://url.spec.whatwg.org/#special-scheme
1193
1445
  */
1194
1446
  ada_really_inline constexpr bool is_special(std::string_view scheme);
1195
1447
 
1196
1448
  /**
1197
- * A special scheme is an ASCII string that is listed in the first column of the
1198
- * following table. The default port for a special scheme is listed in the
1199
- * second column on the same row. The default port for any other ASCII string is
1200
- * null.
1201
- *
1202
- * @see https://url.spec.whatwg.org/#url-miscellaneous
1203
- * @param scheme
1204
- * @return The special port
1449
+ * Returns the default port for a special scheme string.
1450
+ * @param scheme The scheme string (e.g., "http", "https").
1451
+ * @return The default port number, or 0 if not a special scheme.
1452
+ * @see https://url.spec.whatwg.org/#special-scheme
1205
1453
  */
1206
1454
  constexpr uint16_t get_special_port(std::string_view scheme) noexcept;
1207
1455
 
1208
1456
  /**
1209
- * Returns the port number of a special scheme.
1457
+ * Returns the default port for a scheme type.
1458
+ * @param type The scheme type enum value.
1459
+ * @return The default port number, or 0 if not applicable.
1210
1460
  * @see https://url.spec.whatwg.org/#special-scheme
1211
1461
  */
1212
1462
  constexpr uint16_t get_special_port(ada::scheme::type type) noexcept;
1463
+
1213
1464
  /**
1214
- * Returns the scheme of an input, or NOT_SPECIAL if it's not a special scheme
1215
- * defined by the spec.
1465
+ * Converts a scheme string to its type enum.
1466
+ * @param scheme The scheme string to convert.
1467
+ * @return The corresponding scheme type, or NOT_SPECIAL if not recognized.
1216
1468
  */
1217
1469
  constexpr ada::scheme::type get_scheme_type(std::string_view scheme) noexcept;
1218
1470
 
@@ -1227,112 +1479,112 @@ constexpr ada::scheme::type get_scheme_type(std::string_view scheme) noexcept;
1227
1479
  namespace ada {
1228
1480
 
1229
1481
  /**
1230
- * Type of URL host as an enum.
1482
+ * @brief Enum representing the type of host in a URL.
1483
+ *
1484
+ * Used to distinguish between regular domain names, IPv4 addresses,
1485
+ * and IPv6 addresses for proper parsing and serialization.
1231
1486
  */
1232
1487
  enum url_host_type : uint8_t {
1233
- /**
1234
- * Represents common URLs such as "https://www.google.com"
1235
- */
1488
+ /** Regular domain name (e.g., "www.example.com") */
1236
1489
  DEFAULT = 0,
1237
- /**
1238
- * Represents ipv4 addresses such as "http://127.0.0.1"
1239
- */
1490
+ /** IPv4 address (e.g., "127.0.0.1") */
1240
1491
  IPV4 = 1,
1241
- /**
1242
- * Represents ipv6 addresses such as
1243
- * "http://[2001:db8:3333:4444:5555:6666:7777:8888]"
1244
- */
1492
+ /** IPv6 address (e.g., "[::1]" or "[2001:db8::1]") */
1245
1493
  IPV6 = 2,
1246
1494
  };
1247
1495
 
1248
1496
  /**
1249
- * @brief Base class of URL implementations
1497
+ * @brief Abstract base class for URL representations.
1498
+ *
1499
+ * The `url_base` class provides the common interface and state shared by
1500
+ * both `ada::url` and `ada::url_aggregator`. It contains basic URL attributes
1501
+ * like validity status and scheme type, but delegates component storage and
1502
+ * access to derived classes.
1250
1503
  *
1251
- * @details A url_base contains a few attributes: is_valid, has_opaque_path and
1252
- * type. All non-trivial implementation details are in derived classes such as
1253
- * ada::url and ada::url_aggregator.
1504
+ * @note This is an abstract class and cannot be instantiated directly.
1505
+ * Use `ada::url` or `ada::url_aggregator` instead.
1254
1506
  *
1255
- * It is an abstract class that cannot be instantiated directly.
1507
+ * @see url
1508
+ * @see url_aggregator
1256
1509
  */
1257
1510
  struct url_base {
1258
1511
  virtual ~url_base() = default;
1259
1512
 
1260
1513
  /**
1261
- * Used for returning the validity from the result of the URL parser.
1514
+ * Indicates whether the URL was successfully parsed.
1515
+ * Set to `false` if parsing failed (e.g., invalid URL syntax).
1262
1516
  */
1263
1517
  bool is_valid{true};
1264
1518
 
1265
1519
  /**
1266
- * A URL has an opaque path if its path is a string.
1520
+ * Indicates whether the URL has an opaque path (non-hierarchical).
1521
+ * Opaque paths occur in non-special URLs like `mailto:` or `javascript:`.
1267
1522
  */
1268
1523
  bool has_opaque_path{false};
1269
1524
 
1270
1525
  /**
1271
- * URL hosts type
1526
+ * The type of the URL's host (domain, IPv4, or IPv6).
1272
1527
  */
1273
1528
  url_host_type host_type = url_host_type::DEFAULT;
1274
1529
 
1275
1530
  /**
1276
1531
  * @private
1532
+ * Internal representation of the URL's scheme type.
1277
1533
  */
1278
1534
  ada::scheme::type type{ada::scheme::type::NOT_SPECIAL};
1279
1535
 
1280
1536
  /**
1281
- * A URL is special if its scheme is a special scheme. A URL is not special if
1282
- * its scheme is not a special scheme.
1537
+ * Checks if the URL has a special scheme (http, https, ws, wss, ftp, file).
1538
+ * Special schemes have specific parsing rules and default ports.
1539
+ * @return `true` if the scheme is special, `false` otherwise.
1283
1540
  */
1284
1541
  [[nodiscard]] ada_really_inline constexpr bool is_special() const noexcept;
1285
1542
 
1286
1543
  /**
1287
- * The origin getter steps are to return the serialization of this's URL's
1288
- * origin. [HTML]
1289
- * @return a newly allocated string.
1544
+ * Returns the URL's origin (scheme + host + port for special URLs).
1545
+ * @return A newly allocated string containing the serialized origin.
1290
1546
  * @see https://url.spec.whatwg.org/#concept-url-origin
1291
1547
  */
1292
- [[nodiscard]] virtual std::string get_origin() const noexcept = 0;
1548
+ [[nodiscard]] virtual std::string get_origin() const = 0;
1293
1549
 
1294
1550
  /**
1295
- * Returns true if this URL has a valid domain as per RFC 1034 and
1296
- * corresponding specifications. Among other things, it requires
1297
- * that the domain string has fewer than 255 octets.
1551
+ * Validates whether the hostname is a valid domain according to RFC 1034.
1552
+ * Checks that the domain and its labels have valid lengths.
1553
+ * @return `true` if the domain is valid, `false` otherwise.
1298
1554
  */
1299
1555
  [[nodiscard]] virtual bool has_valid_domain() const noexcept = 0;
1300
1556
 
1301
1557
  /**
1302
1558
  * @private
1303
- *
1304
- * Return the 'special port' if the URL is special and not 'file'.
1305
- * Returns 0 otherwise.
1559
+ * Returns the default port for special schemes (e.g., 443 for https).
1560
+ * Returns 0 for file:// URLs or non-special schemes.
1306
1561
  */
1307
1562
  [[nodiscard]] inline uint16_t get_special_port() const noexcept;
1308
1563
 
1309
1564
  /**
1310
1565
  * @private
1311
- *
1312
- * Get the default port if the url's scheme has one, returns 0 otherwise.
1566
+ * Returns the default port for the URL's scheme, or 0 if none.
1313
1567
  */
1314
1568
  [[nodiscard]] ada_really_inline uint16_t scheme_default_port() const noexcept;
1315
1569
 
1316
1570
  /**
1317
1571
  * @private
1318
- *
1319
- * Parse a port (16-bit decimal digit) from the provided input.
1320
- * We assume that the input does not contain spaces or tabs
1321
- * within the ASCII digits.
1322
- * It returns how many bytes were consumed when a number is successfully
1323
- * parsed.
1324
- * @return On failure, it returns zero.
1325
- * @see https://url.spec.whatwg.org/#host-parsing
1572
+ * Parses a port number from the input string.
1573
+ * @param view The string containing the port to parse.
1574
+ * @param check_trailing_content Whether to validate no trailing characters.
1575
+ * @return Number of bytes consumed on success, 0 on failure.
1326
1576
  */
1327
1577
  virtual size_t parse_port(std::string_view view,
1328
- bool check_trailing_content) noexcept = 0;
1578
+ bool check_trailing_content) = 0;
1329
1579
 
1330
- virtual ada_really_inline size_t parse_port(std::string_view view) noexcept {
1580
+ /** @private */
1581
+ virtual ada_really_inline size_t parse_port(std::string_view view) {
1331
1582
  return this->parse_port(view, false);
1332
1583
  }
1333
1584
 
1334
1585
  /**
1335
- * Returns a JSON string representation of this URL.
1586
+ * Returns a JSON string representation of this URL for debugging.
1587
+ * @return A JSON-formatted string with URL information.
1336
1588
  */
1337
1589
  [[nodiscard]] virtual std::string to_string() const = 0;
1338
1590
 
@@ -1401,8 +1653,7 @@ ada_really_inline std::optional<std::string_view> prune_hash(
1401
1653
  * @see https://url.spec.whatwg.org/#shorten-a-urls-path
1402
1654
  * @returns Returns true if path is shortened.
1403
1655
  */
1404
- ada_really_inline bool shorten_path(std::string& path,
1405
- ada::scheme::type type) noexcept;
1656
+ ada_really_inline bool shorten_path(std::string& path, ada::scheme::type type);
1406
1657
 
1407
1658
  /**
1408
1659
  * @private
@@ -1411,7 +1662,7 @@ ada_really_inline bool shorten_path(std::string& path,
1411
1662
  * @returns Returns true if path is shortened.
1412
1663
  */
1413
1664
  ada_really_inline bool shorten_path(std::string_view& path,
1414
- ada::scheme::type type) noexcept;
1665
+ ada::scheme::type type);
1415
1666
 
1416
1667
  /**
1417
1668
  * @private
@@ -1432,15 +1683,14 @@ ada_really_inline void parse_prepared_path(std::string_view input,
1432
1683
  * @private
1433
1684
  * Remove and mutate all ASCII tab or newline characters from an input.
1434
1685
  */
1435
- ada_really_inline void remove_ascii_tab_or_newline(std::string& input) noexcept;
1686
+ ada_really_inline void remove_ascii_tab_or_newline(std::string& input);
1436
1687
 
1437
1688
  /**
1438
1689
  * @private
1439
1690
  * Return the substring from input going from index pos to the end.
1440
- * This function cannot throw.
1441
1691
  */
1442
1692
  ada_really_inline constexpr std::string_view substring(std::string_view input,
1443
- size_t pos) noexcept;
1693
+ size_t pos);
1444
1694
 
1445
1695
  /**
1446
1696
  * @private
@@ -1455,7 +1705,7 @@ bool overlaps(std::string_view input1, const std::string& input2) noexcept;
1455
1705
  */
1456
1706
  ada_really_inline constexpr std::string_view substring(std::string_view input,
1457
1707
  size_t pos1,
1458
- size_t pos2) noexcept {
1708
+ size_t pos2) {
1459
1709
  #if ADA_DEVELOPMENT_CHECKS
1460
1710
  if (pos2 < pos1) {
1461
1711
  std::cerr << "Negative-length substring: [" << pos1 << " to " << pos2 << ")"
@@ -1494,8 +1744,7 @@ void trim_c0_whitespace(std::string_view& input) noexcept;
1494
1744
  * https://url.spec.whatwg.org/#potentially-strip-trailing-spaces-from-an-opaque-path
1495
1745
  */
1496
1746
  template <class url_type>
1497
- ada_really_inline void strip_trailing_spaces_from_opaque_path(
1498
- url_type& url) noexcept;
1747
+ ada_really_inline void strip_trailing_spaces_from_opaque_path(url_type& url);
1499
1748
 
1500
1749
  /**
1501
1750
  * @private
@@ -1585,7 +1834,13 @@ inline int fast_digit_count(uint32_t x) noexcept {
1585
1834
  /* begin file include/ada/parser.h */
1586
1835
  /**
1587
1836
  * @file parser.h
1588
- * @brief Definitions for the parser.
1837
+ * @brief Low-level URL parsing functions.
1838
+ *
1839
+ * This header provides the internal URL parsing implementation. Most users
1840
+ * should use `ada::parse()` from implementation.h instead of these functions
1841
+ * directly.
1842
+ *
1843
+ * @see implementation.h for the recommended public API
1589
1844
  */
1590
1845
  #ifndef ADA_PARSER_H
1591
1846
  #define ADA_PARSER_H
@@ -2329,6 +2584,7 @@ struct expected_operations_base : expected_storage_base<T, E> {
2329
2584
  }
2330
2585
 
2331
2586
  template <class Rhs>
2587
+ // NOLINTNEXTLINE(bugprone-exception-escape)
2332
2588
  void construct_with(Rhs &&rhs) noexcept {
2333
2589
  new (std::addressof(this->m_val)) T(std::forward<Rhs>(rhs).get());
2334
2590
  this->m_has_val = true;
@@ -4115,7 +4371,6 @@ void swap(expected<T, E> &lhs,
4115
4371
  #endif
4116
4372
  /* end file include/ada/expected.h */
4117
4373
 
4118
- #if ADA_INCLUDE_URL_PATTERN
4119
4374
  /* begin file include/ada/url_pattern_regex.h */
4120
4375
  /**
4121
4376
  * @file url_search_params.h
@@ -4131,6 +4386,7 @@ void swap(expected<T, E> &lhs,
4131
4386
  #include <regex>
4132
4387
  #endif // ADA_USE_UNSAFE_STD_REGEX_PROVIDER
4133
4388
 
4389
+ #if ADA_INCLUDE_URL_PATTERN
4134
4390
  namespace ada::url_pattern_regex {
4135
4391
 
4136
4392
  template <typename T>
@@ -4175,7 +4431,7 @@ class std_regex_provider final {
4175
4431
  #endif // ADA_USE_UNSAFE_STD_REGEX_PROVIDER
4176
4432
 
4177
4433
  } // namespace ada::url_pattern_regex
4178
-
4434
+ #endif // ADA_INCLUDE_URL_PATTERN
4179
4435
  #endif // ADA_URL_PATTERN_REGEX_H
4180
4436
  /* end file include/ada/url_pattern_regex.h */
4181
4437
  /* begin file include/ada/url_pattern_init.h */
@@ -4189,14 +4445,23 @@ class std_regex_provider final {
4189
4445
  /* begin file include/ada/errors.h */
4190
4446
  /**
4191
4447
  * @file errors.h
4192
- * @brief Definitions for the errors.
4448
+ * @brief Error type definitions for URL parsing.
4449
+ *
4450
+ * Defines the error codes that can be returned when URL parsing fails.
4193
4451
  */
4194
4452
  #ifndef ADA_ERRORS_H
4195
4453
  #define ADA_ERRORS_H
4196
4454
 
4197
4455
  #include <cstdint>
4198
4456
  namespace ada {
4199
- enum class errors : uint8_t { type_error };
4457
+ /**
4458
+ * @brief Error codes for URL parsing operations.
4459
+ *
4460
+ * Used with `tl::expected` to indicate why a URL parsing operation failed.
4461
+ */
4462
+ enum class errors : uint8_t {
4463
+ type_error /**< A type error occurred (e.g., invalid URL syntax). */
4464
+ };
4200
4465
  } // namespace ada
4201
4466
  #endif // ADA_ERRORS_H
4202
4467
  /* end file include/ada/errors.h */
@@ -4204,11 +4469,13 @@ enum class errors : uint8_t { type_error };
4204
4469
  #include <string_view>
4205
4470
  #include <string>
4206
4471
  #include <optional>
4472
+ #include <iostream>
4207
4473
 
4208
4474
  #if ADA_TESTING
4209
4475
  #include <iostream>
4210
4476
  #endif // ADA_TESTING
4211
4477
 
4478
+ #if ADA_INCLUDE_URL_PATTERN
4212
4479
  namespace ada {
4213
4480
 
4214
4481
  // Important: C++20 allows us to use concept rather than `using` or `typedef
@@ -4232,6 +4499,17 @@ struct url_pattern_init {
4232
4499
  pattern,
4233
4500
  };
4234
4501
 
4502
+ friend std::ostream& operator<<(std::ostream& os, process_type type) {
4503
+ switch (type) {
4504
+ case process_type::url:
4505
+ return os << "url";
4506
+ case process_type::pattern:
4507
+ return os << "pattern";
4508
+ default:
4509
+ return os << "unknown";
4510
+ }
4511
+ }
4512
+
4235
4513
  // All strings must be valid UTF-8.
4236
4514
  // @see https://urlpattern.spec.whatwg.org/#process-a-urlpatterninit
4237
4515
  static tl::expected<url_pattern_init, errors> process(
@@ -4312,14 +4590,11 @@ struct url_pattern_init {
4312
4590
  std::optional<std::string> base_url{};
4313
4591
  };
4314
4592
  } // namespace ada
4315
-
4593
+ #endif // ADA_INCLUDE_URL_PATTERN
4316
4594
  #endif // ADA_URL_PATTERN_INIT_H
4317
4595
  /* end file include/ada/url_pattern_init.h */
4318
- #endif // ADA_INCLUDE_URL_PATTERN
4319
4596
 
4320
- /**
4321
- * @private
4322
- */
4597
+ /** @private Forward declarations */
4323
4598
  namespace ada {
4324
4599
  struct url_aggregator;
4325
4600
  struct url;
@@ -4333,14 +4608,24 @@ enum class errors : uint8_t;
4333
4608
 
4334
4609
  /**
4335
4610
  * @namespace ada::parser
4336
- * @brief Includes the definitions for supported parsers
4611
+ * @brief Internal URL parsing implementation.
4612
+ *
4613
+ * Contains the core URL parsing algorithm as specified by the WHATWG URL
4614
+ * Standard. These functions are used internally by `ada::parse()`.
4337
4615
  */
4338
4616
  namespace ada::parser {
4339
4617
  /**
4340
- * Parses a url. The parameter user_input is the input to be parsed:
4341
- * it should be a valid UTF-8 string. The parameter base_url is an optional
4342
- * parameter that can be used to resolve relative URLs. If the base_url is
4343
- * provided, the user_input is resolved against the base_url.
4618
+ * Parses a URL string into a URL object.
4619
+ *
4620
+ * @tparam result_type The type of URL object to create (url or url_aggregator).
4621
+ *
4622
+ * @param user_input The URL string to parse (must be valid UTF-8).
4623
+ * @param base_url Optional base URL for resolving relative URLs.
4624
+ *
4625
+ * @return The parsed URL object. Check `is_valid` to determine if parsing
4626
+ * succeeded.
4627
+ *
4628
+ * @see https://url.spec.whatwg.org/#concept-basic-url-parser
4344
4629
  */
4345
4630
  template <typename result_type = url_aggregator>
4346
4631
  result_type parse_url(std::string_view user_input,
@@ -4378,11 +4663,17 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
4378
4663
  #ifndef ADA_PARSER_INL_H
4379
4664
  #define ADA_PARSER_INL_H
4380
4665
 
4381
- #if ADA_INCLUDE_URL_PATTERN
4382
4666
  /* begin file include/ada/url_pattern.h */
4383
4667
  /**
4384
4668
  * @file url_pattern.h
4385
- * @brief Declaration for the URLPattern implementation.
4669
+ * @brief URLPattern API implementation.
4670
+ *
4671
+ * This header provides the URLPattern API as specified by the WHATWG URL
4672
+ * Pattern Standard. URLPattern allows matching URLs against patterns with
4673
+ * wildcards and named groups, similar to how regular expressions match strings.
4674
+ *
4675
+ * @see https://urlpattern.spec.whatwg.org/
4676
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API
4386
4677
  */
4387
4678
  #ifndef ADA_URL_PATTERN_H
4388
4679
  #define ADA_URL_PATTERN_H
@@ -4390,8 +4681,13 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
4390
4681
  /* begin file include/ada/implementation.h */
4391
4682
  /**
4392
4683
  * @file implementation.h
4393
- * @brief Definitions for user facing functions for parsing URL and it's
4394
- * components.
4684
+ * @brief User-facing functions for URL parsing and manipulation.
4685
+ *
4686
+ * This header provides the primary public API for parsing URLs in Ada.
4687
+ * It includes the main `ada::parse()` function which is the recommended
4688
+ * entry point for most users.
4689
+ *
4690
+ * @see https://url.spec.whatwg.org/#api
4395
4691
  */
4396
4692
  #ifndef ADA_IMPLEMENTATION_H
4397
4693
  #define ADA_IMPLEMENTATION_H
@@ -4403,7 +4699,13 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
4403
4699
  /* begin file include/ada/url.h */
4404
4700
  /**
4405
4701
  * @file url.h
4406
- * @brief Declaration for the URL
4702
+ * @brief Declaration for the `ada::url` class.
4703
+ *
4704
+ * This file contains the `ada::url` struct which represents a parsed URL
4705
+ * using separate `std::string` instances for each component. This
4706
+ * representation is more flexible but uses more memory than `url_aggregator`.
4707
+ *
4708
+ * @see url_aggregator.h for a more memory-efficient alternative
4407
4709
  */
4408
4710
  #ifndef ADA_URL_H
4409
4711
  #define ADA_URL_H
@@ -4414,127 +4716,14 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
4414
4716
  #include <string>
4415
4717
  #include <string_view>
4416
4718
 
4417
- /* begin file include/ada/checkers.h */
4418
- /**
4419
- * @file checkers.h
4420
- * @brief Declarations for URL specific checkers used within Ada.
4421
- */
4422
- #ifndef ADA_CHECKERS_H
4423
- #define ADA_CHECKERS_H
4424
-
4425
-
4426
- #include <cstring>
4427
- #include <string_view>
4428
-
4429
- /**
4430
- * These functions are not part of our public API and may
4431
- * change at any time.
4432
- * @private
4433
- * @namespace ada::checkers
4434
- * @brief Includes the definitions for validation functions
4435
- */
4436
- namespace ada::checkers {
4437
-
4438
- /**
4439
- * @private
4440
- * Assuming that x is an ASCII letter, this function returns the lower case
4441
- * equivalent.
4442
- * @details More likely to be inlined by the compiler and constexpr.
4443
- */
4444
- constexpr char to_lower(char x) noexcept;
4445
-
4446
- /**
4447
- * @private
4448
- * Returns true if the character is an ASCII letter. Equivalent to std::isalpha
4449
- * but more likely to be inlined by the compiler.
4450
- *
4451
- * @attention std::isalpha is not constexpr generally.
4452
- */
4453
- constexpr bool is_alpha(char x) noexcept;
4454
-
4455
- /**
4456
- * @private
4457
- * Check whether a string starts with 0x or 0X. The function is only
4458
- * safe if input.size() >=2.
4459
- *
4460
- * @see has_hex_prefix
4461
- */
4462
- constexpr bool has_hex_prefix_unsafe(std::string_view input);
4463
- /**
4464
- * @private
4465
- * Check whether a string starts with 0x or 0X.
4466
- */
4467
- constexpr bool has_hex_prefix(std::string_view input);
4468
-
4469
- /**
4470
- * @private
4471
- * Check whether x is an ASCII digit. More likely to be inlined than
4472
- * std::isdigit.
4473
- */
4474
- constexpr bool is_digit(char x) noexcept;
4475
-
4476
- /**
4477
- * @private
4478
- * @details A string starts with a Windows drive letter if all of the following
4479
- * are true:
4480
- *
4481
- * - its length is greater than or equal to 2
4482
- * - its first two code points are a Windows drive letter
4483
- * - its length is 2 or its third code point is U+002F (/), U+005C (\), U+003F
4484
- * (?), or U+0023 (#).
4485
- *
4486
- * https://url.spec.whatwg.org/#start-with-a-windows-drive-letter
4487
- */
4488
- inline constexpr bool is_windows_drive_letter(std::string_view input) noexcept;
4489
-
4490
- /**
4491
- * @private
4492
- * @details A normalized Windows drive letter is a Windows drive letter of which
4493
- * the second code point is U+003A (:).
4494
- */
4495
- inline constexpr bool is_normalized_windows_drive_letter(
4496
- std::string_view input) noexcept;
4497
-
4498
- /**
4499
- * @private
4500
- * Returns true if an input is an ipv4 address. It is assumed that the string
4501
- * does not contain uppercase ASCII characters (the input should have been
4502
- * lowered cased before calling this function) and is not empty.
4503
- */
4504
- ada_really_inline constexpr bool is_ipv4(std::string_view view) noexcept;
4505
-
4506
- /**
4507
- * @private
4508
- * Returns a bitset. If the first bit is set, then at least one character needs
4509
- * percent encoding. If the second bit is set, a \\ is found. If the third bit
4510
- * is set then we have a dot. If the fourth bit is set, then we have a percent
4511
- * character.
4512
- */
4513
- ada_really_inline constexpr uint8_t path_signature(
4514
- std::string_view input) noexcept;
4515
-
4516
- /**
4517
- * @private
4518
- * Returns true if the length of the domain name and its labels are according to
4519
- * the specifications. The length of the domain must be 255 octets (253
4520
- * characters not including the last 2 which are the empty label reserved at the
4521
- * end). When the empty label is included (a dot at the end), the domain name
4522
- * can have 254 characters. The length of a label must be at least 1 and at most
4523
- * 63 characters.
4524
- * @see section 3.1. of https://www.rfc-editor.org/rfc/rfc1034
4525
- * @see https://www.unicode.org/reports/tr46/#ToASCII
4526
- */
4527
- ada_really_inline constexpr bool verify_dns_length(
4528
- std::string_view input) noexcept;
4529
-
4530
- } // namespace ada::checkers
4531
-
4532
- #endif // ADA_CHECKERS_H
4533
- /* end file include/ada/checkers.h */
4534
4719
  /* begin file include/ada/url_components.h */
4535
4720
  /**
4536
4721
  * @file url_components.h
4537
- * @brief Declaration for the URL Components
4722
+ * @brief URL component offset representation for url_aggregator.
4723
+ *
4724
+ * This file defines the `url_components` struct which stores byte offsets
4725
+ * into a URL string buffer. It is used internally by `url_aggregator` to
4726
+ * efficiently locate URL components without storing separate strings.
4538
4727
  */
4539
4728
  #ifndef ADA_URL_COMPONENTS_H
4540
4729
  #define ADA_URL_COMPONENTS_H
@@ -4542,14 +4731,32 @@ ada_really_inline constexpr bool verify_dns_length(
4542
4731
  namespace ada {
4543
4732
 
4544
4733
  /**
4545
- * @brief URL Component representations using offsets.
4734
+ * @brief Stores byte offsets for URL components within a buffer.
4735
+ *
4736
+ * The `url_components` struct uses 32-bit offsets to track the boundaries
4737
+ * of each URL component within a single string buffer. This enables efficient
4738
+ * component extraction without additional memory allocations.
4546
4739
  *
4547
- * @details We design the url_components struct so that it is as small
4548
- * and simple as possible. This version uses 32 bytes.
4740
+ * Component layout in a URL:
4741
+ * ```
4742
+ * https://user:pass@example.com:1234/foo/bar?baz#quux
4743
+ * | | | | ^^^^| | |
4744
+ * | | | | | | | `----- hash_start
4745
+ * | | | | | | `--------- search_start
4746
+ * | | | | | `----------------- pathname_start
4747
+ * | | | | `--------------------- port
4748
+ * | | | `----------------------- host_end
4749
+ * | | `---------------------------------- host_start
4750
+ * | `--------------------------------------- username_end
4751
+ * `--------------------------------------------- protocol_end
4752
+ * ```
4549
4753
  *
4550
- * This struct is used to extract components from a single 'href'.
4754
+ * @note The 32-bit offsets limit URLs to 4GB in length.
4755
+ * @note A value of `omitted` (UINT32_MAX) indicates the component is not
4756
+ * present.
4551
4757
  */
4552
4758
  struct url_components {
4759
+ /** Sentinel value indicating a component is not present. */
4553
4760
  constexpr static uint32_t omitted = uint32_t(-1);
4554
4761
 
4555
4762
  url_components() = default;
@@ -4559,47 +4766,43 @@ struct url_components {
4559
4766
  url_components &operator=(const url_components &u) = default;
4560
4767
  ~url_components() = default;
4561
4768
 
4562
- /*
4563
- * By using 32-bit integers, we implicitly assume that the URL string
4564
- * cannot exceed 4 GB.
4565
- *
4566
- * https://user:pass@example.com:1234/foo/bar?baz#quux
4567
- * | | | | ^^^^| | |
4568
- * | | | | | | | `----- hash_start
4569
- * | | | | | | `--------- search_start
4570
- * | | | | | `----------------- pathname_start
4571
- * | | | | `--------------------- port
4572
- * | | | `----------------------- host_end
4573
- * | | `---------------------------------- host_start
4574
- * | `--------------------------------------- username_end
4575
- * `--------------------------------------------- protocol_end
4576
- */
4769
+ /** Offset of the end of the protocol/scheme (position of ':'). */
4577
4770
  uint32_t protocol_end{0};
4771
+
4578
4772
  /**
4579
- * Username end is not `omitted` by default to make username and password
4580
- * getters less costly to implement.
4773
+ * Offset of the end of the username.
4774
+ * Initialized to 0 (not `omitted`) to simplify username/password getters.
4581
4775
  */
4582
4776
  uint32_t username_end{0};
4777
+
4778
+ /** Offset of the start of the host. */
4583
4779
  uint32_t host_start{0};
4780
+
4781
+ /** Offset of the end of the host. */
4584
4782
  uint32_t host_end{0};
4783
+
4784
+ /** Port number, or `omitted` if no port is specified. */
4585
4785
  uint32_t port{omitted};
4786
+
4787
+ /** Offset of the start of the pathname. */
4586
4788
  uint32_t pathname_start{0};
4789
+
4790
+ /** Offset of the '?' starting the query, or `omitted` if no query. */
4587
4791
  uint32_t search_start{omitted};
4792
+
4793
+ /** Offset of the '#' starting the fragment, or `omitted` if no fragment. */
4588
4794
  uint32_t hash_start{omitted};
4589
4795
 
4590
4796
  /**
4591
- * Check the following conditions:
4592
- * protocol_end < username_end < ... < hash_start,
4593
- * expect when a value is omitted. It also computes
4594
- * a lower bound on the possible string length that may match these
4595
- * offsets.
4596
- * @return true if the offset values are
4597
- * consistent with a possible URL string
4797
+ * Validates that offsets are in ascending order and consistent.
4798
+ * Useful for debugging to detect internal corruption.
4799
+ * @return `true` if offsets are consistent, `false` otherwise.
4598
4800
  */
4599
4801
  [[nodiscard]] constexpr bool check_offset_consistency() const noexcept;
4600
4802
 
4601
4803
  /**
4602
- * Converts a url_components to JSON stringified version.
4804
+ * Returns a JSON string representation of the offsets for debugging.
4805
+ * @return A JSON-formatted string with all offset values.
4603
4806
  */
4604
4807
  [[nodiscard]] std::string to_string() const;
4605
4808
 
@@ -4622,15 +4825,26 @@ struct url_aggregator;
4622
4825
  // }
4623
4826
 
4624
4827
  /**
4625
- * @brief Generic URL struct reliant on std::string instantiation.
4828
+ * @brief Represents a parsed URL with individual string components.
4829
+ *
4830
+ * The `url` struct stores each URL component (scheme, username, password,
4831
+ * host, port, path, query, fragment) as a separate `std::string`. This
4832
+ * provides flexibility but incurs more memory allocations compared to
4833
+ * `url_aggregator`.
4834
+ *
4835
+ * **When to use `ada::url`:**
4836
+ * - When you need to frequently modify individual URL components
4837
+ * - When you want independent ownership of component strings
4626
4838
  *
4627
- * @details To disambiguate from a valid URL string it can also be referred to
4628
- * as a URL record. A URL is a struct that represents a universal identifier.
4629
- * Unlike the url_aggregator, the ada::url represents the different components
4630
- * of a parsed URL as independent std::string instances. This makes the
4631
- * structure heavier and more reliant on memory allocations. When getting
4632
- * components from the parsed URL, a new std::string is typically constructed.
4839
+ * **When to use `ada::url_aggregator` instead:**
4840
+ * - For read-mostly operations on parsed URLs
4841
+ * - When memory efficiency is important
4842
+ * - When you only need string_view access to components
4633
4843
  *
4844
+ * @note This type is returned when parsing with `ada::parse<ada::url>()`.
4845
+ * By default, `ada::parse()` returns `ada::url_aggregator`.
4846
+ *
4847
+ * @see url_aggregator For a more memory-efficient URL representation
4634
4848
  * @see https://url.spec.whatwg.org/#url-representation
4635
4849
  */
4636
4850
  struct url : url_base {
@@ -4689,177 +4903,217 @@ struct url : url_base {
4689
4903
  */
4690
4904
  std::optional<std::string> hash{};
4691
4905
 
4692
- /** @return true if it has an host but it is the empty string */
4906
+ /**
4907
+ * Checks if the URL has an empty hostname (host is set but empty string).
4908
+ * @return `true` if host exists but is empty, `false` otherwise.
4909
+ */
4693
4910
  [[nodiscard]] inline bool has_empty_hostname() const noexcept;
4694
- /** @return true if the URL has a (non default) port */
4911
+
4912
+ /**
4913
+ * Checks if the URL has a non-default port explicitly specified.
4914
+ * @return `true` if a port is present, `false` otherwise.
4915
+ */
4695
4916
  [[nodiscard]] inline bool has_port() const noexcept;
4696
- /** @return true if it has a host (included an empty host) */
4917
+
4918
+ /**
4919
+ * Checks if the URL has a hostname (including empty hostnames).
4920
+ * @return `true` if host is present, `false` otherwise.
4921
+ */
4697
4922
  [[nodiscard]] inline bool has_hostname() const noexcept;
4923
+
4924
+ /**
4925
+ * Validates whether the hostname is a valid domain according to RFC 1034.
4926
+ * Checks that the domain and its labels have valid lengths (max 255 octets
4927
+ * total, max 63 octets per label).
4928
+ * @return `true` if the domain is valid, `false` otherwise.
4929
+ */
4698
4930
  [[nodiscard]] bool has_valid_domain() const noexcept override;
4699
4931
 
4700
4932
  /**
4701
- * Returns a JSON string representation of this URL.
4933
+ * Returns a JSON string representation of this URL for debugging.
4934
+ * @return A JSON-formatted string with all URL components.
4702
4935
  */
4703
4936
  [[nodiscard]] std::string to_string() const override;
4704
4937
 
4705
4938
  /**
4939
+ * Returns the full serialized URL (the href).
4940
+ * @return The complete URL string (allocates a new string).
4706
4941
  * @see https://url.spec.whatwg.org/#dom-url-href
4707
- * @see https://url.spec.whatwg.org/#concept-url-serializer
4708
4942
  */
4709
- [[nodiscard]] ada_really_inline std::string get_href() const noexcept;
4943
+ [[nodiscard]] ada_really_inline std::string get_href() const;
4710
4944
 
4711
4945
  /**
4712
- * The origin getter steps are to return the serialization of this's URL's
4713
- * origin. [HTML]
4714
- * @return a newly allocated string.
4946
+ * Returns the URL's origin as a string (scheme + host + port for special
4947
+ * URLs).
4948
+ * @return A newly allocated string containing the serialized origin.
4715
4949
  * @see https://url.spec.whatwg.org/#concept-url-origin
4716
4950
  */
4717
- [[nodiscard]] std::string get_origin() const noexcept override;
4951
+ [[nodiscard]] std::string get_origin() const override;
4718
4952
 
4719
4953
  /**
4720
- * The protocol getter steps are to return this's URL's scheme, followed by
4721
- * U+003A (:).
4722
- * @return a newly allocated string.
4954
+ * Returns the URL's scheme followed by a colon (e.g., "https:").
4955
+ * @return A newly allocated string with the protocol.
4723
4956
  * @see https://url.spec.whatwg.org/#dom-url-protocol
4724
4957
  */
4725
- [[nodiscard]] std::string get_protocol() const noexcept;
4958
+ [[nodiscard]] std::string get_protocol() const;
4726
4959
 
4727
4960
  /**
4728
- * Return url's host, serialized, followed by U+003A (:) and url's port,
4729
- * serialized.
4730
- * When there is no host, this function returns the empty string.
4731
- * @return a newly allocated string.
4961
+ * Returns the URL's host and port (e.g., "example.com:8080").
4962
+ * If no port is set, returns just the host. Returns empty string if no host.
4963
+ * @return A newly allocated string with host:port.
4732
4964
  * @see https://url.spec.whatwg.org/#dom-url-host
4733
4965
  */
4734
- [[nodiscard]] std::string get_host() const noexcept;
4966
+ [[nodiscard]] std::string get_host() const;
4735
4967
 
4736
4968
  /**
4737
- * Return this's URL's host, serialized.
4738
- * When there is no host, this function returns the empty string.
4739
- * @return a newly allocated string.
4969
+ * Returns the URL's hostname (without port).
4970
+ * Returns empty string if no host is set.
4971
+ * @return A newly allocated string with the hostname.
4740
4972
  * @see https://url.spec.whatwg.org/#dom-url-hostname
4741
4973
  */
4742
- [[nodiscard]] std::string get_hostname() const noexcept;
4974
+ [[nodiscard]] std::string get_hostname() const;
4743
4975
 
4744
4976
  /**
4745
- * The pathname getter steps are to return the result of URL path serializing
4746
- * this's URL.
4747
- * @return a newly allocated string.
4977
+ * Returns the URL's path component.
4978
+ * @return A string_view pointing to the path.
4748
4979
  * @see https://url.spec.whatwg.org/#dom-url-pathname
4749
4980
  */
4750
4981
  [[nodiscard]] constexpr std::string_view get_pathname() const noexcept;
4751
4982
 
4752
4983
  /**
4753
- * Compute the pathname length in bytes without instantiating a view or a
4754
- * string.
4755
- * @return size of the pathname in bytes
4984
+ * Returns the byte length of the pathname without creating a string.
4985
+ * @return Size of the pathname in bytes.
4756
4986
  * @see https://url.spec.whatwg.org/#dom-url-pathname
4757
4987
  */
4758
4988
  [[nodiscard]] ada_really_inline size_t get_pathname_length() const noexcept;
4759
4989
 
4760
4990
  /**
4761
- * Return U+003F (?), followed by this's URL's query.
4762
- * @return a newly allocated string.
4991
+ * Returns the URL's query string prefixed with '?' (e.g., "?foo=bar").
4992
+ * Returns empty string if no query is set.
4993
+ * @return A newly allocated string with the search/query.
4763
4994
  * @see https://url.spec.whatwg.org/#dom-url-search
4764
4995
  */
4765
- [[nodiscard]] std::string get_search() const noexcept;
4996
+ [[nodiscard]] std::string get_search() const;
4766
4997
 
4767
4998
  /**
4768
- * The username getter steps are to return this's URL's username.
4769
- * @return a constant reference to the underlying string.
4999
+ * Returns the URL's username component.
5000
+ * @return A constant reference to the username string.
4770
5001
  * @see https://url.spec.whatwg.org/#dom-url-username
4771
5002
  */
4772
5003
  [[nodiscard]] const std::string &get_username() const noexcept;
4773
5004
 
4774
5005
  /**
4775
- * @return Returns true on successful operation.
5006
+ * Sets the URL's username, percent-encoding special characters.
5007
+ * @param input The new username value.
5008
+ * @return `true` on success, `false` if the URL cannot have credentials.
4776
5009
  * @see https://url.spec.whatwg.org/#dom-url-username
4777
5010
  */
4778
5011
  bool set_username(std::string_view input);
4779
5012
 
4780
5013
  /**
4781
- * @return Returns true on success.
5014
+ * Sets the URL's password, percent-encoding special characters.
5015
+ * @param input The new password value.
5016
+ * @return `true` on success, `false` if the URL cannot have credentials.
4782
5017
  * @see https://url.spec.whatwg.org/#dom-url-password
4783
5018
  */
4784
5019
  bool set_password(std::string_view input);
4785
5020
 
4786
5021
  /**
4787
- * @return Returns true on success.
5022
+ * Sets the URL's port from a string (e.g., "8080").
5023
+ * @param input The port string. Empty string removes the port.
5024
+ * @return `true` on success, `false` if the URL cannot have a port.
4788
5025
  * @see https://url.spec.whatwg.org/#dom-url-port
4789
5026
  */
4790
5027
  bool set_port(std::string_view input);
4791
5028
 
4792
5029
  /**
4793
- * This function always succeeds.
5030
+ * Sets the URL's fragment/hash (the part after '#').
5031
+ * @param input The new hash value (with or without leading '#').
4794
5032
  * @see https://url.spec.whatwg.org/#dom-url-hash
4795
5033
  */
4796
5034
  void set_hash(std::string_view input);
4797
5035
 
4798
5036
  /**
4799
- * This function always succeeds.
5037
+ * Sets the URL's query string (the part after '?').
5038
+ * @param input The new query value (with or without leading '?').
4800
5039
  * @see https://url.spec.whatwg.org/#dom-url-search
4801
5040
  */
4802
5041
  void set_search(std::string_view input);
4803
5042
 
4804
5043
  /**
4805
- * @return Returns true on success.
4806
- * @see https://url.spec.whatwg.org/#dom-url-search
5044
+ * Sets the URL's pathname.
5045
+ * @param input The new path value.
5046
+ * @return `true` on success, `false` if the URL has an opaque path.
5047
+ * @see https://url.spec.whatwg.org/#dom-url-pathname
4807
5048
  */
4808
5049
  bool set_pathname(std::string_view input);
4809
5050
 
4810
5051
  /**
4811
- * @return Returns true on success.
5052
+ * Sets the URL's host (hostname and optionally port).
5053
+ * @param input The new host value (e.g., "example.com:8080").
5054
+ * @return `true` on success, `false` if parsing fails.
4812
5055
  * @see https://url.spec.whatwg.org/#dom-url-host
4813
5056
  */
4814
5057
  bool set_host(std::string_view input);
4815
5058
 
4816
5059
  /**
4817
- * @return Returns true on success.
5060
+ * Sets the URL's hostname (without port).
5061
+ * @param input The new hostname value.
5062
+ * @return `true` on success, `false` if parsing fails.
4818
5063
  * @see https://url.spec.whatwg.org/#dom-url-hostname
4819
5064
  */
4820
5065
  bool set_hostname(std::string_view input);
4821
5066
 
4822
5067
  /**
4823
- * @return Returns true on success.
5068
+ * Sets the URL's protocol/scheme.
5069
+ * @param input The new protocol (with or without trailing ':').
5070
+ * @return `true` on success, `false` if the scheme is invalid.
4824
5071
  * @see https://url.spec.whatwg.org/#dom-url-protocol
4825
5072
  */
4826
5073
  bool set_protocol(std::string_view input);
4827
5074
 
4828
5075
  /**
5076
+ * Replaces the entire URL by parsing a new href string.
5077
+ * @param input The new URL string to parse.
5078
+ * @return `true` on success, `false` if parsing fails.
4829
5079
  * @see https://url.spec.whatwg.org/#dom-url-href
4830
5080
  */
4831
5081
  bool set_href(std::string_view input);
4832
5082
 
4833
5083
  /**
4834
- * The password getter steps are to return this's URL's password.
4835
- * @return a constant reference to the underlying string.
5084
+ * Returns the URL's password component.
5085
+ * @return A constant reference to the password string.
4836
5086
  * @see https://url.spec.whatwg.org/#dom-url-password
4837
5087
  */
4838
5088
  [[nodiscard]] const std::string &get_password() const noexcept;
4839
5089
 
4840
5090
  /**
4841
- * Return this's URL's port, serialized.
4842
- * @return a newly constructed string representing the port.
5091
+ * Returns the URL's port as a string (e.g., "8080").
5092
+ * Returns empty string if no port is set.
5093
+ * @return A newly allocated string with the port.
4843
5094
  * @see https://url.spec.whatwg.org/#dom-url-port
4844
5095
  */
4845
- [[nodiscard]] std::string get_port() const noexcept;
5096
+ [[nodiscard]] std::string get_port() const;
4846
5097
 
4847
5098
  /**
4848
- * Return U+0023 (#), followed by this's URL's fragment.
4849
- * @return a newly constructed string representing the hash.
5099
+ * Returns the URL's fragment prefixed with '#' (e.g., "#section").
5100
+ * Returns empty string if no fragment is set.
5101
+ * @return A newly allocated string with the hash.
4850
5102
  * @see https://url.spec.whatwg.org/#dom-url-hash
4851
5103
  */
4852
- [[nodiscard]] std::string get_hash() const noexcept;
5104
+ [[nodiscard]] std::string get_hash() const;
4853
5105
 
4854
5106
  /**
4855
- * A URL includes credentials if its username or password is not the empty
4856
- * string.
5107
+ * Checks if the URL has credentials (non-empty username or password).
5108
+ * @return `true` if username or password is non-empty, `false` otherwise.
4857
5109
  */
4858
5110
  [[nodiscard]] ada_really_inline bool has_credentials() const noexcept;
4859
5111
 
4860
5112
  /**
4861
- * Useful for implementing efficient serialization for the URL.
5113
+ * Returns the URL component offsets for efficient serialization.
4862
5114
  *
5115
+ * The components represent byte offsets into the serialized URL:
5116
+ * ```
4863
5117
  * https://user:pass@example.com:1234/foo/bar?baz#quux
4864
5118
  * | | | | ^^^^| | |
4865
5119
  * | | | | | | | `----- hash_start
@@ -4870,19 +5124,23 @@ struct url : url_base {
4870
5124
  * | | `---------------------------------- host_start
4871
5125
  * | `--------------------------------------- username_end
4872
5126
  * `--------------------------------------------- protocol_end
4873
- *
4874
- * Inspired after servo/url
4875
- *
4876
- * @return a newly constructed component.
4877
- *
4878
- * @see
4879
- * https://github.com/servo/rust-url/blob/b65a45515c10713f6d212e6726719a020203cc98/url/src/quirks.rs#L31
5127
+ * ```
5128
+ * @return A newly constructed url_components struct.
5129
+ * @see https://github.com/servo/rust-url
4880
5130
  */
4881
5131
  [[nodiscard]] ada_really_inline ada::url_components get_components()
4882
5132
  const noexcept;
4883
- /** @return true if the URL has a hash component */
5133
+
5134
+ /**
5135
+ * Checks if the URL has a fragment/hash component.
5136
+ * @return `true` if hash is present, `false` otherwise.
5137
+ */
4884
5138
  [[nodiscard]] constexpr bool has_hash() const noexcept override;
4885
- /** @return true if the URL has a search component */
5139
+
5140
+ /**
5141
+ * Checks if the URL has a query/search component.
5142
+ * @return `true` if query is present, `false` otherwise.
5143
+ */
4886
5144
  [[nodiscard]] constexpr bool has_search() const noexcept override;
4887
5145
 
4888
5146
  private:
@@ -4891,7 +5149,7 @@ struct url : url_base {
4891
5149
  friend ada::url_aggregator ada::parser::parse_url<ada::url_aggregator>(
4892
5150
  std::string_view, const ada::url_aggregator *);
4893
5151
  friend void ada::helpers::strip_trailing_spaces_from_opaque_path<ada::url>(
4894
- ada::url &url) noexcept;
5152
+ ada::url &url);
4895
5153
 
4896
5154
  friend ada::url ada::parser::parse_url_impl<ada::url, true>(std::string_view,
4897
5155
  const ada::url *);
@@ -4998,7 +5256,7 @@ struct url : url_base {
4998
5256
  * Take the scheme from another URL. The scheme string is moved from the
4999
5257
  * provided url.
5000
5258
  */
5001
- constexpr void copy_scheme(ada::url &&u) noexcept;
5259
+ constexpr void copy_scheme(ada::url &&u);
5002
5260
 
5003
5261
  /**
5004
5262
  * Take the scheme from another URL. The scheme string is copied from the
@@ -5014,22 +5272,72 @@ inline std::ostream &operator<<(std::ostream &out, const ada::url &u);
5014
5272
  #endif // ADA_URL_H
5015
5273
  /* end file include/ada/url.h */
5016
5274
 
5017
- #if ADA_INCLUDE_URL_PATTERN
5018
- #endif // ADA_INCLUDE_URL_PATTERN
5019
-
5020
5275
  namespace ada {
5021
5276
 
5277
+ /**
5278
+ * Result type for URL parsing operations.
5279
+ *
5280
+ * Uses `tl::expected` to represent either a successfully parsed URL or an
5281
+ * error. This allows for exception-free error handling.
5282
+ *
5283
+ * @tparam result_type The URL type to return (default: `ada::url_aggregator`)
5284
+ *
5285
+ * @example
5286
+ * ```cpp
5287
+ * ada::result<ada::url_aggregator> result = ada::parse("https://example.com");
5288
+ * if (result) {
5289
+ * // Success: use result.value() or *result
5290
+ * } else {
5291
+ * // Error: handle result.error()
5292
+ * }
5293
+ * ```
5294
+ */
5022
5295
  template <class result_type = ada::url_aggregator>
5023
5296
  using result = tl::expected<result_type, ada::errors>;
5024
5297
 
5025
5298
  /**
5026
- * The URL parser takes a scalar value string input, with an optional null or
5027
- * base URL base (default null). The parser assumes the input is a valid ASCII
5028
- * or UTF-8 string.
5299
+ * Parses a URL string according to the WHATWG URL Standard.
5300
+ *
5301
+ * This is the main entry point for URL parsing in Ada. The function takes
5302
+ * a string input and optionally a base URL for resolving relative URLs.
5303
+ *
5304
+ * @tparam result_type The URL type to return. Can be either `ada::url` or
5305
+ * `ada::url_aggregator` (default). The `url_aggregator` type is more
5306
+ * memory-efficient as it stores components as offsets into a single
5307
+ * buffer.
5308
+ *
5309
+ * @param input The URL string to parse. Must be valid ASCII or UTF-8 encoded.
5310
+ * Leading and trailing whitespace is automatically trimmed.
5311
+ * @param base_url Optional pointer to a base URL for resolving relative URLs.
5312
+ * If nullptr (default), only absolute URLs can be parsed successfully.
5313
+ *
5314
+ * @return A `result<result_type>` containing either the parsed URL on success,
5315
+ * or an error code on failure. Use the boolean conversion or
5316
+ * `has_value()` to check for success.
5317
+ *
5318
+ * @note The parser is fully compliant with the WHATWG URL Standard.
5319
+ *
5320
+ * @example
5321
+ * ```cpp
5322
+ * // Parse an absolute URL
5323
+ * auto url = ada::parse("https://user:pass@example.com:8080/path?query#hash");
5324
+ * if (url) {
5325
+ * std::cout << url->get_hostname(); // "example.com"
5326
+ * std::cout << url->get_pathname(); // "/path"
5327
+ * }
5029
5328
  *
5030
- * @param input the string input to analyze (must be valid ASCII or UTF-8)
5031
- * @param base_url the optional URL input to use as a base url.
5032
- * @return a parsed URL.
5329
+ * // Parse a relative URL with a base
5330
+ * auto base = ada::parse("https://example.com/dir/");
5331
+ * if (base) {
5332
+ * auto relative = ada::parse("../other/page", &*base);
5333
+ * if (relative) {
5334
+ * std::cout << relative->get_href(); //
5335
+ * "https://example.com/other/page"
5336
+ * }
5337
+ * }
5338
+ * ```
5339
+ *
5340
+ * @see https://url.spec.whatwg.org/#url-parsing
5033
5341
  */
5034
5342
  template <class result_type = ada::url_aggregator>
5035
5343
  ada_warn_unused ada::result<result_type> parse(
@@ -5041,23 +5349,56 @@ extern template ada::result<url_aggregator> parse<url_aggregator>(
5041
5349
  std::string_view input, const url_aggregator* base_url);
5042
5350
 
5043
5351
  /**
5044
- * Verifies whether the URL strings can be parsed. The function assumes
5045
- * that the inputs are valid ASCII or UTF-8 strings.
5352
+ * Checks whether a URL string can be successfully parsed.
5353
+ *
5354
+ * This is a fast validation function that checks if a URL string is valid
5355
+ * according to the WHATWG URL Standard without fully constructing a URL
5356
+ * object. Use this when you only need to validate URLs without needing
5357
+ * their parsed components.
5358
+ *
5359
+ * @param input The URL string to validate. Must be valid ASCII or UTF-8.
5360
+ * @param base_input Optional pointer to a base URL string for resolving
5361
+ * relative URLs. If nullptr (default), the input is validated as
5362
+ * an absolute URL.
5363
+ *
5364
+ * @return `true` if the URL can be parsed successfully, `false` otherwise.
5365
+ *
5366
+ * @example
5367
+ * ```cpp
5368
+ * // Check absolute URL
5369
+ * bool valid = ada::can_parse("https://example.com"); // true
5370
+ * bool invalid = ada::can_parse("not a url"); // false
5371
+ *
5372
+ * // Check relative URL with base
5373
+ * std::string_view base = "https://example.com/";
5374
+ * bool relative_valid = ada::can_parse("../path", &base); // true
5375
+ * ```
5376
+ *
5046
5377
  * @see https://url.spec.whatwg.org/#dom-url-canparse
5047
- * @return If URL can be parsed or not.
5048
5378
  */
5049
5379
  bool can_parse(std::string_view input,
5050
5380
  const std::string_view* base_input = nullptr);
5051
5381
 
5052
5382
  #if ADA_INCLUDE_URL_PATTERN
5053
5383
  /**
5054
- * Implementation of the URL pattern parsing algorithm.
5055
- * @see https://urlpattern.spec.whatwg.org
5384
+ * Parses a URL pattern according to the URLPattern specification.
5385
+ *
5386
+ * URL patterns provide a syntax for matching URLs against patterns, similar
5387
+ * to how regular expressions match strings. This is useful for routing and
5388
+ * URL-based dispatching.
5389
+ *
5390
+ * @tparam regex_provider The regex implementation to use for pattern matching.
5391
+ *
5392
+ * @param input Either a URL pattern string (valid UTF-8) or a URLPatternInit
5393
+ * struct specifying individual component patterns.
5394
+ * @param base_url Optional pointer to a base URL string (valid UTF-8) for
5395
+ * resolving relative patterns.
5396
+ * @param options Optional pointer to configuration options (e.g., ignore_case).
5056
5397
  *
5057
- * @param input valid UTF-8 string or URLPatternInit struct
5058
- * @param base_url an optional valid UTF-8 string
5059
- * @param options an optional url_pattern_options struct
5060
- * @return url_pattern instance
5398
+ * @return A `tl::expected` containing either the parsed url_pattern on success,
5399
+ * or an error code on failure.
5400
+ *
5401
+ * @see https://urlpattern.spec.whatwg.org
5061
5402
  */
5062
5403
  template <url_pattern_regex::regex_concept regex_provider>
5063
5404
  ada_warn_unused tl::expected<url_pattern<regex_provider>, errors>
@@ -5067,9 +5408,14 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init>&& input,
5067
5408
  #endif // ADA_INCLUDE_URL_PATTERN
5068
5409
 
5069
5410
  /**
5070
- * Computes a href string from a file path. The function assumes
5071
- * that the input is a valid ASCII or UTF-8 string.
5072
- * @return a href string (starts with file:://)
5411
+ * Converts a file system path to a file:// URL.
5412
+ *
5413
+ * Creates a properly formatted file URL from a local file system path.
5414
+ * Handles platform-specific path separators and percent-encoding.
5415
+ *
5416
+ * @param path The file system path to convert. Must be valid ASCII or UTF-8.
5417
+ *
5418
+ * @return A file:// URL string representing the given path.
5073
5419
  */
5074
5420
  std::string href_from_file(std::string_view path);
5075
5421
  } // namespace ada
@@ -5088,6 +5434,7 @@ std::string href_from_file(std::string_view path);
5088
5434
  #include <iostream>
5089
5435
  #endif // ADA_TESTING
5090
5436
 
5437
+ #if ADA_INCLUDE_URL_PATTERN
5091
5438
  namespace ada {
5092
5439
 
5093
5440
  enum class url_pattern_part_type : uint8_t {
@@ -5104,6 +5451,19 @@ enum class url_pattern_part_type : uint8_t {
5104
5451
  FULL_WILDCARD,
5105
5452
  };
5106
5453
 
5454
+ // Pattern type for fast-path matching optimization.
5455
+ // This allows skipping expensive regex evaluation for common simple patterns.
5456
+ enum class url_pattern_component_type : uint8_t {
5457
+ // Pattern is "^$" - only matches empty string
5458
+ EMPTY,
5459
+ // Pattern is "^<literal>$" - exact string match (no regex needed)
5460
+ EXACT_MATCH,
5461
+ // Pattern is "^(.*)$" - matches anything (full wildcard)
5462
+ FULL_WILDCARD,
5463
+ // Pattern requires actual regex evaluation
5464
+ REGEXP,
5465
+ };
5466
+
5107
5467
  enum class url_pattern_part_modifier : uint8_t {
5108
5468
  // The part does not have a modifier.
5109
5469
  none,
@@ -5223,11 +5583,15 @@ class url_pattern_component {
5223
5583
  url_pattern_component(std::string&& new_pattern,
5224
5584
  typename regex_provider::regex_type&& new_regexp,
5225
5585
  std::vector<std::string>&& new_group_name_list,
5226
- bool new_has_regexp_groups)
5586
+ bool new_has_regexp_groups,
5587
+ url_pattern_component_type new_type,
5588
+ std::string&& new_exact_match_value = {})
5227
5589
  : regexp(std::move(new_regexp)),
5228
5590
  pattern(std::move(new_pattern)),
5229
5591
  group_name_list(std::move(new_group_name_list)),
5230
- has_regexp_groups(new_has_regexp_groups) {}
5592
+ exact_match_value(std::move(new_exact_match_value)),
5593
+ has_regexp_groups(new_has_regexp_groups),
5594
+ type(new_type) {}
5231
5595
 
5232
5596
  // @see https://urlpattern.spec.whatwg.org/#compile-a-component
5233
5597
  template <url_pattern_encoding_callback F>
@@ -5240,6 +5604,16 @@ class url_pattern_component {
5240
5604
  std::string&& input,
5241
5605
  std::vector<std::optional<std::string>>&& exec_result);
5242
5606
 
5607
+ // Fast path test that returns true/false without constructing result groups.
5608
+ // Uses cached pattern type to skip regex evaluation for simple patterns.
5609
+ bool fast_test(std::string_view input) const noexcept;
5610
+
5611
+ // Fast path match that returns capture groups without regex for simple
5612
+ // patterns. Returns nullopt if pattern doesn't match, otherwise returns
5613
+ // capture groups.
5614
+ std::optional<std::vector<std::optional<std::string>>> fast_match(
5615
+ std::string_view input) const;
5616
+
5243
5617
  #if ADA_TESTING
5244
5618
  friend void PrintTo(const url_pattern_component& component,
5245
5619
  std::ostream* os) {
@@ -5255,7 +5629,11 @@ class url_pattern_component {
5255
5629
  typename regex_provider::regex_type regexp{};
5256
5630
  std::string pattern{};
5257
5631
  std::vector<std::string> group_name_list{};
5632
+ // For EXACT_MATCH type: the literal string to compare against
5633
+ std::string exact_match_value{};
5258
5634
  bool has_regexp_groups = false;
5635
+ // Cached pattern type for fast-path optimization
5636
+ url_pattern_component_type type = url_pattern_component_type::REGEXP;
5259
5637
  };
5260
5638
 
5261
5639
  // A URLPattern input can be either a string or a URLPatternInit object.
@@ -5287,14 +5665,28 @@ struct url_pattern_options {
5287
5665
  #endif // ADA_TESTING
5288
5666
  };
5289
5667
 
5290
- // URLPattern is a Web Platform standard API for matching URLs against a
5291
- // pattern syntax (think of it as a regular expression for URLs). It is
5292
- // defined in https://wicg.github.io/urlpattern.
5293
- // More information about the URL Pattern syntax can be found at
5294
- // https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API
5295
- //
5296
- // We require all strings to be valid UTF-8: it is the user's responsibility
5297
- // to ensure that the provided strings are valid UTF-8.
5668
+ /**
5669
+ * @brief URL pattern matching class implementing the URLPattern API.
5670
+ *
5671
+ * URLPattern provides a way to match URLs against patterns with wildcards
5672
+ * and named capture groups. It's useful for routing, URL-based dispatching,
5673
+ * and URL validation.
5674
+ *
5675
+ * Pattern syntax supports:
5676
+ * - Literal text matching
5677
+ * - Named groups: `:name` (matches up to the next separator)
5678
+ * - Wildcards: `*` (matches everything)
5679
+ * - Custom regex: `(pattern)`
5680
+ * - Optional segments: `:name?`
5681
+ * - Repeated segments: `:name+`, `:name*`
5682
+ *
5683
+ * @tparam regex_provider The regex implementation to use for pattern matching.
5684
+ * Must satisfy the url_pattern_regex::regex_concept.
5685
+ *
5686
+ * @note All string inputs must be valid UTF-8.
5687
+ *
5688
+ * @see https://urlpattern.spec.whatwg.org/
5689
+ */
5298
5690
  template <url_pattern_regex::regex_concept regex_provider>
5299
5691
  class url_pattern {
5300
5692
  public:
@@ -5347,6 +5739,13 @@ class url_pattern {
5347
5739
  // @see https://urlpattern.spec.whatwg.org/#url-pattern-has-regexp-groups
5348
5740
  [[nodiscard]] bool has_regexp_groups() const;
5349
5741
 
5742
+ // Helper to test all components at once. Returns true if all match.
5743
+ [[nodiscard]] bool test_components(
5744
+ std::string_view protocol, std::string_view username,
5745
+ std::string_view password, std::string_view hostname,
5746
+ std::string_view port, std::string_view pathname, std::string_view search,
5747
+ std::string_view hash) const;
5748
+
5350
5749
  #if ADA_TESTING
5351
5750
  friend void PrintTo(const url_pattern& c, std::ostream* os) {
5352
5751
  *os << "protocol_component: '" << c.get_protocol() << ", ";
@@ -5420,9 +5819,8 @@ class url_pattern {
5420
5819
  */
5421
5820
  bool ignore_case_ = false;
5422
5821
  };
5423
-
5424
5822
  } // namespace ada
5425
-
5823
+ #endif // ADA_INCLUDE_URL_PATTERN
5426
5824
  #endif
5427
5825
  /* end file include/ada/url_pattern.h */
5428
5826
  /* begin file include/ada/url_pattern_helpers.h */
@@ -5438,6 +5836,7 @@ class url_pattern {
5438
5836
  #include <tuple>
5439
5837
  #include <vector>
5440
5838
 
5839
+ #if ADA_INCLUDE_URL_PATTERN
5441
5840
  namespace ada {
5442
5841
  enum class errors : uint8_t;
5443
5842
  }
@@ -5471,8 +5870,8 @@ enum class token_policy {
5471
5870
  // @see https://urlpattern.spec.whatwg.org/#tokens
5472
5871
  class token {
5473
5872
  public:
5474
- token(token_type _type, size_t _index, std::string&& _value)
5475
- : type(_type), index(_index), value(std::move(_value)) {}
5873
+ token(token_type _type, size_t _index, std::string_view _value)
5874
+ : type(_type), index(_index), value(_value) {}
5476
5875
 
5477
5876
  // A token has an associated type, a string, initially "invalid-char".
5478
5877
  token_type type = token_type::INVALID_CHAR;
@@ -5483,7 +5882,7 @@ class token {
5483
5882
 
5484
5883
  // A token has an associated value, a string, initially the empty string. It
5485
5884
  // contains the code points from the pattern string represented by the token.
5486
- std::string value{};
5885
+ std::string_view value{};
5487
5886
  };
5488
5887
 
5489
5888
  // @see https://urlpattern.spec.whatwg.org/#pattern-parser
@@ -5561,7 +5960,7 @@ class Tokenizer {
5561
5960
 
5562
5961
  private:
5563
5962
  // has an associated input, a pattern string, initially the empty string.
5564
- std::string input;
5963
+ std::string_view input;
5565
5964
  // has an associated policy, a tokenize policy, initially "strict".
5566
5965
  token_policy policy;
5567
5966
  // has an associated token list, a token list, initially an empty list.
@@ -5655,7 +6054,7 @@ struct constructor_string_parser {
5655
6054
  // @see https://urlpattern.spec.whatwg.org/#make-a-component-string
5656
6055
  std::string make_component_string();
5657
6056
  // has an associated input, a string, which must be set upon creation.
5658
- std::string input;
6057
+ std::string_view input;
5659
6058
  // has an associated token list, a token list, which must be set upon
5660
6059
  // creation.
5661
6060
  std::vector<token> token_list;
@@ -5762,17 +6161,16 @@ bool protocol_component_matches_special_scheme(
5762
6161
  ada::url_pattern_component<regex_provider>& input);
5763
6162
 
5764
6163
  // @see https://urlpattern.spec.whatwg.org/#convert-a-modifier-to-a-string
5765
- std::string convert_modifier_to_string(url_pattern_part_modifier modifier);
6164
+ std::string_view convert_modifier_to_string(url_pattern_part_modifier modifier);
5766
6165
 
5767
6166
  // @see https://urlpattern.spec.whatwg.org/#generate-a-segment-wildcard-regexp
5768
6167
  std::string generate_segment_wildcard_regexp(
5769
6168
  url_pattern_compile_component_options options);
5770
6169
 
5771
6170
  } // namespace ada::url_pattern_helpers
5772
-
6171
+ #endif // ADA_INCLUDE_URL_PATTERN
5773
6172
  #endif
5774
6173
  /* end file include/ada/url_pattern_helpers.h */
5775
- #endif // ADA_INCLUDE_URL_PATTERN
5776
6174
 
5777
6175
  #include <string>
5778
6176
  #include <string_view>
@@ -6129,7 +6527,10 @@ constexpr ada::scheme::type get_scheme_type(std::string_view scheme) noexcept {
6129
6527
  /* begin file include/ada/serializers.h */
6130
6528
  /**
6131
6529
  * @file serializers.h
6132
- * @brief Definitions for the URL serializers.
6530
+ * @brief IP address serialization utilities.
6531
+ *
6532
+ * This header provides functions for converting IP addresses to their
6533
+ * string representations according to the WHATWG URL Standard.
6133
6534
  */
6134
6535
  #ifndef ADA_SERIALIZERS_H
6135
6536
  #define ADA_SERIALIZERS_H
@@ -6140,32 +6541,41 @@ constexpr ada::scheme::type get_scheme_type(std::string_view scheme) noexcept {
6140
6541
 
6141
6542
  /**
6142
6543
  * @namespace ada::serializers
6143
- * @brief Includes the definitions for URL serializers
6544
+ * @brief IP address serialization functions.
6545
+ *
6546
+ * Contains utilities for serializing IPv4 and IPv6 addresses to strings.
6144
6547
  */
6145
6548
  namespace ada::serializers {
6146
6549
 
6147
6550
  /**
6148
- * Finds and returns the longest sequence of 0 values in a ipv6 input.
6551
+ * Finds the longest consecutive sequence of zero pieces in an IPv6 address.
6552
+ * Used for :: compression in IPv6 serialization.
6553
+ *
6554
+ * @param address The 8 16-bit pieces of the IPv6 address.
6555
+ * @param[out] compress Index of the start of the longest zero sequence.
6556
+ * @param[out] compress_length Length of the longest zero sequence.
6149
6557
  */
6150
6558
  void find_longest_sequence_of_ipv6_pieces(
6151
6559
  const std::array<uint16_t, 8>& address, size_t& compress,
6152
6560
  size_t& compress_length) noexcept;
6153
6561
 
6154
6562
  /**
6155
- * Serializes an ipv6 address.
6156
- * @details An IPv6 address is a 128-bit unsigned integer that identifies a
6157
- * network address.
6563
+ * Serializes an IPv6 address to its string representation.
6564
+ *
6565
+ * @param address The 8 16-bit pieces of the IPv6 address.
6566
+ * @return The serialized IPv6 string (e.g., "2001:db8::1").
6158
6567
  * @see https://url.spec.whatwg.org/#concept-ipv6-serializer
6159
6568
  */
6160
- std::string ipv6(const std::array<uint16_t, 8>& address) noexcept;
6569
+ std::string ipv6(const std::array<uint16_t, 8>& address);
6161
6570
 
6162
6571
  /**
6163
- * Serializes an ipv4 address.
6164
- * @details An IPv4 address is a 32-bit unsigned integer that identifies a
6165
- * network address.
6572
+ * Serializes an IPv4 address to its dotted-decimal string representation.
6573
+ *
6574
+ * @param address The 32-bit IPv4 address as an integer.
6575
+ * @return The serialized IPv4 string (e.g., "192.168.1.1").
6166
6576
  * @see https://url.spec.whatwg.org/#concept-ipv4-serializer
6167
6577
  */
6168
- std::string ipv4(uint64_t address) noexcept;
6578
+ std::string ipv4(uint64_t address);
6169
6579
 
6170
6580
  } // namespace ada::serializers
6171
6581
 
@@ -6174,7 +6584,12 @@ std::string ipv4(uint64_t address) noexcept;
6174
6584
  /* begin file include/ada/state.h */
6175
6585
  /**
6176
6586
  * @file state.h
6177
- * @brief Definitions for the states of the URL state machine.
6587
+ * @brief URL parser state machine states.
6588
+ *
6589
+ * Defines the states used by the URL parsing state machine as specified
6590
+ * in the WHATWG URL Standard.
6591
+ *
6592
+ * @see https://url.spec.whatwg.org/#url-parsing
6178
6593
  */
6179
6594
  #ifndef ADA_STATE_H
6180
6595
  #define ADA_STATE_H
@@ -6185,6 +6600,11 @@ std::string ipv4(uint64_t address) noexcept;
6185
6600
  namespace ada {
6186
6601
 
6187
6602
  /**
6603
+ * @brief States in the URL parsing state machine.
6604
+ *
6605
+ * The URL parser processes input through a sequence of states, each handling
6606
+ * a specific part of the URL syntax.
6607
+ *
6188
6608
  * @see https://url.spec.whatwg.org/#url-parsing
6189
6609
  */
6190
6610
  enum class state {
@@ -6290,7 +6710,9 @@ enum class state {
6290
6710
  };
6291
6711
 
6292
6712
  /**
6293
- * Stringify a URL state machine state.
6713
+ * Converts a parser state to its string name for debugging.
6714
+ * @param s The state to convert.
6715
+ * @return A string representation of the state.
6294
6716
  */
6295
6717
  ada_warn_unused std::string to_string(ada::state s);
6296
6718
 
@@ -6629,6 +7051,7 @@ inline std::ostream &operator<<(std::ostream &out, const ada::url &u) {
6629
7051
  out.protocol_end = uint32_t(get_protocol().size());
6630
7052
 
6631
7053
  // Trailing index is always the next character of the current one.
7054
+ // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
6632
7055
  size_t running_index = out.protocol_end;
6633
7056
 
6634
7057
  if (host.has_value()) {
@@ -6748,7 +7171,7 @@ inline void url::set_scheme(std::string &&new_scheme) noexcept {
6748
7171
  }
6749
7172
  }
6750
7173
 
6751
- constexpr void url::copy_scheme(ada::url &&u) noexcept {
7174
+ constexpr void url::copy_scheme(ada::url &&u) {
6752
7175
  non_special_scheme = u.non_special_scheme;
6753
7176
  type = u.type;
6754
7177
  }
@@ -6758,7 +7181,7 @@ constexpr void url::copy_scheme(const ada::url &u) {
6758
7181
  type = u.type;
6759
7182
  }
6760
7183
 
6761
- [[nodiscard]] ada_really_inline std::string url::get_href() const noexcept {
7184
+ [[nodiscard]] ada_really_inline std::string url::get_href() const {
6762
7185
  std::string output = get_protocol();
6763
7186
 
6764
7187
  if (host.has_value()) {
@@ -6917,7 +7340,13 @@ namespace ada {
6917
7340
  /* begin file include/ada/url_aggregator.h */
6918
7341
  /**
6919
7342
  * @file url_aggregator.h
6920
- * @brief Declaration for the basic URL definitions
7343
+ * @brief Declaration for the `ada::url_aggregator` class.
7344
+ *
7345
+ * This file contains the `ada::url_aggregator` struct which represents a parsed
7346
+ * URL using a single buffer with component offsets. This is the default and
7347
+ * most memory-efficient URL representation in Ada.
7348
+ *
7349
+ * @see url.h for an alternative representation using separate strings
6921
7350
  */
6922
7351
  #ifndef ADA_URL_AGGREGATOR_H
6923
7352
  #define ADA_URL_AGGREGATOR_H
@@ -6933,12 +7362,23 @@ namespace ada {
6933
7362
  namespace parser {}
6934
7363
 
6935
7364
  /**
6936
- * @brief Lightweight URL struct.
7365
+ * @brief Memory-efficient URL representation using a single buffer.
7366
+ *
7367
+ * The `url_aggregator` stores the entire normalized URL in a single string
7368
+ * buffer and tracks component boundaries using offsets. This design minimizes
7369
+ * memory allocations and is ideal for read-mostly access patterns.
7370
+ *
7371
+ * Getter methods return `std::string_view` pointing into the internal buffer.
7372
+ * These views are lightweight (no allocation) but become invalid if the
7373
+ * url_aggregator is modified or destroyed.
6937
7374
  *
6938
- * @details The url_aggregator class aims to minimize temporary memory
6939
- * allocation while representing a parsed URL. Internally, it contains a single
6940
- * normalized URL (the href), and it makes available the components, mostly
6941
- * using std::string_view.
7375
+ * @warning Views returned by getters (e.g., `get_pathname()`) are invalidated
7376
+ * when any setter is called. Do not use a getter's result as input to a
7377
+ * setter on the same object without copying first.
7378
+ *
7379
+ * @note This is the default URL type returned by `ada::parse()`.
7380
+ *
7381
+ * @see url For an alternative using separate std::string instances
6942
7382
  */
6943
7383
  struct url_aggregator : url_base {
6944
7384
  url_aggregator() = default;
@@ -6948,6 +7388,25 @@ struct url_aggregator : url_base {
6948
7388
  url_aggregator &operator=(const url_aggregator &u) = default;
6949
7389
  ~url_aggregator() override = default;
6950
7390
 
7391
+ /**
7392
+ * The setter functions follow the steps defined in the URL Standard.
7393
+ *
7394
+ * The url_aggregator has a single buffer that contains the entire normalized
7395
+ * URL. The various components are represented as offsets into that buffer.
7396
+ * When you call get_pathname(), for example, you get a std::string_view that
7397
+ * points into that buffer. If the url_aggregator is modified, the buffer may
7398
+ * be reallocated, and the std::string_view you obtained earlier may become
7399
+ * invalid. In particular, this implies that you cannot modify the URL using
7400
+ * a setter function with a std::string_view that points into the
7401
+ * url_aggregator E.g., the following is incorrect:
7402
+ * url->set_hostname(url->get_pathname()).
7403
+ * You must first copy the pathname to a separate string.
7404
+ * std::string pathname(url->get_pathname());
7405
+ * url->set_hostname(pathname);
7406
+ *
7407
+ * The caller is responsible for ensuring that the url_aggregator is not
7408
+ * modified while any std::string_view obtained from it is in use.
7409
+ */
6951
7410
  bool set_href(std::string_view input);
6952
7411
  bool set_host(std::string_view input);
6953
7412
  bool set_hostname(std::string_view input);
@@ -6959,115 +7418,130 @@ struct url_aggregator : url_base {
6959
7418
  void set_search(std::string_view input);
6960
7419
  void set_hash(std::string_view input);
6961
7420
 
7421
+ /**
7422
+ * Validates whether the hostname is a valid domain according to RFC 1034.
7423
+ * @return `true` if the domain is valid, `false` otherwise.
7424
+ */
6962
7425
  [[nodiscard]] bool has_valid_domain() const noexcept override;
7426
+
6963
7427
  /**
6964
- * The origin getter steps are to return the serialization of this's URL's
6965
- * origin. [HTML]
6966
- * @return a newly allocated string.
7428
+ * Returns the URL's origin (scheme + host + port for special URLs).
7429
+ * @return A newly allocated string containing the serialized origin.
6967
7430
  * @see https://url.spec.whatwg.org/#concept-url-origin
6968
7431
  */
6969
- [[nodiscard]] std::string get_origin() const noexcept override;
7432
+ [[nodiscard]] std::string get_origin() const override;
7433
+
6970
7434
  /**
6971
- * Return the normalized string.
6972
- * This function does not allocate memory.
6973
- * It is highly efficient.
6974
- * @return a constant reference to the underlying normalized URL.
7435
+ * Returns the full serialized URL (the href) as a string_view.
7436
+ * Does not allocate memory. The returned view becomes invalid if this
7437
+ * url_aggregator is modified or destroyed.
7438
+ * @return A string_view into the internal buffer.
6975
7439
  * @see https://url.spec.whatwg.org/#dom-url-href
6976
- * @see https://url.spec.whatwg.org/#concept-url-serializer
6977
7440
  */
6978
7441
  [[nodiscard]] constexpr std::string_view get_href() const noexcept
6979
7442
  ada_lifetime_bound;
7443
+
6980
7444
  /**
6981
- * The username getter steps are to return this's URL's username.
6982
- * This function does not allocate memory.
6983
- * @return a lightweight std::string_view.
7445
+ * Returns the URL's username component.
7446
+ * Does not allocate memory. The returned view becomes invalid if this
7447
+ * url_aggregator is modified or destroyed.
7448
+ * @return A string_view of the username.
6984
7449
  * @see https://url.spec.whatwg.org/#dom-url-username
6985
7450
  */
6986
- [[nodiscard]] std::string_view get_username() const noexcept
6987
- ada_lifetime_bound;
7451
+ [[nodiscard]] std::string_view get_username() const ada_lifetime_bound;
7452
+
6988
7453
  /**
6989
- * The password getter steps are to return this's URL's password.
6990
- * This function does not allocate memory.
6991
- * @return a lightweight std::string_view.
7454
+ * Returns the URL's password component.
7455
+ * Does not allocate memory. The returned view becomes invalid if this
7456
+ * url_aggregator is modified or destroyed.
7457
+ * @return A string_view of the password.
6992
7458
  * @see https://url.spec.whatwg.org/#dom-url-password
6993
7459
  */
6994
- [[nodiscard]] std::string_view get_password() const noexcept
6995
- ada_lifetime_bound;
7460
+ [[nodiscard]] std::string_view get_password() const ada_lifetime_bound;
7461
+
6996
7462
  /**
6997
- * Return this's URL's port, serialized.
6998
- * This function does not allocate memory.
6999
- * @return a lightweight std::string_view.
7463
+ * Returns the URL's port as a string (e.g., "8080").
7464
+ * Does not allocate memory. Returns empty view if no port is set.
7465
+ * The returned view becomes invalid if this url_aggregator is modified.
7466
+ * @return A string_view of the port.
7000
7467
  * @see https://url.spec.whatwg.org/#dom-url-port
7001
7468
  */
7002
- [[nodiscard]] std::string_view get_port() const noexcept ada_lifetime_bound;
7469
+ [[nodiscard]] std::string_view get_port() const ada_lifetime_bound;
7470
+
7003
7471
  /**
7004
- * Return U+0023 (#), followed by this's URL's fragment.
7005
- * This function does not allocate memory.
7006
- * @return a lightweight std::string_view..
7472
+ * Returns the URL's fragment prefixed with '#' (e.g., "#section").
7473
+ * Does not allocate memory. Returns empty view if no fragment is set.
7474
+ * The returned view becomes invalid if this url_aggregator is modified.
7475
+ * @return A string_view of the hash.
7007
7476
  * @see https://url.spec.whatwg.org/#dom-url-hash
7008
7477
  */
7009
- [[nodiscard]] std::string_view get_hash() const noexcept ada_lifetime_bound;
7478
+ [[nodiscard]] std::string_view get_hash() const ada_lifetime_bound;
7479
+
7010
7480
  /**
7011
- * Return url's host, serialized, followed by U+003A (:) and url's port,
7012
- * serialized.
7013
- * This function does not allocate memory.
7014
- * When there is no host, this function returns the empty view.
7015
- * @return a lightweight std::string_view.
7481
+ * Returns the URL's host and port (e.g., "example.com:8080").
7482
+ * Does not allocate memory. Returns empty view if no host is set.
7483
+ * The returned view becomes invalid if this url_aggregator is modified.
7484
+ * @return A string_view of host:port.
7016
7485
  * @see https://url.spec.whatwg.org/#dom-url-host
7017
7486
  */
7018
- [[nodiscard]] std::string_view get_host() const noexcept ada_lifetime_bound;
7487
+ [[nodiscard]] std::string_view get_host() const ada_lifetime_bound;
7488
+
7019
7489
  /**
7020
- * Return this's URL's host, serialized.
7021
- * This function does not allocate memory.
7022
- * When there is no host, this function returns the empty view.
7023
- * @return a lightweight std::string_view.
7490
+ * Returns the URL's hostname (without port).
7491
+ * Does not allocate memory. Returns empty view if no host is set.
7492
+ * The returned view becomes invalid if this url_aggregator is modified.
7493
+ * @return A string_view of the hostname.
7024
7494
  * @see https://url.spec.whatwg.org/#dom-url-hostname
7025
7495
  */
7026
- [[nodiscard]] std::string_view get_hostname() const noexcept
7027
- ada_lifetime_bound;
7496
+ [[nodiscard]] std::string_view get_hostname() const ada_lifetime_bound;
7497
+
7028
7498
  /**
7029
- * The pathname getter steps are to return the result of URL path serializing
7030
- * this's URL.
7031
- * This function does not allocate memory.
7032
- * @return a lightweight std::string_view.
7499
+ * Returns the URL's path component.
7500
+ * Does not allocate memory. The returned view becomes invalid if this
7501
+ * url_aggregator is modified or destroyed.
7502
+ * @return A string_view of the pathname.
7033
7503
  * @see https://url.spec.whatwg.org/#dom-url-pathname
7034
7504
  */
7035
- [[nodiscard]] constexpr std::string_view get_pathname() const noexcept
7505
+ [[nodiscard]] constexpr std::string_view get_pathname() const
7036
7506
  ada_lifetime_bound;
7507
+
7037
7508
  /**
7038
- * Compute the pathname length in bytes without instantiating a view or a
7039
- * string.
7040
- * @return size of the pathname in bytes
7509
+ * Returns the byte length of the pathname without creating a string.
7510
+ * @return Size of the pathname in bytes.
7041
7511
  * @see https://url.spec.whatwg.org/#dom-url-pathname
7042
7512
  */
7043
7513
  [[nodiscard]] ada_really_inline uint32_t get_pathname_length() const noexcept;
7514
+
7044
7515
  /**
7045
- * Return U+003F (?), followed by this's URL's query.
7046
- * This function does not allocate memory.
7047
- * @return a lightweight std::string_view.
7516
+ * Returns the URL's query string prefixed with '?' (e.g., "?foo=bar").
7517
+ * Does not allocate memory. Returns empty view if no query is set.
7518
+ * The returned view becomes invalid if this url_aggregator is modified.
7519
+ * @return A string_view of the search/query.
7048
7520
  * @see https://url.spec.whatwg.org/#dom-url-search
7049
7521
  */
7050
- [[nodiscard]] std::string_view get_search() const noexcept ada_lifetime_bound;
7522
+ [[nodiscard]] std::string_view get_search() const ada_lifetime_bound;
7523
+
7051
7524
  /**
7052
- * The protocol getter steps are to return this's URL's scheme, followed by
7053
- * U+003A (:).
7054
- * This function does not allocate memory.
7055
- * @return a lightweight std::string_view.
7525
+ * Returns the URL's scheme followed by a colon (e.g., "https:").
7526
+ * Does not allocate memory. The returned view becomes invalid if this
7527
+ * url_aggregator is modified or destroyed.
7528
+ * @return A string_view of the protocol.
7056
7529
  * @see https://url.spec.whatwg.org/#dom-url-protocol
7057
7530
  */
7058
- [[nodiscard]] std::string_view get_protocol() const noexcept
7059
- ada_lifetime_bound;
7531
+ [[nodiscard]] std::string_view get_protocol() const ada_lifetime_bound;
7060
7532
 
7061
7533
  /**
7062
- * A URL includes credentials if its username or password is not the empty
7063
- * string.
7534
+ * Checks if the URL has credentials (non-empty username or password).
7535
+ * @return `true` if username or password is non-empty, `false` otherwise.
7064
7536
  */
7065
7537
  [[nodiscard]] ada_really_inline constexpr bool has_credentials()
7066
7538
  const noexcept;
7067
7539
 
7068
7540
  /**
7069
- * Useful for implementing efficient serialization for the URL.
7541
+ * Returns the URL component offsets for efficient serialization.
7070
7542
  *
7543
+ * The components represent byte offsets into the serialized URL:
7544
+ * ```
7071
7545
  * https://user:pass@example.com:1234/foo/bar?baz#quux
7072
7546
  * | | | | ^^^^| | |
7073
7547
  * | | | | | | | `----- hash_start
@@ -7078,57 +7552,99 @@ struct url_aggregator : url_base {
7078
7552
  * | | `---------------------------------- host_start
7079
7553
  * | `--------------------------------------- username_end
7080
7554
  * `--------------------------------------------- protocol_end
7081
- *
7082
- * Inspired after servo/url
7083
- *
7084
- * @return a constant reference to the underlying component attribute.
7085
- *
7086
- * @see
7087
- * https://github.com/servo/rust-url/blob/b65a45515c10713f6d212e6726719a020203cc98/url/src/quirks.rs#L31
7555
+ * ```
7556
+ * @return A constant reference to the url_components struct.
7557
+ * @see https://github.com/servo/rust-url
7088
7558
  */
7089
7559
  [[nodiscard]] ada_really_inline const url_components &get_components()
7090
7560
  const noexcept;
7561
+
7091
7562
  /**
7092
- * Returns a string representation of this URL.
7563
+ * Returns a JSON string representation of this URL for debugging.
7564
+ * @return A JSON-formatted string with all URL components.
7093
7565
  */
7094
7566
  [[nodiscard]] std::string to_string() const override;
7567
+
7095
7568
  /**
7096
- * Returns a string diagram of this URL.
7569
+ * Returns a visual diagram showing component boundaries in the URL.
7570
+ * Useful for debugging and understanding URL structure.
7571
+ * @return A multi-line string diagram.
7097
7572
  */
7098
7573
  [[nodiscard]] std::string to_diagram() const;
7099
7574
 
7100
7575
  /**
7101
- * Verifies that the parsed URL could be valid. Useful for debugging purposes.
7102
- * @return true if the URL is valid, otherwise return true of the offsets are
7103
- * possible.
7576
+ * Validates internal consistency of component offsets (for debugging).
7577
+ * @return `true` if offsets are consistent, `false` if corrupted.
7104
7578
  */
7105
7579
  [[nodiscard]] constexpr bool validate() const noexcept;
7106
7580
 
7107
- /** @return true if it has an host but it is the empty string */
7581
+ /**
7582
+ * Checks if the URL has an empty hostname (host is set but empty string).
7583
+ * @return `true` if host exists but is empty, `false` otherwise.
7584
+ */
7108
7585
  [[nodiscard]] constexpr bool has_empty_hostname() const noexcept;
7109
- /** @return true if it has a host (included an empty host) */
7586
+
7587
+ /**
7588
+ * Checks if the URL has a hostname (including empty hostnames).
7589
+ * @return `true` if host is present, `false` otherwise.
7590
+ */
7110
7591
  [[nodiscard]] constexpr bool has_hostname() const noexcept;
7111
- /** @return true if the URL has a non-empty username */
7592
+
7593
+ /**
7594
+ * Checks if the URL has a non-empty username.
7595
+ * @return `true` if username is non-empty, `false` otherwise.
7596
+ */
7112
7597
  [[nodiscard]] constexpr bool has_non_empty_username() const noexcept;
7113
- /** @return true if the URL has a non-empty password */
7598
+
7599
+ /**
7600
+ * Checks if the URL has a non-empty password.
7601
+ * @return `true` if password is non-empty, `false` otherwise.
7602
+ */
7114
7603
  [[nodiscard]] constexpr bool has_non_empty_password() const noexcept;
7115
- /** @return true if the URL has a (non default) port */
7604
+
7605
+ /**
7606
+ * Checks if the URL has a non-default port explicitly specified.
7607
+ * @return `true` if a port is present, `false` otherwise.
7608
+ */
7116
7609
  [[nodiscard]] constexpr bool has_port() const noexcept;
7117
- /** @return true if the URL has a password */
7610
+
7611
+ /**
7612
+ * Checks if the URL has a password component (may be empty).
7613
+ * @return `true` if password is present, `false` otherwise.
7614
+ */
7118
7615
  [[nodiscard]] constexpr bool has_password() const noexcept;
7119
- /** @return true if the URL has a hash component */
7616
+
7617
+ /**
7618
+ * Checks if the URL has a fragment/hash component.
7619
+ * @return `true` if hash is present, `false` otherwise.
7620
+ */
7120
7621
  [[nodiscard]] constexpr bool has_hash() const noexcept override;
7121
- /** @return true if the URL has a search component */
7622
+
7623
+ /**
7624
+ * Checks if the URL has a query/search component.
7625
+ * @return `true` if query is present, `false` otherwise.
7626
+ */
7122
7627
  [[nodiscard]] constexpr bool has_search() const noexcept override;
7123
7628
 
7629
+ /**
7630
+ * Removes the port from the URL.
7631
+ */
7124
7632
  inline void clear_port();
7633
+
7634
+ /**
7635
+ * Removes the hash/fragment from the URL.
7636
+ */
7125
7637
  inline void clear_hash();
7638
+
7639
+ /**
7640
+ * Removes the query/search string from the URL.
7641
+ */
7126
7642
  inline void clear_search() override;
7127
7643
 
7128
7644
  private:
7129
7645
  // helper methods
7130
7646
  friend void helpers::strip_trailing_spaces_from_opaque_path<url_aggregator>(
7131
- url_aggregator &url) noexcept;
7647
+ url_aggregator &url);
7132
7648
  // parse_url methods
7133
7649
  friend url_aggregator parser::parse_url<url_aggregator>(
7134
7650
  std::string_view, const url_aggregator *);
@@ -7157,7 +7673,7 @@ struct url_aggregator : url_base {
7157
7673
  */
7158
7674
  [[nodiscard]] ada_really_inline bool is_at_path() const noexcept;
7159
7675
 
7160
- inline void add_authority_slashes_if_needed() noexcept;
7676
+ inline void add_authority_slashes_if_needed();
7161
7677
 
7162
7678
  /**
7163
7679
  * To optimize performance, you may indicate how much memory to allocate
@@ -7165,10 +7681,10 @@ struct url_aggregator : url_base {
7165
7681
  */
7166
7682
  constexpr void reserve(uint32_t capacity);
7167
7683
 
7168
- ada_really_inline size_t parse_port(
7169
- std::string_view view, bool check_trailing_content) noexcept override;
7684
+ ada_really_inline size_t parse_port(std::string_view view,
7685
+ bool check_trailing_content) override;
7170
7686
 
7171
- ada_really_inline size_t parse_port(std::string_view view) noexcept override {
7687
+ ada_really_inline size_t parse_port(std::string_view view) override {
7172
7688
  return this->parse_port(view, false);
7173
7689
  }
7174
7690
 
@@ -7233,16 +7749,16 @@ struct url_aggregator : url_base {
7233
7749
  std::string_view input);
7234
7750
  [[nodiscard]] constexpr bool has_authority() const noexcept;
7235
7751
  constexpr void set_protocol_as_file();
7236
- inline void set_scheme(std::string_view new_scheme) noexcept;
7752
+ inline void set_scheme(std::string_view new_scheme);
7237
7753
  /**
7238
7754
  * Fast function to set the scheme from a view with a colon in the
7239
7755
  * buffer, does not change type.
7240
7756
  */
7241
7757
  inline void set_scheme_from_view_with_colon(
7242
- std::string_view new_scheme_with_colon) noexcept;
7243
- inline void copy_scheme(const url_aggregator &u) noexcept;
7758
+ std::string_view new_scheme_with_colon);
7759
+ inline void copy_scheme(const url_aggregator &u);
7244
7760
 
7245
- inline void update_host_to_base_host(const std::string_view input) noexcept;
7761
+ inline void update_host_to_base_host(const std::string_view input);
7246
7762
 
7247
7763
  }; // url_aggregator
7248
7764
 
@@ -8034,7 +8550,7 @@ url_aggregator::get_components() const noexcept {
8034
8550
  components.protocol_end + 2) == "//";
8035
8551
  }
8036
8552
 
8037
- inline void ada::url_aggregator::add_authority_slashes_if_needed() noexcept {
8553
+ inline void ada::url_aggregator::add_authority_slashes_if_needed() {
8038
8554
  ada_log("url_aggregator::add_authority_slashes_if_needed");
8039
8555
  ADA_ASSERT_TRUE(validate());
8040
8556
  // Protocol setter will insert `http:` to the URL. It is up to hostname setter
@@ -8071,7 +8587,7 @@ constexpr bool url_aggregator::has_non_empty_username() const noexcept {
8071
8587
 
8072
8588
  constexpr bool url_aggregator::has_non_empty_password() const noexcept {
8073
8589
  ada_log("url_aggregator::has_non_empty_password");
8074
- return components.host_start - components.username_end > 0;
8590
+ return components.host_start > components.username_end;
8075
8591
  }
8076
8592
 
8077
8593
  constexpr bool url_aggregator::has_password() const noexcept {
@@ -8143,8 +8659,8 @@ constexpr bool url_aggregator::has_port() const noexcept {
8143
8659
  return buffer;
8144
8660
  }
8145
8661
 
8146
- ada_really_inline size_t url_aggregator::parse_port(
8147
- std::string_view view, bool check_trailing_content) noexcept {
8662
+ ada_really_inline size_t
8663
+ url_aggregator::parse_port(std::string_view view, bool check_trailing_content) {
8148
8664
  ada_log("url_aggregator::parse_port('", view, "') ", view.size());
8149
8665
  if (!view.empty() && view[0] == '-') {
8150
8666
  ada_log("parse_port: view[0] == '0' && view.size() > 1");
@@ -8382,8 +8898,8 @@ constexpr void url_aggregator::set_protocol_as_file() {
8382
8898
  return true;
8383
8899
  }
8384
8900
 
8385
- [[nodiscard]] constexpr std::string_view url_aggregator::get_pathname()
8386
- const noexcept ada_lifetime_bound {
8901
+ [[nodiscard]] constexpr std::string_view url_aggregator::get_pathname() const
8902
+ ada_lifetime_bound {
8387
8903
  ada_log("url_aggregator::get_pathname pathname_start = ",
8388
8904
  components.pathname_start, " buffer.size() = ", buffer.size(),
8389
8905
  " components.search_start = ", components.search_start,
@@ -8402,8 +8918,7 @@ inline std::ostream &operator<<(std::ostream &out,
8402
8918
  return out << u.to_string();
8403
8919
  }
8404
8920
 
8405
- void url_aggregator::update_host_to_base_host(
8406
- const std::string_view input) noexcept {
8921
+ void url_aggregator::update_host_to_base_host(const std::string_view input) {
8407
8922
  ada_log("url_aggregator::update_host_to_base_host ", input);
8408
8923
  ADA_ASSERT_TRUE(validate());
8409
8924
  ADA_ASSERT_TRUE(!helpers::overlaps(input, buffer));
@@ -8430,7 +8945,13 @@ void url_aggregator::update_host_to_base_host(
8430
8945
  /* begin file include/ada/url_search_params.h */
8431
8946
  /**
8432
8947
  * @file url_search_params.h
8433
- * @brief Declaration for the URL Search Params
8948
+ * @brief URL query string parameter manipulation.
8949
+ *
8950
+ * This file provides the `url_search_params` class for parsing, manipulating,
8951
+ * and serializing URL query strings. It implements the URLSearchParams API
8952
+ * from the WHATWG URL Standard.
8953
+ *
8954
+ * @see https://url.spec.whatwg.org/#interface-urlsearchparams
8434
8955
  */
8435
8956
  #ifndef ADA_URL_SEARCH_PARAMS_H
8436
8957
  #define ADA_URL_SEARCH_PARAMS_H
@@ -8442,37 +8963,51 @@ void url_aggregator::update_host_to_base_host(
8442
8963
 
8443
8964
  namespace ada {
8444
8965
 
8966
+ /**
8967
+ * @brief Iterator types for url_search_params iteration.
8968
+ */
8445
8969
  enum class url_search_params_iter_type {
8446
- KEYS,
8447
- VALUES,
8448
- ENTRIES,
8970
+ KEYS, /**< Iterate over parameter keys only */
8971
+ VALUES, /**< Iterate over parameter values only */
8972
+ ENTRIES, /**< Iterate over key-value pairs */
8449
8973
  };
8450
8974
 
8451
8975
  template <typename T, url_search_params_iter_type Type>
8452
8976
  struct url_search_params_iter;
8453
8977
 
8978
+ /** Type alias for a key-value pair of string views. */
8454
8979
  typedef std::pair<std::string_view, std::string_view> key_value_view_pair;
8455
8980
 
8981
+ /** Iterator over search parameter keys. */
8456
8982
  using url_search_params_keys_iter =
8457
8983
  url_search_params_iter<std::string_view, url_search_params_iter_type::KEYS>;
8984
+ /** Iterator over search parameter values. */
8458
8985
  using url_search_params_values_iter =
8459
8986
  url_search_params_iter<std::string_view,
8460
8987
  url_search_params_iter_type::VALUES>;
8988
+ /** Iterator over search parameter key-value pairs. */
8461
8989
  using url_search_params_entries_iter =
8462
8990
  url_search_params_iter<key_value_view_pair,
8463
8991
  url_search_params_iter_type::ENTRIES>;
8464
8992
 
8465
8993
  /**
8466
- * We require all strings to be valid UTF-8. It is the user's responsibility to
8467
- * ensure that the provided strings are valid UTF-8.
8994
+ * @brief Class for parsing and manipulating URL query strings.
8995
+ *
8996
+ * The `url_search_params` class provides methods to parse, modify, and
8997
+ * serialize URL query parameters (the part after '?' in a URL). It handles
8998
+ * percent-encoding and decoding automatically.
8999
+ *
9000
+ * All string inputs must be valid UTF-8. The caller is responsible for
9001
+ * ensuring UTF-8 validity.
9002
+ *
8468
9003
  * @see https://url.spec.whatwg.org/#interface-urlsearchparams
8469
9004
  */
8470
9005
  struct url_search_params {
8471
9006
  url_search_params() = default;
8472
9007
 
8473
9008
  /**
8474
- * @see
8475
- * https://github.com/web-platform-tests/wpt/blob/master/url/urlsearchparams-constructor.any.js
9009
+ * Constructs url_search_params by parsing a query string.
9010
+ * @param input A query string (with or without leading '?'). Must be UTF-8.
8476
9011
  */
8477
9012
  explicit url_search_params(const std::string_view input) {
8478
9013
  initialize(input);
@@ -8484,75 +9019,106 @@ struct url_search_params {
8484
9019
  url_search_params &operator=(const url_search_params &u) = default;
8485
9020
  ~url_search_params() = default;
8486
9021
 
9022
+ /**
9023
+ * Returns the number of key-value pairs.
9024
+ * @return The total count of parameters.
9025
+ */
8487
9026
  [[nodiscard]] inline size_t size() const noexcept;
8488
9027
 
8489
9028
  /**
8490
- * Both key and value must be valid UTF-8.
9029
+ * Appends a new key-value pair to the parameter list.
9030
+ * @param key The parameter name (must be valid UTF-8).
9031
+ * @param value The parameter value (must be valid UTF-8).
8491
9032
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-append
8492
9033
  */
8493
9034
  inline void append(std::string_view key, std::string_view value);
8494
9035
 
8495
9036
  /**
9037
+ * Removes all pairs with the given key.
9038
+ * @param key The parameter name to remove.
8496
9039
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-delete
8497
9040
  */
8498
9041
  inline void remove(std::string_view key);
9042
+
9043
+ /**
9044
+ * Removes all pairs with the given key and value.
9045
+ * @param key The parameter name.
9046
+ * @param value The parameter value to match.
9047
+ */
8499
9048
  inline void remove(std::string_view key, std::string_view value);
8500
9049
 
8501
9050
  /**
9051
+ * Returns the value of the first pair with the given key.
9052
+ * @param key The parameter name to search for.
9053
+ * @return The value if found, or std::nullopt if not present.
8502
9054
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-get
8503
9055
  */
8504
9056
  inline std::optional<std::string_view> get(std::string_view key);
8505
9057
 
8506
9058
  /**
9059
+ * Returns all values for pairs with the given key.
9060
+ * @param key The parameter name to search for.
9061
+ * @return A vector of all matching values (may be empty).
8507
9062
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-getall
8508
9063
  */
8509
9064
  inline std::vector<std::string> get_all(std::string_view key);
8510
9065
 
8511
9066
  /**
9067
+ * Checks if any pair has the given key.
9068
+ * @param key The parameter name to search for.
9069
+ * @return `true` if at least one pair has this key.
8512
9070
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-has
8513
9071
  */
8514
9072
  inline bool has(std::string_view key) noexcept;
9073
+
9074
+ /**
9075
+ * Checks if any pair matches the given key and value.
9076
+ * @param key The parameter name to search for.
9077
+ * @param value The parameter value to match.
9078
+ * @return `true` if a matching pair exists.
9079
+ */
8515
9080
  inline bool has(std::string_view key, std::string_view value) noexcept;
8516
9081
 
8517
9082
  /**
8518
- * Both key and value must be valid UTF-8.
9083
+ * Sets a parameter value, replacing any existing pairs with the same key.
9084
+ * @param key The parameter name (must be valid UTF-8).
9085
+ * @param value The parameter value (must be valid UTF-8).
8519
9086
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-set
8520
9087
  */
8521
9088
  inline void set(std::string_view key, std::string_view value);
8522
9089
 
8523
9090
  /**
9091
+ * Sorts all key-value pairs by their keys using code unit comparison.
8524
9092
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-sort
8525
9093
  */
8526
9094
  inline void sort();
8527
9095
 
8528
9096
  /**
9097
+ * Serializes the parameters to a query string (without leading '?').
9098
+ * @return The percent-encoded query string.
8529
9099
  * @see https://url.spec.whatwg.org/#urlsearchparams-stringification-behavior
8530
9100
  */
8531
9101
  inline std::string to_string() const;
8532
9102
 
8533
9103
  /**
8534
- * Returns a simple JS-style iterator over all of the keys in this
8535
- * url_search_params. The keys in the iterator are not unique. The valid
8536
- * lifespan of the iterator is tied to the url_search_params. The iterator
8537
- * must be freed when you're done with it.
8538
- * @see https://url.spec.whatwg.org/#interface-urlsearchparams
9104
+ * Returns an iterator over all parameter keys.
9105
+ * Keys may repeat if there are duplicate parameters.
9106
+ * @return An iterator yielding string_view keys.
9107
+ * @note The iterator is invalidated if this object is modified.
8539
9108
  */
8540
9109
  inline url_search_params_keys_iter get_keys();
8541
9110
 
8542
9111
  /**
8543
- * Returns a simple JS-style iterator over all of the values in this
8544
- * url_search_params. The valid lifespan of the iterator is tied to the
8545
- * url_search_params. The iterator must be freed when you're done with it.
8546
- * @see https://url.spec.whatwg.org/#interface-urlsearchparams
9112
+ * Returns an iterator over all parameter values.
9113
+ * @return An iterator yielding string_view values.
9114
+ * @note The iterator is invalidated if this object is modified.
8547
9115
  */
8548
9116
  inline url_search_params_values_iter get_values();
8549
9117
 
8550
9118
  /**
8551
- * Returns a simple JS-style iterator over all of the entries in this
8552
- * url_search_params. The entries are pairs of keys and corresponding values.
8553
- * The valid lifespan of the iterator is tied to the url_search_params. The
8554
- * iterator must be freed when you're done with it.
8555
- * @see https://url.spec.whatwg.org/#interface-urlsearchparams
9119
+ * Returns an iterator over all key-value pairs.
9120
+ * @return An iterator yielding key-value pair views.
9121
+ * @note The iterator is invalidated if this object is modified.
8556
9122
  */
8557
9123
  inline url_search_params_entries_iter get_entries();
8558
9124
 
@@ -8589,8 +9155,13 @@ struct url_search_params {
8589
9155
  }; // url_search_params
8590
9156
 
8591
9157
  /**
8592
- * Implements a non-conventional iterator pattern that is closer in style to
8593
- * JavaScript's definition of an iterator.
9158
+ * @brief JavaScript-style iterator for url_search_params.
9159
+ *
9160
+ * Provides a `next()` method that returns successive values until exhausted.
9161
+ * This matches the iterator pattern used in the Web Platform.
9162
+ *
9163
+ * @tparam T The type of value returned by the iterator.
9164
+ * @tparam Type The type of iteration (KEYS, VALUES, or ENTRIES).
8594
9165
  *
8595
9166
  * @see https://webidl.spec.whatwg.org/#idl-iterable
8596
9167
  */
@@ -8605,10 +9176,15 @@ struct url_search_params_iter {
8605
9176
  ~url_search_params_iter() = default;
8606
9177
 
8607
9178
  /**
8608
- * Return the next item in the iterator or std::nullopt if done.
9179
+ * Returns the next value in the iteration sequence.
9180
+ * @return The next value, or std::nullopt if iteration is complete.
8609
9181
  */
8610
9182
  inline std::optional<T> next();
8611
9183
 
9184
+ /**
9185
+ * Checks if more values are available.
9186
+ * @return `true` if `next()` will return a value, `false` if exhausted.
9187
+ */
8612
9188
  inline bool has_next() const;
8613
9189
 
8614
9190
  private:
@@ -8915,7 +9491,6 @@ url_search_params_entries_iter::next() {
8915
9491
  #endif // ADA_URL_SEARCH_PARAMS_INL_H
8916
9492
  /* end file include/ada/url_search_params-inl.h */
8917
9493
 
8918
- #if ADA_INCLUDE_URL_PATTERN
8919
9494
  /* begin file include/ada/url_pattern-inl.h */
8920
9495
  /**
8921
9496
  * @file url_pattern-inl.h
@@ -8929,6 +9504,7 @@ url_search_params_entries_iter::next() {
8929
9504
  #include <string_view>
8930
9505
  #include <utility>
8931
9506
 
9507
+ #if ADA_INCLUDE_URL_PATTERN
8932
9508
  namespace ada {
8933
9509
 
8934
9510
  inline bool url_pattern_init::operator==(const url_pattern_init& other) const {
@@ -8961,10 +9537,8 @@ url_pattern_component<regex_provider>::create_component_match_result(
8961
9537
  // says we should start from 1. This case is handled by the
8962
9538
  // std_regex_provider.
8963
9539
  for (size_t index = 0; index < exec_result.size(); index++) {
8964
- result.groups.insert({
8965
- group_name_list[index],
8966
- std::move(exec_result[index]),
8967
- });
9540
+ result.groups.emplace(group_name_list[index],
9541
+ std::move(exec_result[index]));
8968
9542
  }
8969
9543
  return result;
8970
9544
  }
@@ -9070,43 +9644,113 @@ url_pattern_component<regex_provider>::compile(
9070
9644
  return tl::unexpected(part_list.error());
9071
9645
  }
9072
9646
 
9073
- // Let (regular expression string, name list) be the result of running
9074
- // generate a regular expression and name list given part list and options.
9647
+ // Detect pattern type early to potentially skip expensive regex compilation
9648
+ const auto has_regexp = [](const auto& part) { return part.is_regexp(); };
9649
+ const bool has_regexp_groups = std::ranges::any_of(*part_list, has_regexp);
9650
+
9651
+ url_pattern_component_type component_type =
9652
+ url_pattern_component_type::REGEXP;
9653
+ std::string exact_match_value{};
9654
+
9655
+ if (part_list->empty()) {
9656
+ component_type = url_pattern_component_type::EMPTY;
9657
+ } else if (part_list->size() == 1) {
9658
+ const auto& part = (*part_list)[0];
9659
+ if (part.type == url_pattern_part_type::FIXED_TEXT &&
9660
+ part.modifier == url_pattern_part_modifier::none &&
9661
+ !options.ignore_case) {
9662
+ component_type = url_pattern_component_type::EXACT_MATCH;
9663
+ exact_match_value = part.value;
9664
+ } else if (part.type == url_pattern_part_type::FULL_WILDCARD &&
9665
+ part.modifier == url_pattern_part_modifier::none &&
9666
+ part.prefix.empty() && part.suffix.empty()) {
9667
+ component_type = url_pattern_component_type::FULL_WILDCARD;
9668
+ }
9669
+ }
9670
+
9671
+ // For simple patterns, skip regex generation and compilation entirely
9672
+ if (component_type != url_pattern_component_type::REGEXP) {
9673
+ auto pattern_string =
9674
+ url_pattern_helpers::generate_pattern_string(*part_list, options);
9675
+ // For FULL_WILDCARD, we need the group name from
9676
+ // generate_regular_expression
9677
+ std::vector<std::string> name_list;
9678
+ if (component_type == url_pattern_component_type::FULL_WILDCARD &&
9679
+ !part_list->empty()) {
9680
+ name_list.push_back((*part_list)[0].name);
9681
+ }
9682
+ return url_pattern_component<regex_provider>(
9683
+ std::move(pattern_string), typename regex_provider::regex_type{},
9684
+ std::move(name_list), has_regexp_groups, component_type,
9685
+ std::move(exact_match_value));
9686
+ }
9687
+
9688
+ // Generate regex for complex patterns
9075
9689
  auto [regular_expression_string, name_list] =
9076
9690
  url_pattern_helpers::generate_regular_expression_and_name_list(*part_list,
9077
9691
  options);
9078
-
9079
- ada_log("regular expression string: ", regular_expression_string);
9080
-
9081
- // Let pattern string be the result of running generate a pattern
9082
- // string given part list and options.
9083
9692
  auto pattern_string =
9084
9693
  url_pattern_helpers::generate_pattern_string(*part_list, options);
9085
9694
 
9086
- // Let regular expression be RegExpCreate(regular expression string,
9087
- // flags). If this throws an exception, catch it, and throw a
9088
- // TypeError.
9089
9695
  std::optional<typename regex_provider::regex_type> regular_expression =
9090
9696
  regex_provider::create_instance(regular_expression_string,
9091
9697
  options.ignore_case);
9092
-
9093
9698
  if (!regular_expression) {
9094
9699
  return tl::unexpected(errors::type_error);
9095
9700
  }
9096
9701
 
9097
- // For each part of part list:
9098
- // - If part's type is "regexp", then set has regexp groups to true.
9099
- const auto has_regexp = [](const auto& part) { return part.is_regexp(); };
9100
- const bool has_regexp_groups = std::ranges::any_of(*part_list, has_regexp);
9101
-
9102
- ada_log("has regexp groups: ", has_regexp_groups);
9103
-
9104
- // Return a new component whose pattern string is pattern string, regular
9105
- // expression is regular expression, group name list is name list, and has
9106
- // regexp groups is has regexp groups.
9107
9702
  return url_pattern_component<regex_provider>(
9108
9703
  std::move(pattern_string), std::move(*regular_expression),
9109
- std::move(name_list), has_regexp_groups);
9704
+ std::move(name_list), has_regexp_groups, component_type,
9705
+ std::move(exact_match_value));
9706
+ }
9707
+
9708
+ template <url_pattern_regex::regex_concept regex_provider>
9709
+ bool url_pattern_component<regex_provider>::fast_test(
9710
+ std::string_view input) const noexcept {
9711
+ // Fast path for simple patterns - avoid regex evaluation
9712
+ // Using if-else for better branch prediction on common cases
9713
+ if (type == url_pattern_component_type::FULL_WILDCARD) {
9714
+ return true;
9715
+ }
9716
+ if (type == url_pattern_component_type::EXACT_MATCH) {
9717
+ return input == exact_match_value;
9718
+ }
9719
+ if (type == url_pattern_component_type::EMPTY) {
9720
+ return input.empty();
9721
+ }
9722
+ // type == REGEXP
9723
+ return regex_provider::regex_match(input, regexp);
9724
+ }
9725
+
9726
+ template <url_pattern_regex::regex_concept regex_provider>
9727
+ std::optional<std::vector<std::optional<std::string>>>
9728
+ url_pattern_component<regex_provider>::fast_match(
9729
+ std::string_view input) const {
9730
+ // Handle each type directly without redundant checks
9731
+ if (type == url_pattern_component_type::FULL_WILDCARD) {
9732
+ // FULL_WILDCARD always matches - capture the input (even if empty)
9733
+ // If there's no group name, return empty groups
9734
+ if (group_name_list.empty()) {
9735
+ return std::vector<std::optional<std::string>>{};
9736
+ }
9737
+ // Capture the matched input (including empty strings)
9738
+ return std::vector<std::optional<std::string>>{std::string(input)};
9739
+ }
9740
+ if (type == url_pattern_component_type::EXACT_MATCH) {
9741
+ if (input == exact_match_value) {
9742
+ return std::vector<std::optional<std::string>>{};
9743
+ }
9744
+ return std::nullopt;
9745
+ }
9746
+ if (type == url_pattern_component_type::EMPTY) {
9747
+ if (input.empty()) {
9748
+ return std::vector<std::optional<std::string>>{};
9749
+ }
9750
+ return std::nullopt;
9751
+ }
9752
+ // type == REGEXP - use regex
9753
+ return regex_provider::regex_search(input, regexp);
9110
9754
  }
9111
9755
 
9112
9756
  template <url_pattern_regex::regex_concept regex_provider>
@@ -9117,18 +9761,88 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::exec(
9117
9761
  return match(input, base_url);
9118
9762
  }
9119
9763
 
9764
+ template <url_pattern_regex::regex_concept regex_provider>
9765
+ bool url_pattern<regex_provider>::test_components(
9766
+ std::string_view protocol, std::string_view username,
9767
+ std::string_view password, std::string_view hostname, std::string_view port,
9768
+ std::string_view pathname, std::string_view search,
9769
+ std::string_view hash) const {
9770
+ return protocol_component.fast_test(protocol) &&
9771
+ username_component.fast_test(username) &&
9772
+ password_component.fast_test(password) &&
9773
+ hostname_component.fast_test(hostname) &&
9774
+ port_component.fast_test(port) &&
9775
+ pathname_component.fast_test(pathname) &&
9776
+ search_component.fast_test(search) && hash_component.fast_test(hash);
9777
+ }
9778
+
9120
9779
  template <url_pattern_regex::regex_concept regex_provider>
9121
9780
  result<bool> url_pattern<regex_provider>::test(
9122
- const url_pattern_input& input, const std::string_view* base_url) {
9123
- // TODO: Optimization opportunity. Rather than returning `url_pattern_result`
9124
- // Implement a fast path just like `can_parse()` in ada_url.
9125
- // Let result be the result of match given this's associated URL pattern,
9126
- // input, and baseURL if given.
9127
- // If result is null, return false.
9128
- if (auto result = match(input, base_url); result.has_value()) {
9129
- return result->has_value();
9781
+ const url_pattern_input& input, const std::string_view* base_url_string) {
9782
+ // If input is a URLPatternInit
9783
+ if (std::holds_alternative<url_pattern_init>(input)) {
9784
+ if (base_url_string) {
9785
+ return tl::unexpected(errors::type_error);
9786
+ }
9787
+
9788
+ std::string protocol{}, username{}, password{}, hostname{};
9789
+ std::string port{}, pathname{}, search{}, hash{};
9790
+
9791
+ auto apply_result = url_pattern_init::process(
9792
+ std::get<url_pattern_init>(input), url_pattern_init::process_type::url,
9793
+ protocol, username, password, hostname, port, pathname, search, hash);
9794
+
9795
+ if (!apply_result) {
9796
+ return false;
9797
+ }
9798
+
9799
+ std::string_view search_view = *apply_result->search;
9800
+ if (search_view.starts_with("?")) {
9801
+ search_view.remove_prefix(1);
9802
+ }
9803
+
9804
+ return test_components(*apply_result->protocol, *apply_result->username,
9805
+ *apply_result->password, *apply_result->hostname,
9806
+ *apply_result->port, *apply_result->pathname,
9807
+ search_view, *apply_result->hash);
9808
+ }
9809
+
9810
+ // URL string input path
9811
+ result<url_aggregator> base_url;
9812
+ if (base_url_string) {
9813
+ base_url = ada::parse<url_aggregator>(*base_url_string, nullptr);
9814
+ if (!base_url) {
9815
+ return false;
9816
+ }
9817
+ }
9818
+
9819
+ auto url =
9820
+ ada::parse<url_aggregator>(std::get<std::string_view>(input),
9821
+ base_url.has_value() ? &*base_url : nullptr);
9822
+ if (!url) {
9823
+ return false;
9824
+ }
9825
+
9826
+ // Extract components as string_view
9827
+ auto protocol_view = url->get_protocol();
9828
+ if (protocol_view.ends_with(":")) {
9829
+ protocol_view.remove_suffix(1);
9830
+ }
9831
+
9832
+ auto search_view = url->get_search();
9833
+ if (search_view.starts_with("?")) {
9834
+ search_view.remove_prefix(1);
9835
+ }
9836
+
9837
+ auto hash_view = url->get_hash();
9838
+ if (hash_view.starts_with("#")) {
9839
+ hash_view.remove_prefix(1);
9130
9840
  }
9131
- return tl::unexpected(errors::type_error);
9841
+
9842
+ return test_components(protocol_view, url->get_username(),
9843
+ url->get_password(), url->get_hostname(),
9844
+ url->get_port(), url->get_pathname(), search_view,
9845
+ hash_view);
9132
9846
  }
9133
9847
 
9134
9848
  template <url_pattern_regex::regex_concept regex_provider>
@@ -9277,74 +9991,61 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
9277
9991
  }
9278
9992
  }
9279
9993
 
9994
+ // Use fast_match which skips regex for simple patterns (EMPTY, EXACT_MATCH,
9995
+ // FULL_WILDCARD) and only falls back to regex for complex REGEXP patterns.
9996
+
9280
9997
  // Let protocolExecResult be RegExpBuiltinExec(urlPattern's protocol
9281
9998
  // component's regular expression, protocol).
9282
- auto protocol_exec_result =
9283
- regex_provider::regex_search(protocol, protocol_component.regexp);
9284
-
9999
+ auto protocol_exec_result = protocol_component.fast_match(protocol);
9285
10000
  if (!protocol_exec_result) {
9286
10001
  return std::nullopt;
9287
10002
  }
9288
10003
 
9289
10004
  // Let usernameExecResult be RegExpBuiltinExec(urlPattern's username
9290
10005
  // component's regular expression, username).
9291
- auto username_exec_result =
9292
- regex_provider::regex_search(username, username_component.regexp);
9293
-
10006
+ auto username_exec_result = username_component.fast_match(username);
9294
10007
  if (!username_exec_result) {
9295
10008
  return std::nullopt;
9296
10009
  }
9297
10010
 
9298
10011
  // Let passwordExecResult be RegExpBuiltinExec(urlPattern's password
9299
10012
  // component's regular expression, password).
9300
- auto password_exec_result =
9301
- regex_provider::regex_search(password, password_component.regexp);
9302
-
10013
+ auto password_exec_result = password_component.fast_match(password);
9303
10014
  if (!password_exec_result) {
9304
10015
  return std::nullopt;
9305
10016
  }
9306
10017
 
9307
10018
  // Let hostnameExecResult be RegExpBuiltinExec(urlPattern's hostname
9308
10019
  // component's regular expression, hostname).
9309
- auto hostname_exec_result =
9310
- regex_provider::regex_search(hostname, hostname_component.regexp);
9311
-
10020
+ auto hostname_exec_result = hostname_component.fast_match(hostname);
9312
10021
  if (!hostname_exec_result) {
9313
10022
  return std::nullopt;
9314
10023
  }
9315
10024
 
9316
10025
  // Let portExecResult be RegExpBuiltinExec(urlPattern's port component's
9317
10026
  // regular expression, port).
9318
- auto port_exec_result =
9319
- regex_provider::regex_search(port, port_component.regexp);
9320
-
10027
+ auto port_exec_result = port_component.fast_match(port);
9321
10028
  if (!port_exec_result) {
9322
10029
  return std::nullopt;
9323
10030
  }
9324
10031
 
9325
10032
  // Let pathnameExecResult be RegExpBuiltinExec(urlPattern's pathname
9326
10033
  // component's regular expression, pathname).
9327
- auto pathname_exec_result =
9328
- regex_provider::regex_search(pathname, pathname_component.regexp);
9329
-
10034
+ auto pathname_exec_result = pathname_component.fast_match(pathname);
9330
10035
  if (!pathname_exec_result) {
9331
10036
  return std::nullopt;
9332
10037
  }
9333
10038
 
9334
10039
  // Let searchExecResult be RegExpBuiltinExec(urlPattern's search component's
9335
10040
  // regular expression, search).
9336
- auto search_exec_result =
9337
- regex_provider::regex_search(search, search_component.regexp);
9338
-
10041
+ auto search_exec_result = search_component.fast_match(search);
9339
10042
  if (!search_exec_result) {
9340
10043
  return std::nullopt;
9341
10044
  }
9342
10045
 
9343
10046
  // Let hashExecResult be RegExpBuiltinExec(urlPattern's hash component's
9344
10047
  // regular expression, hash).
9345
- auto hash_exec_result =
9346
- regex_provider::regex_search(hash, hash_component.regexp);
9347
-
10048
+ auto hash_exec_result = hash_component.fast_match(hash);
9348
10049
  if (!hash_exec_result) {
9349
10050
  return std::nullopt;
9350
10051
  }
@@ -9397,7 +10098,7 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
9397
10098
  }
9398
10099
 
9399
10100
  } // namespace ada
9400
-
10101
+ #endif // ADA_INCLUDE_URL_PATTERN
9401
10102
  #endif
9402
10103
  /* end file include/ada/url_pattern-inl.h */
9403
10104
  /* begin file include/ada/url_pattern_helpers-inl.h */
@@ -9412,8 +10113,9 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
9412
10113
  #include <string_view>
9413
10114
 
9414
10115
 
10116
+ #if ADA_INCLUDE_URL_PATTERN
9415
10117
  namespace ada::url_pattern_helpers {
9416
- #ifdef ADA_TESTING
10118
+ #if defined(ADA_TESTING) || defined(ADA_LOGGING)
9417
10119
  inline std::string to_string(token_type type) {
9418
10120
  switch (type) {
9419
10121
  case token_type::INVALID_CHAR:
@@ -9440,7 +10142,7 @@ inline std::string to_string(token_type type) {
9440
10142
  ada::unreachable();
9441
10143
  }
9442
10144
  }
9443
- #endif // ADA_TESTING
10145
+ #endif // defined(ADA_TESTING) || defined(ADA_LOGGING)
9444
10146
 
9445
10147
  template <url_pattern_regex::regex_concept regex_provider>
9446
10148
  constexpr void constructor_string_parser<regex_provider>::rewind() {
@@ -9692,8 +10394,8 @@ std::string constructor_string_parser<regex_provider>::make_component_string() {
9692
10394
  const auto component_start_input_index = component_start_token->index;
9693
10395
  // Return the code point substring from component start input index to end
9694
10396
  // index within parser's input.
9695
- return input.substr(component_start_input_index,
9696
- end_index - component_start_input_index);
10397
+ return std::string(input.substr(component_start_input_index,
10398
+ end_index - component_start_input_index));
9697
10399
  }
9698
10400
 
9699
10401
  template <url_pattern_regex::regex_concept regex_provider>
@@ -10199,13 +10901,31 @@ tl::expected<std::vector<url_pattern_part>, errors> parse_pattern_string(
10199
10901
  template <url_pattern_regex::regex_concept regex_provider>
10200
10902
  bool protocol_component_matches_special_scheme(
10201
10903
  url_pattern_component<regex_provider>& component) {
10202
- // let's avoid unnecessary copy here.
10203
- auto& regex = component.regexp;
10204
- return regex_provider::regex_match("http", regex) ||
10205
- regex_provider::regex_match("https", regex) ||
10206
- regex_provider::regex_match("ws", regex) ||
10207
- regex_provider::regex_match("wss", regex) ||
10208
- regex_provider::regex_match("ftp", regex);
10904
+ // Optimization: Use fast_test for simple patterns to avoid regex overhead
10905
+ switch (component.type) {
10906
+ case url_pattern_component_type::EMPTY:
10907
+ // Empty pattern can't match any special scheme
10908
+ return false;
10909
+ case url_pattern_component_type::EXACT_MATCH:
10910
+ // Direct string comparison for exact match patterns
10911
+ return component.exact_match_value == "http" ||
10912
+ component.exact_match_value == "https" ||
10913
+ component.exact_match_value == "ws" ||
10914
+ component.exact_match_value == "wss" ||
10915
+ component.exact_match_value == "ftp";
10916
+ case url_pattern_component_type::FULL_WILDCARD:
10917
+ // Full wildcard matches everything including special schemes
10918
+ return true;
10919
+ case url_pattern_component_type::REGEXP:
10920
+ // Fall back to regex matching for complex patterns
10921
+ auto& regex = component.regexp;
10922
+ return regex_provider::regex_match("http", regex) ||
10923
+ regex_provider::regex_match("https", regex) ||
10924
+ regex_provider::regex_match("ws", regex) ||
10925
+ regex_provider::regex_match("wss", regex) ||
10926
+ regex_provider::regex_match("ftp", regex);
10927
+ }
10928
+ ada::unreachable();
10209
10929
  }
10210
10930
 
10211
10931
  template <url_pattern_regex::regex_concept regex_provider>
@@ -10488,10 +11208,9 @@ constructor_string_parser<regex_provider>::parse(std::string_view input) {
10488
11208
  }
10489
11209
 
10490
11210
  } // namespace ada::url_pattern_helpers
10491
-
11211
+ #endif // ADA_INCLUDE_URL_PATTERN
10492
11212
  #endif
10493
11213
  /* end file include/ada/url_pattern_helpers-inl.h */
10494
- #endif // ADA_INCLUDE_URL_PATTERN
10495
11214
 
10496
11215
  // Public API
10497
11216
  /* begin file include/ada/ada_version.h */
@@ -10502,13 +11221,13 @@ constructor_string_parser<regex_provider>::parse(std::string_view input) {
10502
11221
  #ifndef ADA_ADA_VERSION_H
10503
11222
  #define ADA_ADA_VERSION_H
10504
11223
 
10505
- #define ADA_VERSION "3.2.2"
11224
+ #define ADA_VERSION "3.4.2"
10506
11225
 
10507
11226
  namespace ada {
10508
11227
 
10509
11228
  enum {
10510
11229
  ADA_VERSION_MAJOR = 3,
10511
- ADA_VERSION_MINOR = 2,
11230
+ ADA_VERSION_MINOR = 4,
10512
11231
  ADA_VERSION_REVISION = 2,
10513
11232
  };
10514
11233
 
@@ -10523,8 +11242,6 @@ enum {
10523
11242
  #ifndef ADA_IMPLEMENTATION_INL_H
10524
11243
  #define ADA_IMPLEMENTATION_INL_H
10525
11244
 
10526
- #if ADA_INCLUDE_URL_PATTERN
10527
- #endif // ADA_INCLUDE_URL_PATTERN
10528
11245
 
10529
11246
 
10530
11247
  #include <variant>