/** * Converts a hex encoded value to its binary value * @param from - buffer containing the input data * @param len - the size of from * @param to - the output buffer !!! must have at least len/2 allocated memory * @returns the written length */ int base16_to_bin(char *from, int len, char *to) { int i, j; for (i = 0, j = 0; j < len; i++, j += 2) { to[i] = (unsigned char) (HEX_DIGIT(from[j]) << 4 | HEX_DIGIT(from[j+1])); } return i; }
void URLParams::DecodeString(const nsACString& aInput, nsAString& aOutput) { nsACString::const_iterator start, end; aInput.BeginReading(start); aInput.EndReading(end); nsCString unescaped; while (start != end) { // replace '+' with U+0020 if (*start == '+') { unescaped.Append(' '); ++start; continue; } // Percent decode algorithm if (*start == '%') { nsACString::const_iterator first(start); ++first; nsACString::const_iterator second(first); ++second; #define ASCII_HEX_DIGIT( x ) \ ((x >= 0x41 && x <= 0x46) || \ (x >= 0x61 && x <= 0x66) || \ (x >= 0x30 && x <= 0x39)) #define HEX_DIGIT( x ) \ (*x >= 0x30 && *x <= 0x39 \ ? *x - 0x30 \ : (*x >= 0x41 && *x <= 0x46 \ ? *x - 0x37 \ : *x - 0x57)) if (first != end && second != end && ASCII_HEX_DIGIT(*first) && ASCII_HEX_DIGIT(*second)) { unescaped.Append(HEX_DIGIT(first) * 16 + HEX_DIGIT(second)); start = ++second; continue; } else { unescaped.Append('%'); ++start; continue; } } unescaped.Append(*start); ++start; } ConvertString(unescaped, aOutput); }