static bool DecodeName(valtype& decoded, const std::string& encoded) { decoded.clear(); for (std::string::const_iterator i = encoded.begin(); i != encoded.end(); ++i) { switch (*i) { case '+': decoded.push_back(' '); continue; case '%': { if (i + 2 >= encoded.end()) return false; const std::string hexStr(i + 1, i + 3); i += 2; int intChar = 0; BOOST_FOREACH(char c, hexStr) { intChar <<= 4; if (c >= '0' && c <= '9') intChar += c - '0'; else { c |= (1 << 5); if (c >= 'a' && c <= 'f') intChar += c - 'a' + 10; else return false; } } decoded.push_back(static_cast<char>(intChar)); continue; } default: decoded.push_back(*i); continue; } }