ada-url 1.24.0__cp312-cp312-macosx_11_0_arm64.whl → 1.29.0__cp312-cp312-macosx_11_0_arm64.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-06-30 19:51:09 -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,19 +1343,23 @@ 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
1364
  ada_warn_unused std::string_view to_string(encoding_type type);
1126
1365
 
@@ -1139,7 +1378,11 @@ ada_warn_unused std::string_view 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_view 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_view 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;
@@ -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,6 +4469,7 @@ 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>
@@ -4233,6 +4499,17 @@ struct url_pattern_init {
4233
4499
  pattern,
4234
4500
  };
4235
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
+
4236
4513
  // All strings must be valid UTF-8.
4237
4514
  // @see https://urlpattern.spec.whatwg.org/#process-a-urlpatterninit
4238
4515
  static tl::expected<url_pattern_init, errors> process(
@@ -4317,9 +4594,7 @@ struct url_pattern_init {
4317
4594
  #endif // ADA_URL_PATTERN_INIT_H
4318
4595
  /* end file include/ada/url_pattern_init.h */
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,
@@ -4381,7 +4666,14 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
4381
4666
  /* begin file include/ada/url_pattern.h */
4382
4667
  /**
4383
4668
  * @file url_pattern.h
4384
- * @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
4385
4677
  */
4386
4678
  #ifndef ADA_URL_PATTERN_H
4387
4679
  #define ADA_URL_PATTERN_H
@@ -4389,8 +4681,13 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
4389
4681
  /* begin file include/ada/implementation.h */
4390
4682
  /**
4391
4683
  * @file implementation.h
4392
- * @brief Definitions for user facing functions for parsing URL and it's
4393
- * 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
4394
4691
  */
4395
4692
  #ifndef ADA_IMPLEMENTATION_H
4396
4693
  #define ADA_IMPLEMENTATION_H
@@ -4402,7 +4699,13 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
4402
4699
  /* begin file include/ada/url.h */
4403
4700
  /**
4404
4701
  * @file url.h
4405
- * @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
4406
4709
  */
4407
4710
  #ifndef ADA_URL_H
4408
4711
  #define ADA_URL_H
@@ -4413,127 +4716,14 @@ tl::expected<url_pattern<regex_provider>, errors> parse_url_pattern_impl(
4413
4716
  #include <string>
4414
4717
  #include <string_view>
4415
4718
 
4416
- /* begin file include/ada/checkers.h */
4417
- /**
4418
- * @file checkers.h
4419
- * @brief Declarations for URL specific checkers used within Ada.
4420
- */
4421
- #ifndef ADA_CHECKERS_H
4422
- #define ADA_CHECKERS_H
4423
-
4424
-
4425
- #include <cstring>
4426
- #include <string_view>
4427
-
4428
- /**
4429
- * These functions are not part of our public API and may
4430
- * change at any time.
4431
- * @private
4432
- * @namespace ada::checkers
4433
- * @brief Includes the definitions for validation functions
4434
- */
4435
- namespace ada::checkers {
4436
-
4437
- /**
4438
- * @private
4439
- * Assuming that x is an ASCII letter, this function returns the lower case
4440
- * equivalent.
4441
- * @details More likely to be inlined by the compiler and constexpr.
4442
- */
4443
- constexpr char to_lower(char x) noexcept;
4444
-
4445
- /**
4446
- * @private
4447
- * Returns true if the character is an ASCII letter. Equivalent to std::isalpha
4448
- * but more likely to be inlined by the compiler.
4449
- *
4450
- * @attention std::isalpha is not constexpr generally.
4451
- */
4452
- constexpr bool is_alpha(char x) noexcept;
4453
-
4454
- /**
4455
- * @private
4456
- * Check whether a string starts with 0x or 0X. The function is only
4457
- * safe if input.size() >=2.
4458
- *
4459
- * @see has_hex_prefix
4460
- */
4461
- constexpr bool has_hex_prefix_unsafe(std::string_view input);
4462
- /**
4463
- * @private
4464
- * Check whether a string starts with 0x or 0X.
4465
- */
4466
- constexpr bool has_hex_prefix(std::string_view input);
4467
-
4468
- /**
4469
- * @private
4470
- * Check whether x is an ASCII digit. More likely to be inlined than
4471
- * std::isdigit.
4472
- */
4473
- constexpr bool is_digit(char x) noexcept;
4474
-
4475
- /**
4476
- * @private
4477
- * @details A string starts with a Windows drive letter if all of the following
4478
- * are true:
4479
- *
4480
- * - its length is greater than or equal to 2
4481
- * - its first two code points are a Windows drive letter
4482
- * - its length is 2 or its third code point is U+002F (/), U+005C (\), U+003F
4483
- * (?), or U+0023 (#).
4484
- *
4485
- * https://url.spec.whatwg.org/#start-with-a-windows-drive-letter
4486
- */
4487
- inline constexpr bool is_windows_drive_letter(std::string_view input) noexcept;
4488
-
4489
- /**
4490
- * @private
4491
- * @details A normalized Windows drive letter is a Windows drive letter of which
4492
- * the second code point is U+003A (:).
4493
- */
4494
- inline constexpr bool is_normalized_windows_drive_letter(
4495
- std::string_view input) noexcept;
4496
-
4497
- /**
4498
- * @private
4499
- * Returns true if an input is an ipv4 address. It is assumed that the string
4500
- * does not contain uppercase ASCII characters (the input should have been
4501
- * lowered cased before calling this function) and is not empty.
4502
- */
4503
- ada_really_inline constexpr bool is_ipv4(std::string_view view) noexcept;
4504
-
4505
- /**
4506
- * @private
4507
- * Returns a bitset. If the first bit is set, then at least one character needs
4508
- * percent encoding. If the second bit is set, a \\ is found. If the third bit
4509
- * is set then we have a dot. If the fourth bit is set, then we have a percent
4510
- * character.
4511
- */
4512
- ada_really_inline constexpr uint8_t path_signature(
4513
- std::string_view input) noexcept;
4514
-
4515
- /**
4516
- * @private
4517
- * Returns true if the length of the domain name and its labels are according to
4518
- * the specifications. The length of the domain must be 255 octets (253
4519
- * characters not including the last 2 which are the empty label reserved at the
4520
- * end). When the empty label is included (a dot at the end), the domain name
4521
- * can have 254 characters. The length of a label must be at least 1 and at most
4522
- * 63 characters.
4523
- * @see section 3.1. of https://www.rfc-editor.org/rfc/rfc1034
4524
- * @see https://www.unicode.org/reports/tr46/#ToASCII
4525
- */
4526
- ada_really_inline constexpr bool verify_dns_length(
4527
- std::string_view input) noexcept;
4528
-
4529
- } // namespace ada::checkers
4530
-
4531
- #endif // ADA_CHECKERS_H
4532
- /* end file include/ada/checkers.h */
4533
4719
  /* begin file include/ada/url_components.h */
4534
4720
  /**
4535
4721
  * @file url_components.h
4536
- * @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.
4537
4727
  */
4538
4728
  #ifndef ADA_URL_COMPONENTS_H
4539
4729
  #define ADA_URL_COMPONENTS_H
@@ -4541,14 +4731,32 @@ ada_really_inline constexpr bool verify_dns_length(
4541
4731
  namespace ada {
4542
4732
 
4543
4733
  /**
4544
- * @brief URL Component representations using offsets.
4734
+ * @brief Stores byte offsets for URL components within a buffer.
4545
4735
  *
4546
- * @details We design the url_components struct so that it is as small
4547
- * and simple as possible. This version uses 32 bytes.
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.
4548
4739
  *
4549
- * This struct is used to extract components from a single 'href'.
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
+ * ```
4753
+ *
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.
4550
4757
  */
4551
4758
  struct url_components {
4759
+ /** Sentinel value indicating a component is not present. */
4552
4760
  constexpr static uint32_t omitted = uint32_t(-1);
4553
4761
 
4554
4762
  url_components() = default;
@@ -4558,47 +4766,43 @@ struct url_components {
4558
4766
  url_components &operator=(const url_components &u) = default;
4559
4767
  ~url_components() = default;
4560
4768
 
4561
- /*
4562
- * By using 32-bit integers, we implicitly assume that the URL string
4563
- * cannot exceed 4 GB.
4564
- *
4565
- * https://user:pass@example.com:1234/foo/bar?baz#quux
4566
- * | | | | ^^^^| | |
4567
- * | | | | | | | `----- hash_start
4568
- * | | | | | | `--------- search_start
4569
- * | | | | | `----------------- pathname_start
4570
- * | | | | `--------------------- port
4571
- * | | | `----------------------- host_end
4572
- * | | `---------------------------------- host_start
4573
- * | `--------------------------------------- username_end
4574
- * `--------------------------------------------- protocol_end
4575
- */
4769
+ /** Offset of the end of the protocol/scheme (position of ':'). */
4576
4770
  uint32_t protocol_end{0};
4771
+
4577
4772
  /**
4578
- * Username end is not `omitted` by default to make username and password
4579
- * getters less costly to implement.
4773
+ * Offset of the end of the username.
4774
+ * Initialized to 0 (not `omitted`) to simplify username/password getters.
4580
4775
  */
4581
4776
  uint32_t username_end{0};
4777
+
4778
+ /** Offset of the start of the host. */
4582
4779
  uint32_t host_start{0};
4780
+
4781
+ /** Offset of the end of the host. */
4583
4782
  uint32_t host_end{0};
4783
+
4784
+ /** Port number, or `omitted` if no port is specified. */
4584
4785
  uint32_t port{omitted};
4786
+
4787
+ /** Offset of the start of the pathname. */
4585
4788
  uint32_t pathname_start{0};
4789
+
4790
+ /** Offset of the '?' starting the query, or `omitted` if no query. */
4586
4791
  uint32_t search_start{omitted};
4792
+
4793
+ /** Offset of the '#' starting the fragment, or `omitted` if no fragment. */
4587
4794
  uint32_t hash_start{omitted};
4588
4795
 
4589
4796
  /**
4590
- * Check the following conditions:
4591
- * protocol_end < username_end < ... < hash_start,
4592
- * expect when a value is omitted. It also computes
4593
- * a lower bound on the possible string length that may match these
4594
- * offsets.
4595
- * @return true if the offset values are
4596
- * 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.
4597
4800
  */
4598
4801
  [[nodiscard]] constexpr bool check_offset_consistency() const noexcept;
4599
4802
 
4600
4803
  /**
4601
- * 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.
4602
4806
  */
4603
4807
  [[nodiscard]] std::string to_string() const;
4604
4808
 
@@ -4621,15 +4825,26 @@ struct url_aggregator;
4621
4825
  // }
4622
4826
 
4623
4827
  /**
4624
- * @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
4625
4838
  *
4626
- * @details To disambiguate from a valid URL string it can also be referred to
4627
- * as a URL record. A URL is a struct that represents a universal identifier.
4628
- * Unlike the url_aggregator, the ada::url represents the different components
4629
- * of a parsed URL as independent std::string instances. This makes the
4630
- * structure heavier and more reliant on memory allocations. When getting
4631
- * 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
4632
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
4633
4848
  * @see https://url.spec.whatwg.org/#url-representation
4634
4849
  */
4635
4850
  struct url : url_base {
@@ -4688,177 +4903,217 @@ struct url : url_base {
4688
4903
  */
4689
4904
  std::optional<std::string> hash{};
4690
4905
 
4691
- /** @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
+ */
4692
4910
  [[nodiscard]] inline bool has_empty_hostname() const noexcept;
4693
- /** @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
+ */
4694
4916
  [[nodiscard]] inline bool has_port() const noexcept;
4695
- /** @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
+ */
4696
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
+ */
4697
4930
  [[nodiscard]] bool has_valid_domain() const noexcept override;
4698
4931
 
4699
4932
  /**
4700
- * 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.
4701
4935
  */
4702
4936
  [[nodiscard]] std::string to_string() const override;
4703
4937
 
4704
4938
  /**
4939
+ * Returns the full serialized URL (the href).
4940
+ * @return The complete URL string (allocates a new string).
4705
4941
  * @see https://url.spec.whatwg.org/#dom-url-href
4706
- * @see https://url.spec.whatwg.org/#concept-url-serializer
4707
4942
  */
4708
- [[nodiscard]] ada_really_inline std::string get_href() const noexcept;
4943
+ [[nodiscard]] ada_really_inline std::string get_href() const;
4709
4944
 
4710
4945
  /**
4711
- * The origin getter steps are to return the serialization of this's URL's
4712
- * origin. [HTML]
4713
- * @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.
4714
4949
  * @see https://url.spec.whatwg.org/#concept-url-origin
4715
4950
  */
4716
- [[nodiscard]] std::string get_origin() const noexcept override;
4951
+ [[nodiscard]] std::string get_origin() const override;
4717
4952
 
4718
4953
  /**
4719
- * The protocol getter steps are to return this's URL's scheme, followed by
4720
- * U+003A (:).
4721
- * @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.
4722
4956
  * @see https://url.spec.whatwg.org/#dom-url-protocol
4723
4957
  */
4724
- [[nodiscard]] std::string get_protocol() const noexcept;
4958
+ [[nodiscard]] std::string get_protocol() const;
4725
4959
 
4726
4960
  /**
4727
- * Return url's host, serialized, followed by U+003A (:) and url's port,
4728
- * serialized.
4729
- * When there is no host, this function returns the empty string.
4730
- * @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.
4731
4964
  * @see https://url.spec.whatwg.org/#dom-url-host
4732
4965
  */
4733
- [[nodiscard]] std::string get_host() const noexcept;
4966
+ [[nodiscard]] std::string get_host() const;
4734
4967
 
4735
4968
  /**
4736
- * Return this's URL's host, serialized.
4737
- * When there is no host, this function returns the empty string.
4738
- * @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.
4739
4972
  * @see https://url.spec.whatwg.org/#dom-url-hostname
4740
4973
  */
4741
- [[nodiscard]] std::string get_hostname() const noexcept;
4974
+ [[nodiscard]] std::string get_hostname() const;
4742
4975
 
4743
4976
  /**
4744
- * The pathname getter steps are to return the result of URL path serializing
4745
- * this's URL.
4746
- * @return a newly allocated string.
4977
+ * Returns the URL's path component.
4978
+ * @return A string_view pointing to the path.
4747
4979
  * @see https://url.spec.whatwg.org/#dom-url-pathname
4748
4980
  */
4749
4981
  [[nodiscard]] constexpr std::string_view get_pathname() const noexcept;
4750
4982
 
4751
4983
  /**
4752
- * Compute the pathname length in bytes without instantiating a view or a
4753
- * string.
4754
- * @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.
4755
4986
  * @see https://url.spec.whatwg.org/#dom-url-pathname
4756
4987
  */
4757
4988
  [[nodiscard]] ada_really_inline size_t get_pathname_length() const noexcept;
4758
4989
 
4759
4990
  /**
4760
- * Return U+003F (?), followed by this's URL's query.
4761
- * @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.
4762
4994
  * @see https://url.spec.whatwg.org/#dom-url-search
4763
4995
  */
4764
- [[nodiscard]] std::string get_search() const noexcept;
4996
+ [[nodiscard]] std::string get_search() const;
4765
4997
 
4766
4998
  /**
4767
- * The username getter steps are to return this's URL's username.
4768
- * @return a constant reference to the underlying string.
4999
+ * Returns the URL's username component.
5000
+ * @return A constant reference to the username string.
4769
5001
  * @see https://url.spec.whatwg.org/#dom-url-username
4770
5002
  */
4771
5003
  [[nodiscard]] const std::string &get_username() const noexcept;
4772
5004
 
4773
5005
  /**
4774
- * @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.
4775
5009
  * @see https://url.spec.whatwg.org/#dom-url-username
4776
5010
  */
4777
5011
  bool set_username(std::string_view input);
4778
5012
 
4779
5013
  /**
4780
- * @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.
4781
5017
  * @see https://url.spec.whatwg.org/#dom-url-password
4782
5018
  */
4783
5019
  bool set_password(std::string_view input);
4784
5020
 
4785
5021
  /**
4786
- * @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.
4787
5025
  * @see https://url.spec.whatwg.org/#dom-url-port
4788
5026
  */
4789
5027
  bool set_port(std::string_view input);
4790
5028
 
4791
5029
  /**
4792
- * 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 '#').
4793
5032
  * @see https://url.spec.whatwg.org/#dom-url-hash
4794
5033
  */
4795
5034
  void set_hash(std::string_view input);
4796
5035
 
4797
5036
  /**
4798
- * 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 '?').
4799
5039
  * @see https://url.spec.whatwg.org/#dom-url-search
4800
5040
  */
4801
5041
  void set_search(std::string_view input);
4802
5042
 
4803
5043
  /**
4804
- * @return Returns true on success.
4805
- * @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
4806
5048
  */
4807
5049
  bool set_pathname(std::string_view input);
4808
5050
 
4809
5051
  /**
4810
- * @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.
4811
5055
  * @see https://url.spec.whatwg.org/#dom-url-host
4812
5056
  */
4813
5057
  bool set_host(std::string_view input);
4814
5058
 
4815
5059
  /**
4816
- * @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.
4817
5063
  * @see https://url.spec.whatwg.org/#dom-url-hostname
4818
5064
  */
4819
5065
  bool set_hostname(std::string_view input);
4820
5066
 
4821
5067
  /**
4822
- * @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.
4823
5071
  * @see https://url.spec.whatwg.org/#dom-url-protocol
4824
5072
  */
4825
5073
  bool set_protocol(std::string_view input);
4826
5074
 
4827
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.
4828
5079
  * @see https://url.spec.whatwg.org/#dom-url-href
4829
5080
  */
4830
5081
  bool set_href(std::string_view input);
4831
5082
 
4832
5083
  /**
4833
- * The password getter steps are to return this's URL's password.
4834
- * @return a constant reference to the underlying string.
5084
+ * Returns the URL's password component.
5085
+ * @return A constant reference to the password string.
4835
5086
  * @see https://url.spec.whatwg.org/#dom-url-password
4836
5087
  */
4837
5088
  [[nodiscard]] const std::string &get_password() const noexcept;
4838
5089
 
4839
5090
  /**
4840
- * Return this's URL's port, serialized.
4841
- * @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.
4842
5094
  * @see https://url.spec.whatwg.org/#dom-url-port
4843
5095
  */
4844
- [[nodiscard]] std::string get_port() const noexcept;
5096
+ [[nodiscard]] std::string get_port() const;
4845
5097
 
4846
5098
  /**
4847
- * Return U+0023 (#), followed by this's URL's fragment.
4848
- * @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.
4849
5102
  * @see https://url.spec.whatwg.org/#dom-url-hash
4850
5103
  */
4851
- [[nodiscard]] std::string get_hash() const noexcept;
5104
+ [[nodiscard]] std::string get_hash() const;
4852
5105
 
4853
5106
  /**
4854
- * A URL includes credentials if its username or password is not the empty
4855
- * 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.
4856
5109
  */
4857
5110
  [[nodiscard]] ada_really_inline bool has_credentials() const noexcept;
4858
5111
 
4859
5112
  /**
4860
- * Useful for implementing efficient serialization for the URL.
5113
+ * Returns the URL component offsets for efficient serialization.
4861
5114
  *
5115
+ * The components represent byte offsets into the serialized URL:
5116
+ * ```
4862
5117
  * https://user:pass@example.com:1234/foo/bar?baz#quux
4863
5118
  * | | | | ^^^^| | |
4864
5119
  * | | | | | | | `----- hash_start
@@ -4869,19 +5124,23 @@ struct url : url_base {
4869
5124
  * | | `---------------------------------- host_start
4870
5125
  * | `--------------------------------------- username_end
4871
5126
  * `--------------------------------------------- protocol_end
4872
- *
4873
- * Inspired after servo/url
4874
- *
4875
- * @return a newly constructed component.
4876
- *
4877
- * @see
4878
- * 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
4879
5130
  */
4880
5131
  [[nodiscard]] ada_really_inline ada::url_components get_components()
4881
5132
  const noexcept;
4882
- /** @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
+ */
4883
5138
  [[nodiscard]] constexpr bool has_hash() const noexcept override;
4884
- /** @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
+ */
4885
5144
  [[nodiscard]] constexpr bool has_search() const noexcept override;
4886
5145
 
4887
5146
  private:
@@ -4890,7 +5149,7 @@ struct url : url_base {
4890
5149
  friend ada::url_aggregator ada::parser::parse_url<ada::url_aggregator>(
4891
5150
  std::string_view, const ada::url_aggregator *);
4892
5151
  friend void ada::helpers::strip_trailing_spaces_from_opaque_path<ada::url>(
4893
- ada::url &url) noexcept;
5152
+ ada::url &url);
4894
5153
 
4895
5154
  friend ada::url ada::parser::parse_url_impl<ada::url, true>(std::string_view,
4896
5155
  const ada::url *);
@@ -4997,7 +5256,7 @@ struct url : url_base {
4997
5256
  * Take the scheme from another URL. The scheme string is moved from the
4998
5257
  * provided url.
4999
5258
  */
5000
- constexpr void copy_scheme(ada::url &&u) noexcept;
5259
+ constexpr void copy_scheme(ada::url &&u);
5001
5260
 
5002
5261
  /**
5003
5262
  * Take the scheme from another URL. The scheme string is copied from the
@@ -5015,17 +5274,70 @@ inline std::ostream &operator<<(std::ostream &out, const ada::url &u);
5015
5274
 
5016
5275
  namespace ada {
5017
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
+ */
5018
5295
  template <class result_type = ada::url_aggregator>
5019
5296
  using result = tl::expected<result_type, ada::errors>;
5020
5297
 
5021
5298
  /**
5022
- * The URL parser takes a scalar value string input, with an optional null or
5023
- * base URL base (default null). The parser assumes the input is a valid ASCII
5024
- * 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.
5025
5317
  *
5026
- * @param input the string input to analyze (must be valid ASCII or UTF-8)
5027
- * @param base_url the optional URL input to use as a base url.
5028
- * @return a parsed URL.
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
+ * }
5328
+ *
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
5029
5341
  */
5030
5342
  template <class result_type = ada::url_aggregator>
5031
5343
  ada_warn_unused ada::result<result_type> parse(
@@ -5037,23 +5349,56 @@ extern template ada::result<url_aggregator> parse<url_aggregator>(
5037
5349
  std::string_view input, const url_aggregator* base_url);
5038
5350
 
5039
5351
  /**
5040
- * Verifies whether the URL strings can be parsed. The function assumes
5041
- * 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
+ *
5042
5377
  * @see https://url.spec.whatwg.org/#dom-url-canparse
5043
- * @return If URL can be parsed or not.
5044
5378
  */
5045
5379
  bool can_parse(std::string_view input,
5046
5380
  const std::string_view* base_input = nullptr);
5047
5381
 
5048
5382
  #if ADA_INCLUDE_URL_PATTERN
5049
5383
  /**
5050
- * Implementation of the URL pattern parsing algorithm.
5051
- * @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.
5052
5389
  *
5053
- * @param input valid UTF-8 string or URLPatternInit struct
5054
- * @param base_url an optional valid UTF-8 string
5055
- * @param options an optional url_pattern_options struct
5056
- * @return url_pattern instance
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).
5397
+ *
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
5057
5402
  */
5058
5403
  template <url_pattern_regex::regex_concept regex_provider>
5059
5404
  ada_warn_unused tl::expected<url_pattern<regex_provider>, errors>
@@ -5063,9 +5408,14 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init>&& input,
5063
5408
  #endif // ADA_INCLUDE_URL_PATTERN
5064
5409
 
5065
5410
  /**
5066
- * Computes a href string from a file path. The function assumes
5067
- * that the input is a valid ASCII or UTF-8 string.
5068
- * @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.
5069
5419
  */
5070
5420
  std::string href_from_file(std::string_view path);
5071
5421
  } // namespace ada
@@ -5101,6 +5451,19 @@ enum class url_pattern_part_type : uint8_t {
5101
5451
  FULL_WILDCARD,
5102
5452
  };
5103
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
+
5104
5467
  enum class url_pattern_part_modifier : uint8_t {
5105
5468
  // The part does not have a modifier.
5106
5469
  none,
@@ -5220,11 +5583,15 @@ class url_pattern_component {
5220
5583
  url_pattern_component(std::string&& new_pattern,
5221
5584
  typename regex_provider::regex_type&& new_regexp,
5222
5585
  std::vector<std::string>&& new_group_name_list,
5223
- 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 = {})
5224
5589
  : regexp(std::move(new_regexp)),
5225
5590
  pattern(std::move(new_pattern)),
5226
5591
  group_name_list(std::move(new_group_name_list)),
5227
- 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) {}
5228
5595
 
5229
5596
  // @see https://urlpattern.spec.whatwg.org/#compile-a-component
5230
5597
  template <url_pattern_encoding_callback F>
@@ -5237,6 +5604,16 @@ class url_pattern_component {
5237
5604
  std::string&& input,
5238
5605
  std::vector<std::optional<std::string>>&& exec_result);
5239
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
+
5240
5617
  #if ADA_TESTING
5241
5618
  friend void PrintTo(const url_pattern_component& component,
5242
5619
  std::ostream* os) {
@@ -5252,7 +5629,11 @@ class url_pattern_component {
5252
5629
  typename regex_provider::regex_type regexp{};
5253
5630
  std::string pattern{};
5254
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{};
5255
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;
5256
5637
  };
5257
5638
 
5258
5639
  // A URLPattern input can be either a string or a URLPatternInit object.
@@ -5284,14 +5665,28 @@ struct url_pattern_options {
5284
5665
  #endif // ADA_TESTING
5285
5666
  };
5286
5667
 
5287
- // URLPattern is a Web Platform standard API for matching URLs against a
5288
- // pattern syntax (think of it as a regular expression for URLs). It is
5289
- // defined in https://wicg.github.io/urlpattern.
5290
- // More information about the URL Pattern syntax can be found at
5291
- // https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API
5292
- //
5293
- // We require all strings to be valid UTF-8: it is the user's responsibility
5294
- // 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
+ */
5295
5690
  template <url_pattern_regex::regex_concept regex_provider>
5296
5691
  class url_pattern {
5297
5692
  public:
@@ -5344,6 +5739,13 @@ class url_pattern {
5344
5739
  // @see https://urlpattern.spec.whatwg.org/#url-pattern-has-regexp-groups
5345
5740
  [[nodiscard]] bool has_regexp_groups() const;
5346
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
+
5347
5749
  #if ADA_TESTING
5348
5750
  friend void PrintTo(const url_pattern& c, std::ostream* os) {
5349
5751
  *os << "protocol_component: '" << c.get_protocol() << ", ";
@@ -5468,8 +5870,8 @@ enum class token_policy {
5468
5870
  // @see https://urlpattern.spec.whatwg.org/#tokens
5469
5871
  class token {
5470
5872
  public:
5471
- token(token_type _type, size_t _index, std::string&& _value)
5472
- : 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) {}
5473
5875
 
5474
5876
  // A token has an associated type, a string, initially "invalid-char".
5475
5877
  token_type type = token_type::INVALID_CHAR;
@@ -5480,7 +5882,7 @@ class token {
5480
5882
 
5481
5883
  // A token has an associated value, a string, initially the empty string. It
5482
5884
  // contains the code points from the pattern string represented by the token.
5483
- std::string value{};
5885
+ std::string_view value{};
5484
5886
  };
5485
5887
 
5486
5888
  // @see https://urlpattern.spec.whatwg.org/#pattern-parser
@@ -5558,7 +5960,7 @@ class Tokenizer {
5558
5960
 
5559
5961
  private:
5560
5962
  // has an associated input, a pattern string, initially the empty string.
5561
- std::string input;
5963
+ std::string_view input;
5562
5964
  // has an associated policy, a tokenize policy, initially "strict".
5563
5965
  token_policy policy;
5564
5966
  // has an associated token list, a token list, initially an empty list.
@@ -5652,7 +6054,7 @@ struct constructor_string_parser {
5652
6054
  // @see https://urlpattern.spec.whatwg.org/#make-a-component-string
5653
6055
  std::string make_component_string();
5654
6056
  // has an associated input, a string, which must be set upon creation.
5655
- std::string input;
6057
+ std::string_view input;
5656
6058
  // has an associated token list, a token list, which must be set upon
5657
6059
  // creation.
5658
6060
  std::vector<token> token_list;
@@ -5759,7 +6161,7 @@ bool protocol_component_matches_special_scheme(
5759
6161
  ada::url_pattern_component<regex_provider>& input);
5760
6162
 
5761
6163
  // @see https://urlpattern.spec.whatwg.org/#convert-a-modifier-to-a-string
5762
- std::string convert_modifier_to_string(url_pattern_part_modifier modifier);
6164
+ std::string_view convert_modifier_to_string(url_pattern_part_modifier modifier);
5763
6165
 
5764
6166
  // @see https://urlpattern.spec.whatwg.org/#generate-a-segment-wildcard-regexp
5765
6167
  std::string generate_segment_wildcard_regexp(
@@ -6125,7 +6527,10 @@ constexpr ada::scheme::type get_scheme_type(std::string_view scheme) noexcept {
6125
6527
  /* begin file include/ada/serializers.h */
6126
6528
  /**
6127
6529
  * @file serializers.h
6128
- * @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.
6129
6534
  */
6130
6535
  #ifndef ADA_SERIALIZERS_H
6131
6536
  #define ADA_SERIALIZERS_H
@@ -6136,32 +6541,41 @@ constexpr ada::scheme::type get_scheme_type(std::string_view scheme) noexcept {
6136
6541
 
6137
6542
  /**
6138
6543
  * @namespace ada::serializers
6139
- * @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.
6140
6547
  */
6141
6548
  namespace ada::serializers {
6142
6549
 
6143
6550
  /**
6144
- * 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.
6145
6557
  */
6146
6558
  void find_longest_sequence_of_ipv6_pieces(
6147
6559
  const std::array<uint16_t, 8>& address, size_t& compress,
6148
6560
  size_t& compress_length) noexcept;
6149
6561
 
6150
6562
  /**
6151
- * Serializes an ipv6 address.
6152
- * @details An IPv6 address is a 128-bit unsigned integer that identifies a
6153
- * 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").
6154
6567
  * @see https://url.spec.whatwg.org/#concept-ipv6-serializer
6155
6568
  */
6156
- std::string ipv6(const std::array<uint16_t, 8>& address) noexcept;
6569
+ std::string ipv6(const std::array<uint16_t, 8>& address);
6157
6570
 
6158
6571
  /**
6159
- * Serializes an ipv4 address.
6160
- * @details An IPv4 address is a 32-bit unsigned integer that identifies a
6161
- * 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").
6162
6576
  * @see https://url.spec.whatwg.org/#concept-ipv4-serializer
6163
6577
  */
6164
- std::string ipv4(uint64_t address) noexcept;
6578
+ std::string ipv4(uint64_t address);
6165
6579
 
6166
6580
  } // namespace ada::serializers
6167
6581
 
@@ -6170,7 +6584,12 @@ std::string ipv4(uint64_t address) noexcept;
6170
6584
  /* begin file include/ada/state.h */
6171
6585
  /**
6172
6586
  * @file state.h
6173
- * @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
6174
6593
  */
6175
6594
  #ifndef ADA_STATE_H
6176
6595
  #define ADA_STATE_H
@@ -6181,6 +6600,11 @@ std::string ipv4(uint64_t address) noexcept;
6181
6600
  namespace ada {
6182
6601
 
6183
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
+ *
6184
6608
  * @see https://url.spec.whatwg.org/#url-parsing
6185
6609
  */
6186
6610
  enum class state {
@@ -6286,7 +6710,9 @@ enum class state {
6286
6710
  };
6287
6711
 
6288
6712
  /**
6289
- * 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.
6290
6716
  */
6291
6717
  ada_warn_unused std::string to_string(ada::state s);
6292
6718
 
@@ -6625,6 +7051,7 @@ inline std::ostream &operator<<(std::ostream &out, const ada::url &u) {
6625
7051
  out.protocol_end = uint32_t(get_protocol().size());
6626
7052
 
6627
7053
  // Trailing index is always the next character of the current one.
7054
+ // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
6628
7055
  size_t running_index = out.protocol_end;
6629
7056
 
6630
7057
  if (host.has_value()) {
@@ -6744,7 +7171,7 @@ inline void url::set_scheme(std::string &&new_scheme) noexcept {
6744
7171
  }
6745
7172
  }
6746
7173
 
6747
- constexpr void url::copy_scheme(ada::url &&u) noexcept {
7174
+ constexpr void url::copy_scheme(ada::url &&u) {
6748
7175
  non_special_scheme = u.non_special_scheme;
6749
7176
  type = u.type;
6750
7177
  }
@@ -6754,7 +7181,7 @@ constexpr void url::copy_scheme(const ada::url &u) {
6754
7181
  type = u.type;
6755
7182
  }
6756
7183
 
6757
- [[nodiscard]] ada_really_inline std::string url::get_href() const noexcept {
7184
+ [[nodiscard]] ada_really_inline std::string url::get_href() const {
6758
7185
  std::string output = get_protocol();
6759
7186
 
6760
7187
  if (host.has_value()) {
@@ -6913,7 +7340,13 @@ namespace ada {
6913
7340
  /* begin file include/ada/url_aggregator.h */
6914
7341
  /**
6915
7342
  * @file url_aggregator.h
6916
- * @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
6917
7350
  */
6918
7351
  #ifndef ADA_URL_AGGREGATOR_H
6919
7352
  #define ADA_URL_AGGREGATOR_H
@@ -6929,12 +7362,23 @@ namespace ada {
6929
7362
  namespace parser {}
6930
7363
 
6931
7364
  /**
6932
- * @brief Lightweight URL struct.
7365
+ * @brief Memory-efficient URL representation using a single buffer.
6933
7366
  *
6934
- * @details The url_aggregator class aims to minimize temporary memory
6935
- * allocation while representing a parsed URL. Internally, it contains a single
6936
- * normalized URL (the href), and it makes available the components, mostly
6937
- * using std::string_view.
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.
7374
+ *
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
6938
7382
  */
6939
7383
  struct url_aggregator : url_base {
6940
7384
  url_aggregator() = default;
@@ -6944,6 +7388,25 @@ struct url_aggregator : url_base {
6944
7388
  url_aggregator &operator=(const url_aggregator &u) = default;
6945
7389
  ~url_aggregator() override = default;
6946
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
+ */
6947
7410
  bool set_href(std::string_view input);
6948
7411
  bool set_host(std::string_view input);
6949
7412
  bool set_hostname(std::string_view input);
@@ -6955,115 +7418,130 @@ struct url_aggregator : url_base {
6955
7418
  void set_search(std::string_view input);
6956
7419
  void set_hash(std::string_view input);
6957
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
+ */
6958
7425
  [[nodiscard]] bool has_valid_domain() const noexcept override;
7426
+
6959
7427
  /**
6960
- * The origin getter steps are to return the serialization of this's URL's
6961
- * origin. [HTML]
6962
- * @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.
6963
7430
  * @see https://url.spec.whatwg.org/#concept-url-origin
6964
7431
  */
6965
- [[nodiscard]] std::string get_origin() const noexcept override;
7432
+ [[nodiscard]] std::string get_origin() const override;
7433
+
6966
7434
  /**
6967
- * Return the normalized string.
6968
- * This function does not allocate memory.
6969
- * It is highly efficient.
6970
- * @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.
6971
7439
  * @see https://url.spec.whatwg.org/#dom-url-href
6972
- * @see https://url.spec.whatwg.org/#concept-url-serializer
6973
7440
  */
6974
7441
  [[nodiscard]] constexpr std::string_view get_href() const noexcept
6975
7442
  ada_lifetime_bound;
7443
+
6976
7444
  /**
6977
- * The username getter steps are to return this's URL's username.
6978
- * This function does not allocate memory.
6979
- * @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.
6980
7449
  * @see https://url.spec.whatwg.org/#dom-url-username
6981
7450
  */
6982
- [[nodiscard]] std::string_view get_username() const noexcept
6983
- ada_lifetime_bound;
7451
+ [[nodiscard]] std::string_view get_username() const ada_lifetime_bound;
7452
+
6984
7453
  /**
6985
- * The password getter steps are to return this's URL's password.
6986
- * This function does not allocate memory.
6987
- * @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.
6988
7458
  * @see https://url.spec.whatwg.org/#dom-url-password
6989
7459
  */
6990
- [[nodiscard]] std::string_view get_password() const noexcept
6991
- ada_lifetime_bound;
7460
+ [[nodiscard]] std::string_view get_password() const ada_lifetime_bound;
7461
+
6992
7462
  /**
6993
- * Return this's URL's port, serialized.
6994
- * This function does not allocate memory.
6995
- * @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.
6996
7467
  * @see https://url.spec.whatwg.org/#dom-url-port
6997
7468
  */
6998
- [[nodiscard]] std::string_view get_port() const noexcept ada_lifetime_bound;
7469
+ [[nodiscard]] std::string_view get_port() const ada_lifetime_bound;
7470
+
6999
7471
  /**
7000
- * Return U+0023 (#), followed by this's URL's fragment.
7001
- * This function does not allocate memory.
7002
- * @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.
7003
7476
  * @see https://url.spec.whatwg.org/#dom-url-hash
7004
7477
  */
7005
- [[nodiscard]] std::string_view get_hash() const noexcept ada_lifetime_bound;
7478
+ [[nodiscard]] std::string_view get_hash() const ada_lifetime_bound;
7479
+
7006
7480
  /**
7007
- * Return url's host, serialized, followed by U+003A (:) and url's port,
7008
- * serialized.
7009
- * This function does not allocate memory.
7010
- * When there is no host, this function returns the empty view.
7011
- * @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.
7012
7485
  * @see https://url.spec.whatwg.org/#dom-url-host
7013
7486
  */
7014
- [[nodiscard]] std::string_view get_host() const noexcept ada_lifetime_bound;
7487
+ [[nodiscard]] std::string_view get_host() const ada_lifetime_bound;
7488
+
7015
7489
  /**
7016
- * Return this's URL's host, serialized.
7017
- * This function does not allocate memory.
7018
- * When there is no host, this function returns the empty view.
7019
- * @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.
7020
7494
  * @see https://url.spec.whatwg.org/#dom-url-hostname
7021
7495
  */
7022
- [[nodiscard]] std::string_view get_hostname() const noexcept
7023
- ada_lifetime_bound;
7496
+ [[nodiscard]] std::string_view get_hostname() const ada_lifetime_bound;
7497
+
7024
7498
  /**
7025
- * The pathname getter steps are to return the result of URL path serializing
7026
- * this's URL.
7027
- * This function does not allocate memory.
7028
- * @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.
7029
7503
  * @see https://url.spec.whatwg.org/#dom-url-pathname
7030
7504
  */
7031
- [[nodiscard]] constexpr std::string_view get_pathname() const noexcept
7505
+ [[nodiscard]] constexpr std::string_view get_pathname() const
7032
7506
  ada_lifetime_bound;
7507
+
7033
7508
  /**
7034
- * Compute the pathname length in bytes without instantiating a view or a
7035
- * string.
7036
- * @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.
7037
7511
  * @see https://url.spec.whatwg.org/#dom-url-pathname
7038
7512
  */
7039
7513
  [[nodiscard]] ada_really_inline uint32_t get_pathname_length() const noexcept;
7514
+
7040
7515
  /**
7041
- * Return U+003F (?), followed by this's URL's query.
7042
- * This function does not allocate memory.
7043
- * @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.
7044
7520
  * @see https://url.spec.whatwg.org/#dom-url-search
7045
7521
  */
7046
- [[nodiscard]] std::string_view get_search() const noexcept ada_lifetime_bound;
7522
+ [[nodiscard]] std::string_view get_search() const ada_lifetime_bound;
7523
+
7047
7524
  /**
7048
- * The protocol getter steps are to return this's URL's scheme, followed by
7049
- * U+003A (:).
7050
- * This function does not allocate memory.
7051
- * @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.
7052
7529
  * @see https://url.spec.whatwg.org/#dom-url-protocol
7053
7530
  */
7054
- [[nodiscard]] std::string_view get_protocol() const noexcept
7055
- ada_lifetime_bound;
7531
+ [[nodiscard]] std::string_view get_protocol() const ada_lifetime_bound;
7056
7532
 
7057
7533
  /**
7058
- * A URL includes credentials if its username or password is not the empty
7059
- * 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.
7060
7536
  */
7061
7537
  [[nodiscard]] ada_really_inline constexpr bool has_credentials()
7062
7538
  const noexcept;
7063
7539
 
7064
7540
  /**
7065
- * Useful for implementing efficient serialization for the URL.
7541
+ * Returns the URL component offsets for efficient serialization.
7066
7542
  *
7543
+ * The components represent byte offsets into the serialized URL:
7544
+ * ```
7067
7545
  * https://user:pass@example.com:1234/foo/bar?baz#quux
7068
7546
  * | | | | ^^^^| | |
7069
7547
  * | | | | | | | `----- hash_start
@@ -7074,57 +7552,99 @@ struct url_aggregator : url_base {
7074
7552
  * | | `---------------------------------- host_start
7075
7553
  * | `--------------------------------------- username_end
7076
7554
  * `--------------------------------------------- protocol_end
7077
- *
7078
- * Inspired after servo/url
7079
- *
7080
- * @return a constant reference to the underlying component attribute.
7081
- *
7082
- * @see
7083
- * 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
7084
7558
  */
7085
7559
  [[nodiscard]] ada_really_inline const url_components &get_components()
7086
7560
  const noexcept;
7561
+
7087
7562
  /**
7088
- * 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.
7089
7565
  */
7090
7566
  [[nodiscard]] std::string to_string() const override;
7567
+
7091
7568
  /**
7092
- * 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.
7093
7572
  */
7094
7573
  [[nodiscard]] std::string to_diagram() const;
7095
7574
 
7096
7575
  /**
7097
- * Verifies that the parsed URL could be valid. Useful for debugging purposes.
7098
- * @return true if the URL is valid, otherwise return true of the offsets are
7099
- * possible.
7576
+ * Validates internal consistency of component offsets (for debugging).
7577
+ * @return `true` if offsets are consistent, `false` if corrupted.
7100
7578
  */
7101
7579
  [[nodiscard]] constexpr bool validate() const noexcept;
7102
7580
 
7103
- /** @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
+ */
7104
7585
  [[nodiscard]] constexpr bool has_empty_hostname() const noexcept;
7105
- /** @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
+ */
7106
7591
  [[nodiscard]] constexpr bool has_hostname() const noexcept;
7107
- /** @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
+ */
7108
7597
  [[nodiscard]] constexpr bool has_non_empty_username() const noexcept;
7109
- /** @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
+ */
7110
7603
  [[nodiscard]] constexpr bool has_non_empty_password() const noexcept;
7111
- /** @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
+ */
7112
7609
  [[nodiscard]] constexpr bool has_port() const noexcept;
7113
- /** @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
+ */
7114
7615
  [[nodiscard]] constexpr bool has_password() const noexcept;
7115
- /** @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
+ */
7116
7621
  [[nodiscard]] constexpr bool has_hash() const noexcept override;
7117
- /** @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
+ */
7118
7627
  [[nodiscard]] constexpr bool has_search() const noexcept override;
7119
7628
 
7629
+ /**
7630
+ * Removes the port from the URL.
7631
+ */
7120
7632
  inline void clear_port();
7633
+
7634
+ /**
7635
+ * Removes the hash/fragment from the URL.
7636
+ */
7121
7637
  inline void clear_hash();
7638
+
7639
+ /**
7640
+ * Removes the query/search string from the URL.
7641
+ */
7122
7642
  inline void clear_search() override;
7123
7643
 
7124
7644
  private:
7125
7645
  // helper methods
7126
7646
  friend void helpers::strip_trailing_spaces_from_opaque_path<url_aggregator>(
7127
- url_aggregator &url) noexcept;
7647
+ url_aggregator &url);
7128
7648
  // parse_url methods
7129
7649
  friend url_aggregator parser::parse_url<url_aggregator>(
7130
7650
  std::string_view, const url_aggregator *);
@@ -7153,7 +7673,7 @@ struct url_aggregator : url_base {
7153
7673
  */
7154
7674
  [[nodiscard]] ada_really_inline bool is_at_path() const noexcept;
7155
7675
 
7156
- inline void add_authority_slashes_if_needed() noexcept;
7676
+ inline void add_authority_slashes_if_needed();
7157
7677
 
7158
7678
  /**
7159
7679
  * To optimize performance, you may indicate how much memory to allocate
@@ -7161,10 +7681,10 @@ struct url_aggregator : url_base {
7161
7681
  */
7162
7682
  constexpr void reserve(uint32_t capacity);
7163
7683
 
7164
- ada_really_inline size_t parse_port(
7165
- 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;
7166
7686
 
7167
- 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 {
7168
7688
  return this->parse_port(view, false);
7169
7689
  }
7170
7690
 
@@ -7229,16 +7749,16 @@ struct url_aggregator : url_base {
7229
7749
  std::string_view input);
7230
7750
  [[nodiscard]] constexpr bool has_authority() const noexcept;
7231
7751
  constexpr void set_protocol_as_file();
7232
- inline void set_scheme(std::string_view new_scheme) noexcept;
7752
+ inline void set_scheme(std::string_view new_scheme);
7233
7753
  /**
7234
7754
  * Fast function to set the scheme from a view with a colon in the
7235
7755
  * buffer, does not change type.
7236
7756
  */
7237
7757
  inline void set_scheme_from_view_with_colon(
7238
- std::string_view new_scheme_with_colon) noexcept;
7239
- 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);
7240
7760
 
7241
- 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);
7242
7762
 
7243
7763
  }; // url_aggregator
7244
7764
 
@@ -8030,7 +8550,7 @@ url_aggregator::get_components() const noexcept {
8030
8550
  components.protocol_end + 2) == "//";
8031
8551
  }
8032
8552
 
8033
- inline void ada::url_aggregator::add_authority_slashes_if_needed() noexcept {
8553
+ inline void ada::url_aggregator::add_authority_slashes_if_needed() {
8034
8554
  ada_log("url_aggregator::add_authority_slashes_if_needed");
8035
8555
  ADA_ASSERT_TRUE(validate());
8036
8556
  // Protocol setter will insert `http:` to the URL. It is up to hostname setter
@@ -8067,7 +8587,7 @@ constexpr bool url_aggregator::has_non_empty_username() const noexcept {
8067
8587
 
8068
8588
  constexpr bool url_aggregator::has_non_empty_password() const noexcept {
8069
8589
  ada_log("url_aggregator::has_non_empty_password");
8070
- return components.host_start - components.username_end > 0;
8590
+ return components.host_start > components.username_end;
8071
8591
  }
8072
8592
 
8073
8593
  constexpr bool url_aggregator::has_password() const noexcept {
@@ -8139,8 +8659,8 @@ constexpr bool url_aggregator::has_port() const noexcept {
8139
8659
  return buffer;
8140
8660
  }
8141
8661
 
8142
- ada_really_inline size_t url_aggregator::parse_port(
8143
- 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) {
8144
8664
  ada_log("url_aggregator::parse_port('", view, "') ", view.size());
8145
8665
  if (!view.empty() && view[0] == '-') {
8146
8666
  ada_log("parse_port: view[0] == '0' && view.size() > 1");
@@ -8378,8 +8898,8 @@ constexpr void url_aggregator::set_protocol_as_file() {
8378
8898
  return true;
8379
8899
  }
8380
8900
 
8381
- [[nodiscard]] constexpr std::string_view url_aggregator::get_pathname()
8382
- const noexcept ada_lifetime_bound {
8901
+ [[nodiscard]] constexpr std::string_view url_aggregator::get_pathname() const
8902
+ ada_lifetime_bound {
8383
8903
  ada_log("url_aggregator::get_pathname pathname_start = ",
8384
8904
  components.pathname_start, " buffer.size() = ", buffer.size(),
8385
8905
  " components.search_start = ", components.search_start,
@@ -8398,8 +8918,7 @@ inline std::ostream &operator<<(std::ostream &out,
8398
8918
  return out << u.to_string();
8399
8919
  }
8400
8920
 
8401
- void url_aggregator::update_host_to_base_host(
8402
- const std::string_view input) noexcept {
8921
+ void url_aggregator::update_host_to_base_host(const std::string_view input) {
8403
8922
  ada_log("url_aggregator::update_host_to_base_host ", input);
8404
8923
  ADA_ASSERT_TRUE(validate());
8405
8924
  ADA_ASSERT_TRUE(!helpers::overlaps(input, buffer));
@@ -8426,7 +8945,13 @@ void url_aggregator::update_host_to_base_host(
8426
8945
  /* begin file include/ada/url_search_params.h */
8427
8946
  /**
8428
8947
  * @file url_search_params.h
8429
- * @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
8430
8955
  */
8431
8956
  #ifndef ADA_URL_SEARCH_PARAMS_H
8432
8957
  #define ADA_URL_SEARCH_PARAMS_H
@@ -8438,37 +8963,51 @@ void url_aggregator::update_host_to_base_host(
8438
8963
 
8439
8964
  namespace ada {
8440
8965
 
8966
+ /**
8967
+ * @brief Iterator types for url_search_params iteration.
8968
+ */
8441
8969
  enum class url_search_params_iter_type {
8442
- KEYS,
8443
- VALUES,
8444
- ENTRIES,
8970
+ KEYS, /**< Iterate over parameter keys only */
8971
+ VALUES, /**< Iterate over parameter values only */
8972
+ ENTRIES, /**< Iterate over key-value pairs */
8445
8973
  };
8446
8974
 
8447
8975
  template <typename T, url_search_params_iter_type Type>
8448
8976
  struct url_search_params_iter;
8449
8977
 
8978
+ /** Type alias for a key-value pair of string views. */
8450
8979
  typedef std::pair<std::string_view, std::string_view> key_value_view_pair;
8451
8980
 
8981
+ /** Iterator over search parameter keys. */
8452
8982
  using url_search_params_keys_iter =
8453
8983
  url_search_params_iter<std::string_view, url_search_params_iter_type::KEYS>;
8984
+ /** Iterator over search parameter values. */
8454
8985
  using url_search_params_values_iter =
8455
8986
  url_search_params_iter<std::string_view,
8456
8987
  url_search_params_iter_type::VALUES>;
8988
+ /** Iterator over search parameter key-value pairs. */
8457
8989
  using url_search_params_entries_iter =
8458
8990
  url_search_params_iter<key_value_view_pair,
8459
8991
  url_search_params_iter_type::ENTRIES>;
8460
8992
 
8461
8993
  /**
8462
- * We require all strings to be valid UTF-8. It is the user's responsibility to
8463
- * 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
+ *
8464
9003
  * @see https://url.spec.whatwg.org/#interface-urlsearchparams
8465
9004
  */
8466
9005
  struct url_search_params {
8467
9006
  url_search_params() = default;
8468
9007
 
8469
9008
  /**
8470
- * @see
8471
- * 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.
8472
9011
  */
8473
9012
  explicit url_search_params(const std::string_view input) {
8474
9013
  initialize(input);
@@ -8480,75 +9019,106 @@ struct url_search_params {
8480
9019
  url_search_params &operator=(const url_search_params &u) = default;
8481
9020
  ~url_search_params() = default;
8482
9021
 
9022
+ /**
9023
+ * Returns the number of key-value pairs.
9024
+ * @return The total count of parameters.
9025
+ */
8483
9026
  [[nodiscard]] inline size_t size() const noexcept;
8484
9027
 
8485
9028
  /**
8486
- * 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).
8487
9032
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-append
8488
9033
  */
8489
9034
  inline void append(std::string_view key, std::string_view value);
8490
9035
 
8491
9036
  /**
9037
+ * Removes all pairs with the given key.
9038
+ * @param key The parameter name to remove.
8492
9039
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-delete
8493
9040
  */
8494
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
+ */
8495
9048
  inline void remove(std::string_view key, std::string_view value);
8496
9049
 
8497
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.
8498
9054
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-get
8499
9055
  */
8500
9056
  inline std::optional<std::string_view> get(std::string_view key);
8501
9057
 
8502
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).
8503
9062
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-getall
8504
9063
  */
8505
9064
  inline std::vector<std::string> get_all(std::string_view key);
8506
9065
 
8507
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.
8508
9070
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-has
8509
9071
  */
8510
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
+ */
8511
9080
  inline bool has(std::string_view key, std::string_view value) noexcept;
8512
9081
 
8513
9082
  /**
8514
- * 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).
8515
9086
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-set
8516
9087
  */
8517
9088
  inline void set(std::string_view key, std::string_view value);
8518
9089
 
8519
9090
  /**
9091
+ * Sorts all key-value pairs by their keys using code unit comparison.
8520
9092
  * @see https://url.spec.whatwg.org/#dom-urlsearchparams-sort
8521
9093
  */
8522
9094
  inline void sort();
8523
9095
 
8524
9096
  /**
9097
+ * Serializes the parameters to a query string (without leading '?').
9098
+ * @return The percent-encoded query string.
8525
9099
  * @see https://url.spec.whatwg.org/#urlsearchparams-stringification-behavior
8526
9100
  */
8527
9101
  inline std::string to_string() const;
8528
9102
 
8529
9103
  /**
8530
- * Returns a simple JS-style iterator over all of the keys in this
8531
- * url_search_params. The keys in the iterator are not unique. The valid
8532
- * lifespan of the iterator is tied to the url_search_params. The iterator
8533
- * must be freed when you're done with it.
8534
- * @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.
8535
9108
  */
8536
9109
  inline url_search_params_keys_iter get_keys();
8537
9110
 
8538
9111
  /**
8539
- * Returns a simple JS-style iterator over all of the values in this
8540
- * url_search_params. The valid lifespan of the iterator is tied to the
8541
- * url_search_params. The iterator must be freed when you're done with it.
8542
- * @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.
8543
9115
  */
8544
9116
  inline url_search_params_values_iter get_values();
8545
9117
 
8546
9118
  /**
8547
- * Returns a simple JS-style iterator over all of the entries in this
8548
- * url_search_params. The entries are pairs of keys and corresponding values.
8549
- * The valid lifespan of the iterator is tied to the url_search_params. The
8550
- * iterator must be freed when you're done with it.
8551
- * @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.
8552
9122
  */
8553
9123
  inline url_search_params_entries_iter get_entries();
8554
9124
 
@@ -8585,8 +9155,13 @@ struct url_search_params {
8585
9155
  }; // url_search_params
8586
9156
 
8587
9157
  /**
8588
- * Implements a non-conventional iterator pattern that is closer in style to
8589
- * 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).
8590
9165
  *
8591
9166
  * @see https://webidl.spec.whatwg.org/#idl-iterable
8592
9167
  */
@@ -8601,10 +9176,15 @@ struct url_search_params_iter {
8601
9176
  ~url_search_params_iter() = default;
8602
9177
 
8603
9178
  /**
8604
- * 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.
8605
9181
  */
8606
9182
  inline std::optional<T> next();
8607
9183
 
9184
+ /**
9185
+ * Checks if more values are available.
9186
+ * @return `true` if `next()` will return a value, `false` if exhausted.
9187
+ */
8608
9188
  inline bool has_next() const;
8609
9189
 
8610
9190
  private:
@@ -8957,10 +9537,8 @@ url_pattern_component<regex_provider>::create_component_match_result(
8957
9537
  // says we should start from 1. This case is handled by the
8958
9538
  // std_regex_provider.
8959
9539
  for (size_t index = 0; index < exec_result.size(); index++) {
8960
- result.groups.insert({
8961
- group_name_list[index],
8962
- std::move(exec_result[index]),
8963
- });
9540
+ result.groups.emplace(group_name_list[index],
9541
+ std::move(exec_result[index]));
8964
9542
  }
8965
9543
  return result;
8966
9544
  }
@@ -9066,43 +9644,113 @@ url_pattern_component<regex_provider>::compile(
9066
9644
  return tl::unexpected(part_list.error());
9067
9645
  }
9068
9646
 
9069
- // Let (regular expression string, name list) be the result of running
9070
- // 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
9071
9689
  auto [regular_expression_string, name_list] =
9072
9690
  url_pattern_helpers::generate_regular_expression_and_name_list(*part_list,
9073
9691
  options);
9074
-
9075
- ada_log("regular expression string: ", regular_expression_string);
9076
-
9077
- // Let pattern string be the result of running generate a pattern
9078
- // string given part list and options.
9079
9692
  auto pattern_string =
9080
9693
  url_pattern_helpers::generate_pattern_string(*part_list, options);
9081
9694
 
9082
- // Let regular expression be RegExpCreate(regular expression string,
9083
- // flags). If this throws an exception, catch it, and throw a
9084
- // TypeError.
9085
9695
  std::optional<typename regex_provider::regex_type> regular_expression =
9086
9696
  regex_provider::create_instance(regular_expression_string,
9087
9697
  options.ignore_case);
9088
-
9089
9698
  if (!regular_expression) {
9090
9699
  return tl::unexpected(errors::type_error);
9091
9700
  }
9092
9701
 
9093
- // For each part of part list:
9094
- // - If part's type is "regexp", then set has regexp groups to true.
9095
- const auto has_regexp = [](const auto& part) { return part.is_regexp(); };
9096
- const bool has_regexp_groups = std::ranges::any_of(*part_list, has_regexp);
9097
-
9098
- ada_log("has regexp groups: ", has_regexp_groups);
9099
-
9100
- // Return a new component whose pattern string is pattern string, regular
9101
- // expression is regular expression, group name list is name list, and has
9102
- // regexp groups is has regexp groups.
9103
9702
  return url_pattern_component<regex_provider>(
9104
9703
  std::move(pattern_string), std::move(*regular_expression),
9105
- 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);
9106
9754
  }
9107
9755
 
9108
9756
  template <url_pattern_regex::regex_concept regex_provider>
@@ -9113,18 +9761,88 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::exec(
9113
9761
  return match(input, base_url);
9114
9762
  }
9115
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
+
9116
9779
  template <url_pattern_regex::regex_concept regex_provider>
9117
9780
  result<bool> url_pattern<regex_provider>::test(
9118
- const url_pattern_input& input, const std::string_view* base_url) {
9119
- // TODO: Optimization opportunity. Rather than returning `url_pattern_result`
9120
- // Implement a fast path just like `can_parse()` in ada_url.
9121
- // Let result be the result of match given this's associated URL pattern,
9122
- // input, and baseURL if given.
9123
- // If result is null, return false.
9124
- if (auto result = match(input, base_url); result.has_value()) {
9125
- 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);
9126
9840
  }
9127
- 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);
9128
9846
  }
9129
9847
 
9130
9848
  template <url_pattern_regex::regex_concept regex_provider>
@@ -9273,74 +9991,61 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
9273
9991
  }
9274
9992
  }
9275
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
+
9276
9997
  // Let protocolExecResult be RegExpBuiltinExec(urlPattern's protocol
9277
9998
  // component's regular expression, protocol).
9278
- auto protocol_exec_result =
9279
- regex_provider::regex_search(protocol, protocol_component.regexp);
9280
-
9999
+ auto protocol_exec_result = protocol_component.fast_match(protocol);
9281
10000
  if (!protocol_exec_result) {
9282
10001
  return std::nullopt;
9283
10002
  }
9284
10003
 
9285
10004
  // Let usernameExecResult be RegExpBuiltinExec(urlPattern's username
9286
10005
  // component's regular expression, username).
9287
- auto username_exec_result =
9288
- regex_provider::regex_search(username, username_component.regexp);
9289
-
10006
+ auto username_exec_result = username_component.fast_match(username);
9290
10007
  if (!username_exec_result) {
9291
10008
  return std::nullopt;
9292
10009
  }
9293
10010
 
9294
10011
  // Let passwordExecResult be RegExpBuiltinExec(urlPattern's password
9295
10012
  // component's regular expression, password).
9296
- auto password_exec_result =
9297
- regex_provider::regex_search(password, password_component.regexp);
9298
-
10013
+ auto password_exec_result = password_component.fast_match(password);
9299
10014
  if (!password_exec_result) {
9300
10015
  return std::nullopt;
9301
10016
  }
9302
10017
 
9303
10018
  // Let hostnameExecResult be RegExpBuiltinExec(urlPattern's hostname
9304
10019
  // component's regular expression, hostname).
9305
- auto hostname_exec_result =
9306
- regex_provider::regex_search(hostname, hostname_component.regexp);
9307
-
10020
+ auto hostname_exec_result = hostname_component.fast_match(hostname);
9308
10021
  if (!hostname_exec_result) {
9309
10022
  return std::nullopt;
9310
10023
  }
9311
10024
 
9312
10025
  // Let portExecResult be RegExpBuiltinExec(urlPattern's port component's
9313
10026
  // regular expression, port).
9314
- auto port_exec_result =
9315
- regex_provider::regex_search(port, port_component.regexp);
9316
-
10027
+ auto port_exec_result = port_component.fast_match(port);
9317
10028
  if (!port_exec_result) {
9318
10029
  return std::nullopt;
9319
10030
  }
9320
10031
 
9321
10032
  // Let pathnameExecResult be RegExpBuiltinExec(urlPattern's pathname
9322
10033
  // component's regular expression, pathname).
9323
- auto pathname_exec_result =
9324
- regex_provider::regex_search(pathname, pathname_component.regexp);
9325
-
10034
+ auto pathname_exec_result = pathname_component.fast_match(pathname);
9326
10035
  if (!pathname_exec_result) {
9327
10036
  return std::nullopt;
9328
10037
  }
9329
10038
 
9330
10039
  // Let searchExecResult be RegExpBuiltinExec(urlPattern's search component's
9331
10040
  // regular expression, search).
9332
- auto search_exec_result =
9333
- regex_provider::regex_search(search, search_component.regexp);
9334
-
10041
+ auto search_exec_result = search_component.fast_match(search);
9335
10042
  if (!search_exec_result) {
9336
10043
  return std::nullopt;
9337
10044
  }
9338
10045
 
9339
10046
  // Let hashExecResult be RegExpBuiltinExec(urlPattern's hash component's
9340
10047
  // regular expression, hash).
9341
- auto hash_exec_result =
9342
- regex_provider::regex_search(hash, hash_component.regexp);
9343
-
10048
+ auto hash_exec_result = hash_component.fast_match(hash);
9344
10049
  if (!hash_exec_result) {
9345
10050
  return std::nullopt;
9346
10051
  }
@@ -9410,7 +10115,7 @@ result<std::optional<url_pattern_result>> url_pattern<regex_provider>::match(
9410
10115
 
9411
10116
  #if ADA_INCLUDE_URL_PATTERN
9412
10117
  namespace ada::url_pattern_helpers {
9413
- #ifdef ADA_TESTING
10118
+ #if defined(ADA_TESTING) || defined(ADA_LOGGING)
9414
10119
  inline std::string to_string(token_type type) {
9415
10120
  switch (type) {
9416
10121
  case token_type::INVALID_CHAR:
@@ -9437,7 +10142,7 @@ inline std::string to_string(token_type type) {
9437
10142
  ada::unreachable();
9438
10143
  }
9439
10144
  }
9440
- #endif // ADA_TESTING
10145
+ #endif // defined(ADA_TESTING) || defined(ADA_LOGGING)
9441
10146
 
9442
10147
  template <url_pattern_regex::regex_concept regex_provider>
9443
10148
  constexpr void constructor_string_parser<regex_provider>::rewind() {
@@ -9689,8 +10394,8 @@ std::string constructor_string_parser<regex_provider>::make_component_string() {
9689
10394
  const auto component_start_input_index = component_start_token->index;
9690
10395
  // Return the code point substring from component start input index to end
9691
10396
  // index within parser's input.
9692
- return input.substr(component_start_input_index,
9693
- end_index - component_start_input_index);
10397
+ return std::string(input.substr(component_start_input_index,
10398
+ end_index - component_start_input_index));
9694
10399
  }
9695
10400
 
9696
10401
  template <url_pattern_regex::regex_concept regex_provider>
@@ -10196,13 +10901,31 @@ tl::expected<std::vector<url_pattern_part>, errors> parse_pattern_string(
10196
10901
  template <url_pattern_regex::regex_concept regex_provider>
10197
10902
  bool protocol_component_matches_special_scheme(
10198
10903
  url_pattern_component<regex_provider>& component) {
10199
- // let's avoid unnecessary copy here.
10200
- auto& regex = component.regexp;
10201
- return regex_provider::regex_match("http", regex) ||
10202
- regex_provider::regex_match("https", regex) ||
10203
- regex_provider::regex_match("ws", regex) ||
10204
- regex_provider::regex_match("wss", regex) ||
10205
- 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();
10206
10929
  }
10207
10930
 
10208
10931
  template <url_pattern_regex::regex_concept regex_provider>
@@ -10498,14 +11221,14 @@ constructor_string_parser<regex_provider>::parse(std::string_view input) {
10498
11221
  #ifndef ADA_ADA_VERSION_H
10499
11222
  #define ADA_ADA_VERSION_H
10500
11223
 
10501
- #define ADA_VERSION "3.2.5"
11224
+ #define ADA_VERSION "3.4.2"
10502
11225
 
10503
11226
  namespace ada {
10504
11227
 
10505
11228
  enum {
10506
11229
  ADA_VERSION_MAJOR = 3,
10507
- ADA_VERSION_MINOR = 2,
10508
- ADA_VERSION_REVISION = 5,
11230
+ ADA_VERSION_MINOR = 4,
11231
+ ADA_VERSION_REVISION = 2,
10509
11232
  };
10510
11233
 
10511
11234
  } // namespace ada