* java.lang.String The encoded string.
* @return java.lang.String The decoded version.
*/
static TString decode(TString s) {
TStringBuilder result = new TStringBuilder();
TByteArrayOutputStream out = new TByteArrayOutputStream();
for (int i = 0; i < s.length();) {
char c = s.charAt(i);
if (c == '%') {
out.reset();
do {
if (i + 2 >= s.length()) {
throw new TIllegalArgumentException();
}
int d1 = TCharacter.digit(s.charAt(i + 1), 16);
int d2 = TCharacter.digit(s.charAt(i + 2), 16);
if (d1 == -1 || d2 == -1) {
throw new TIllegalArgumentException();
}
out.write((byte) ((d1 << 4) + d2));
i += 3;
} while (i < s.length() && s.charAt(i) == '%');
result.append(TString.wrap(out.toString()));
continue;
}
result.append(c);
i++;
}
return TString.wrap(result.toString());
}