| 14073 | } |
| 14074 | |
| 14075 | inline void url_aggregator::set_scheme(std::string_view new_scheme) noexcept { |
| 14076 | ada_log("url_aggregator::set_scheme ", new_scheme); |
| 14077 | ADA_ASSERT_TRUE(validate()); |
| 14078 | ADA_ASSERT_TRUE(new_scheme.empty() || new_scheme.back() != ':'); |
| 14079 | // next line could overflow but unsigned arithmetic has well-defined |
| 14080 | // overflows. |
| 14081 | uint32_t new_difference = |
| 14082 | uint32_t(new_scheme.size()) - components.protocol_end + 1; |
| 14083 | |
| 14084 | type = ada::scheme::get_scheme_type(new_scheme); |
| 14085 | if (buffer.empty()) { |
| 14086 | buffer.append(helpers::concat(new_scheme, ":")); |
| 14087 | } else { |
| 14088 | buffer.erase(0, components.protocol_end); |
| 14089 | buffer.insert(0, helpers::concat(new_scheme, ":")); |
| 14090 | } |
| 14091 | components.protocol_end = uint32_t(new_scheme.size() + 1); |
| 14092 | |
| 14093 | // Update the rest of the components. |
| 14094 | components.username_end += new_difference; |
| 14095 | components.host_start += new_difference; |
| 14096 | components.host_end += new_difference; |
| 14097 | components.pathname_start += new_difference; |
| 14098 | if (components.search_start != url_components::omitted) { |
| 14099 | components.search_start += new_difference; |
| 14100 | } |
| 14101 | if (components.hash_start != url_components::omitted) { |
| 14102 | components.hash_start += new_difference; |
| 14103 | } |
| 14104 | ADA_ASSERT_TRUE(validate()); |
| 14105 | } |
| 14106 | |
| 14107 | bool url_aggregator::set_protocol(const std::string_view input) { |
| 14108 | ada_log("url_aggregator::set_protocol ", input); |