
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost- bounces@lists.boost.org] On Behalf Of Eric Niebler Sent: Wednesday, June 23, 2010 7:49 PM To: boost@lists.boost.org Subject: Re: [boost] [RFC] string inserter/extractor "q u o t i n g"
Do you think uri escaping (reserved chars are replaced with %hexdigit hexdigit) should be supported as well?
By this utility? No. By another string algorithm? Yeah, maybe. Could be useful for both filesystem and asio. I am not sure how this can be useful for filesystem.
What's your use case? Uri parsing. I found out that it was easier to implement this unescaping with a function rather than with a grammar parser. I am attaching an implementation of uri_unescape().
BR, Dmitry std::string uri_unescape(std::string const& s) { std::string result; result.reserve(s.size()); size_t cur = 0; size_t prev = 0; size_t const npos = std::string::npos; while ((cur = s.find('%', prev)) != npos) { if (s.size() < cur + 3 || !isxdigit(s[cur + 1]) || !isxdigit(s[cur + 2])) return std::string(); result += s.substr(prev, cur - prev); char b[3]; b[0] = s[cur + 1]; b[1] = s[cur + 2]; b[2] = 0; char const c = static_cast<char>(strtoul(b, 0, 16)); result += c; prev = cur + 3; } result += s.substr(prev); return result; }