Added Encodings::Hex::decode
This commit is contained in:
parent
3ab582d60b
commit
228a03a004
2 changed files with 13 additions and 0 deletions
|
@ -102,6 +102,16 @@ namespace Encodings {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Decodes a hex-encoded std::string to a raw binary std::string.
|
||||||
|
std::string Hex::decode(const std::string & in){
|
||||||
|
std::string ret(in.size()/2, '\000');
|
||||||
|
for (size_t i = 0; i < in.size(); ++i){
|
||||||
|
char c = in[i];
|
||||||
|
ret[i>>1] |= ((c&15) + (((c&64)>>6) | ((c&64)>>3))) << ((~i&1) << 2);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/// urlencodes std::string data, leaving only the characters A-Za-z0-9~!&()' alone.
|
/// urlencodes std::string data, leaving only the characters A-Za-z0-9~!&()' alone.
|
||||||
std::string URL::encode(const std::string & c){
|
std::string URL::encode(const std::string & c){
|
||||||
std::string escaped = "";
|
std::string escaped = "";
|
||||||
|
|
|
@ -33,6 +33,9 @@ namespace Encodings {
|
||||||
}
|
}
|
||||||
/// Encodes a single character as two hex digits in string form.
|
/// Encodes a single character as two hex digits in string form.
|
||||||
static std::string chr(char dec);
|
static std::string chr(char dec);
|
||||||
|
|
||||||
|
/// Decodes a hex-encoded std::string to a raw binary std::string.
|
||||||
|
static std::string decode(const std::string & in);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue