コード例 #1
0
ファイル: percent_encoding.cpp プロジェクト: includeos/uri
std::string uri::decode(const std::experimental::string_view input) {
  std::string res;
  res.reserve(input.size());
  for (auto it = input.cbegin(), e = input.cend(); it not_eq e; ++it) {
    if (*it == '%') {

      if (++it >= e) return decode_error(std::move(res));
      const uint8_t nibble1 = (*it);

      if (++it >= e) return decode_error(std::move(res));
      const uint8_t nibble2 = (*it);

      res += static_cast<char>(from_hex(nibble1, nibble2));

    } else {
      if (is_reserved(*it) or is_unreserved(*it))
        res += *it;
      else
        return decode_error(std::move(res));
    }
  }
  return res;
}