| 12815 | } |
| 12816 | |
| 12817 | bool url::set_port(const std::string_view input) { |
| 12818 | if (cannot_have_credentials_or_port()) { |
| 12819 | return false; |
| 12820 | } |
| 12821 | |
| 12822 | if (input.empty()) { |
| 12823 | port = std::nullopt; |
| 12824 | return true; |
| 12825 | } |
| 12826 | |
| 12827 | std::string trimmed(input); |
| 12828 | helpers::remove_ascii_tab_or_newline(trimmed); |
| 12829 | |
| 12830 | if (trimmed.empty()) { |
| 12831 | return true; |
| 12832 | } |
| 12833 | |
| 12834 | // Input should not start with a non-digit character. |
| 12835 | if (!ada::unicode::is_ascii_digit(trimmed.front())) { |
| 12836 | return false; |
| 12837 | } |
| 12838 | |
| 12839 | // Find the first non-digit character to determine the length of digits |
| 12840 | auto first_non_digit = |
| 12841 | std::ranges::find_if_not(trimmed, ada::unicode::is_ascii_digit); |
| 12842 | std::string_view digits_to_parse = |
| 12843 | std::string_view(trimmed.data(), first_non_digit - trimmed.begin()); |
| 12844 | |
| 12845 | // Revert changes if parse_port fails. |
| 12846 | std::optional<uint16_t> previous_port = port; |
| 12847 | parse_port(digits_to_parse); |
| 12848 | if (is_valid) { |
| 12849 | return true; |
| 12850 | } |
| 12851 | port = std::move(previous_port); |
| 12852 | is_valid = true; |
| 12853 | return false; |
| 12854 | } |
| 12855 | |
| 12856 | void url::set_hash(const std::string_view input) { |
| 12857 | if (input.empty()) { |
no test coverage detected