968 static constexpr std::array<std::uint8_t, 256> PASS_THROUGH{{
969 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
970 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
971 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
972 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
973 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
974 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
975 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
976 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0,
977 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
978 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
979 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
980 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
981 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
982 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
983 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
984 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
987 bool in_fragment{
false};
990 bool literal_located{
false};
991 std::pair<std::size_t, std::size_t> literal{std::string_view::npos,
992 std::string_view::npos};
993 std::size_t run_start{0};
994 for (std::size_t position = 0; position < input.size(); position += 1) {
995 const auto byte{
static_cast<unsigned char>(input[position])};
997 if (PASS_THROUGH[
byte] != 0 ||
1006 if (
byte ==
'#' && !in_fragment) {
1011 if (
byte ==
'[' ||
byte ==
']') [[unlikely]] {
1012 if (!literal_located) {
1013 literal = ip_literal_brackets(input);
1014 literal_located =
true;
1017 if (position == literal.first || position == literal.second) {
1023 output.append(input.substr(run_start, position - run_start));
1025 const auto high{
static_cast<unsigned char>((
byte >> 4U) & 0x0FU)};
1026 const auto low{
static_cast<unsigned char>(
byte & 0x0FU)};
1027 const std::array<char, 3> encoded{
1028 {
'%',
static_cast<char>(high < 10 ?
'0' + high :
'A' + high - 10),
1029 static_cast<char>(low < 10 ?
'0' + low :
'A' + low - 10)}};
1030 output.append(std::string_view{encoded.data(), encoded.size()});
1031 run_start = position + 1;
1034 output.append(input.substr(run_start));