String decodeName(String input)

Source

static String decodeName(String input) {
  var out = new StringBuffer();
  cu(String n) => const Utf8Encoder().convert(n)[0];
  mainLoop: for (var i = 0; i < input.length; i++) {
    String char = input[i];

    if (char == "%") {
      String hexA = input[i + 1];
      if ((cu(hexA) >= cu("0") && cu(hexA) <= cu("9")) ||
          (cu(hexA) >= cu("A") && cu(hexA) <= cu("F"))
      ) {
        String s = hexA;

        if (i + 2 < input.length) {
          String hexB = input[i + 2];
          if ((cu(hexB) > cu("0") && cu(hexB) <= cu("9")) ||
              (cu(hexB) >= cu("A") && cu(hexB) <= cu("F"))
          ) {
            ++i;
            s += hexB;
          }
        }

        int c = int.parse(s, radix: 16);
        out.writeCharCode(c);
        i++;
        continue;
      }
    }

    out.write(char);
  }

  return out.toString();
}