diff --git a/include/ada/url_pattern.h b/include/ada/url_pattern.h index 6ff7bde7f..13466dd62 100644 --- a/include/ada/url_pattern.h +++ b/include/ada/url_pattern.h @@ -125,7 +125,21 @@ enum class url_pattern_part_modifier : uint8_t { }; // @see https://urlpattern.spec.whatwg.org/#part -struct url_pattern_part { +class url_pattern_part { + public: + url_pattern_part(url_pattern_part_type _type, std::string&& _value, + url_pattern_part_modifier _modifier) + : type(_type), value(_value), modifier(_modifier) {} + + url_pattern_part(url_pattern_part_type _type, std::string&& _value, + url_pattern_part_modifier _modifier, std::string&& _name, + std::string&& _prefix, std::string&& _suffix) + : type(_type), + value(_value), + modifier(_modifier), + name(_name), + prefix(_prefix), + suffix(_suffix) {} // A part has an associated type, a string, which must be set upon creation. url_pattern_part_type type; // A part has an associated value, a string, which must be set upon creation. diff --git a/include/ada/url_pattern_helpers-inl.h b/include/ada/url_pattern_helpers-inl.h index 370a44a19..def6a174d 100644 --- a/include/ada/url_pattern_helpers-inl.h +++ b/include/ada/url_pattern_helpers-inl.h @@ -519,11 +519,10 @@ url_pattern_parser::maybe_add_part_from_the_pending_fixed_value() { pending_fixed_value.clear(); // Let part be a new part whose type is "fixed-text", value is encoded value, // and modifier is "none". - url_pattern_part part{.type = url_pattern_part_type::FIXED_TEXT, - .value = std::move(*encoded_value), - .modifier = url_pattern_part_modifier::NONE}; // Append part to parser’s part list. - parts.push_back(std::move(part)); + parts.emplace_back(url_pattern_part_type::FIXED_TEXT, + std::move(*encoded_value), + url_pattern_part_modifier::NONE); return std::nullopt; } @@ -574,11 +573,9 @@ std::optional url_pattern_parser::add_part( } // Let part be a new part whose type is "fixed-text", value is encoded // value, and modifier is modifier. - url_pattern_part part{.type = url_pattern_part_type::FIXED_TEXT, - .value = std::move(*encoded_value), - .modifier = modifier}; // Append part to parser’s part list. - parts.push_back(std::move(part)); + parts.emplace_back(url_pattern_part_type::FIXED_TEXT, + std::move(*encoded_value), modifier); return std::nullopt; } // Let regexp value be the empty string. @@ -639,14 +636,9 @@ std::optional url_pattern_parser::add_part( // Let part be a new part whose type is type, value is regexp value, // modifier is modifier, name is name, prefix is encoded prefix, and suffix // is encoded suffix. - auto part = url_pattern_part{.type = type, - .value = std::move(regexp_value), - .modifier = modifier, - .name = std::move(name), - .prefix = std::move(*encoded_prefix), - .suffix = std::move(*encoded_suffix)}; // Append part to parser’s part list. - parts.push_back(std::move(part)); + parts.emplace_back(type, std::move(regexp_value), modifier, std::move(name), + std::move(*encoded_prefix), std::move(*encoded_suffix)); return std::nullopt; } diff --git a/src/url_pattern.cpp b/src/url_pattern.cpp index e370b10c3..7f1e80187 100644 --- a/src/url_pattern.cpp +++ b/src/url_pattern.cpp @@ -549,7 +549,7 @@ generate_regular_expression_and_name_list( std::string result = "^"; // Let name list be a new list - std::vector name_list; + std::vector name_list{}; const std::string full_wildcard_regexp_value = ".*"; // For each part of part list: