#pragma once

String uriDecode(const String& input) {
    String decoded = "";
    char a, b;
    for (size_t i = 0; i < input.length(); i++) {
        if ((input[i] == '%') && (i + 2 < input.length()) &&
            ((a = input[i + 1]) && (b = input[i + 2])) &&
            isxdigit(a) && isxdigit(b)) {
            a = (a <= '9') ? a - '0' : (toupper(a) - 'A' + 10);
            b = (b <= '9') ? b - '0' : (toupper(b) - 'A' + 10);
            decoded += char((a << 4) | b);
            i += 2;
        } else if (input[i] == '+') {
            decoded += ' ';
        } else {
            decoded += input[i];
        }
    }
    return decoded;
}