private static String decodeUtf8Component(char[] buf, String s, int from, int toExcluded) {
        int bufIdx = 0;
        for (int i = from; i < toExcluded;) {
            final int undecodedChars = toExcluded - i;
            final char c = s.charAt(i++);
            if (c != '%') {
                buf[bufIdx++] = c != '+' ? c : SPACE;
                continue;
            }

            // %x or %
            if (undecodedChars < 3) {
                buf[bufIdx++] = UNKNOWN_CHAR;
                break;
            }

            // %xx
            final int b = decodeHexByte(s.charAt(i++), s.charAt(i++));
            if (b < 0) {
                buf[bufIdx++] = UNKNOWN_CHAR;
                continue;
            }

            // 1-byte ASCII
            if ((b & 0x80) == 0) {
                buf[bufIdx++] = (char) b;
                continue;
            }

            // 2-byte UTF-8
            if ((b >>> 5) == 0b110 && (b & 0x1E) != 0) {
                if (undecodedChars < 6 || s.charAt(i) != '%') {
                    buf[bufIdx++] = UNKNOWN_CHAR;
                    i += 3;
                    continue;
                }

                final int b2 = decodeHexByte(s.charAt(i + 1), s.charAt(i + 2));
                i += 3;

                if (b2 < 0 || !isContinuation(b2)) {
                    buf[bufIdx++] = UNKNOWN_CHAR;
                    continue;
                }

                buf[bufIdx++] = (char) (((byte) b << 6) ^ (byte) b2 ^
                                        ((byte) 0xC0 << 6) ^ (byte) 0x80);
                continue;
            }

            // 3-byte UTF-8
            if ((b >>> 4) == 0b1110) {
                if (undecodedChars < 9 || s.charAt(i) != '%' || s.charAt(i + 3) != '%') {
                    buf[bufIdx++] = UNKNOWN_CHAR;
                    i += 6;
                    continue;
                }

                final int b2 = decodeHexByte(s.charAt(i + 1), s.charAt(i + 2));
                final int b3 = decodeHexByte(s.charAt(i + 4), s.charAt(i + 5));
                i += 6;

                if (b2 < 0 || b3 < 0 ||
                    (b == 0xe0 && (b2 & 0xe0) == 0x80) || !isContinuation(b2) || !isContinuation(b3)) {
                    buf[bufIdx++] = UNKNOWN_CHAR;
                    continue;
                }

                final char decoded = (char) (((byte) b << 12) ^ ((byte) b2 << 6) ^ (byte) b3 ^
                                             ((byte) 0xE0 << 12) ^ ((byte) 0x80 << 6) ^ (byte) 0x80);
                buf[bufIdx++] = !Character.isSurrogate(decoded) ? decoded : UNKNOWN_CHAR;
                continue;
            }

            // 4-byte UTF-8
            if ((b >>> 3) == 0b11110) {
                if (undecodedChars < 12 ||
                    s.charAt(i) != '%' || s.charAt(i + 3) != '%' || s.charAt(i + 6) != '%') {
                    buf[bufIdx++] = UNKNOWN_CHAR;
                    i += 9;
                    continue;
                }

                final int b2 = decodeHexByte(s.charAt(i + 1), s.charAt(i + 2));
                final int b3 = decodeHexByte(s.charAt(i + 4), s.charAt(i + 5));
                final int b4 = decodeHexByte(s.charAt(i + 7), s.charAt(i + 8));
                i += 9;

                if (b2 < 0 || b3 < 0 || b4 < 0 ||
                    !isContinuation(b2) || !isContinuation(b3) || !isContinuation(b4)) {
                    buf[bufIdx++] = UNKNOWN_CHAR;
                    continue;
                }

                final int codepoint =
                        ((byte) b << 18) ^ ((byte) b2 << 12) ^ ((byte) b3 << 6) ^ (byte) b4 ^
                        ((byte) 0xF0 << 18) ^ ((byte) 0x80 << 12) ^ ((byte) 0x80 << 6) ^ (byte) 0x80;
                buf[bufIdx++] = Character.highSurrogate(codepoint);
                buf[bufIdx++] = Character.lowSurrogate(codepoint);
                continue;
            }

            buf[bufIdx++] = UNKNOWN_CHAR;
        }

        return new String(buf, 0, bufIdx);
    }
Decodes the specified string from the index of {@code from} to the index of {@code toExcluded} if it's
<a href="https://datatracker.ietf.org/doc/html/rfc3986#section-2.1">Percent-Encoded</a>.
core/src/main/java/com/linecorp/armeria/internal/common/PercentDecoder.java