Decodes the argument which is assumed to be encoded in the {@code
x-www-form-urlencoded} MIME content type using the specified encoding
scheme.
'+' will be converted to space, '%' and two following hex digit
characters are converted to the equivalent byte value. All other
characters are passed through unmodified. For example "A+B+C %24%25" ->
"A B C $%".
if (enc == null) {
throw new NullPointerException();
}
// If the given encoding is an empty string throw an exception.
if (enc.length() == 0) {
throw new UnsupportedEncodingException(Msg
.getString("K00a5", "enc")); //$NON-NLS-1$ //$NON-NLS-2$
}
StringBuffer result = new StringBuffer(s.length());
ByteArrayOutputStream out = new ByteArrayOutputStream();
for (int i = 0; i < s.length();) {
char c = s.charAt(i);
if (c == '+") {
result.append(' ");
} else if (c == '%") {
out.reset();
do {
if (i + 2 >= s.length()) {
throw new IllegalArgumentException(Msg.getString(
"K01fe", i)); //$NON-NLS-1$
}
int d1 = Character.digit(s.charAt(i + 1), 16);
int d2 = Character.digit(s.charAt(i + 2), 16);
if (d1 == -1 || d2 == -1) {
throw new IllegalArgumentException(Msg.getString(
"K01ff", //$NON-NLS-1$
s.substring(i, i + 3), String.valueOf(i)));
}
out.write((byte) ((d1 << 4) + d2));
i += 3;
} while (i < s.length() && s.charAt(i) == '%");
result.append(out.toString(enc));
continue;
} else {
result.append(c);
}
i++;
}
return result.toString();