974 static constexpr std::array<std::uint8_t, 256> PASS_THROUGH{{
975 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
976 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
977 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
978 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
979 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
980 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
981 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
982 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 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,
985 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
986 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
987 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
988 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
989 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
990 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
993 bool in_fragment{
false};
996 bool literal_located{
false};
997 std::pair<std::size_t, std::size_t> literal{std::string_view::npos,
998 std::string_view::npos};
999 std::size_t run_start{0};
1000 for (std::size_t position = 0; position < input.size(); position += 1) {
1001 const auto byte{
static_cast<unsigned char>(input[position])};
1003 if (PASS_THROUGH[
byte] != 0 ||
1012 if (
byte ==
'#' && !in_fragment) {
1017 if (
byte ==
'[' ||
byte ==
']') [[unlikely]] {
1018 if (!literal_located) {
1019 literal = ip_literal_brackets(input);
1020 literal_located =
true;
1023 if (position == literal.first || position == literal.second) {
1029 output.append(input.substr(run_start, position - run_start));
1031 const auto high{
static_cast<unsigned char>((
byte >> 4U) & 0x0FU)};
1032 const auto low{
static_cast<unsigned char>(
byte & 0x0FU)};
1033 const std::array<char, 3> encoded{
1034 {
'%',
static_cast<char>(high < 10 ?
'0' + high :
'A' + high - 10),
1035 static_cast<char>(low < 10 ?
'0' + low :
'A' + low - 10)}};
1036 output.append(std::string_view{encoded.data(), encoded.size()});
1037 run_start = position + 1;
1040 output.append(input.substr(run_start));