Commit 6694eb62 authored by Diogo Silva's avatar Diogo Silva
Browse files

Utility: reformated and changed C-style cast to static_cast

parent 9c47d860
...@@ -23,11 +23,11 @@ ...@@ -23,11 +23,11 @@
#include "Utility.h" #include "Utility.h"
#include <json/json.h>
#include <algorithm> #include <algorithm>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <iomanip> #include <iomanip>
#include <json/json.h>
#include <sstream> #include <sstream>
#include <unordered_map> #include <unordered_map>
...@@ -110,11 +110,10 @@ std::string Url::unescape(const std::string& value) { ...@@ -110,11 +110,10 @@ std::string Url::unescape(const std::string& value) {
for (int i = 0; i < value.length(); i++) { for (int i = 0; i < value.length(); i++) {
if (value[i] == '%') { if (value[i] == '%') {
// Failed to unescape (there is not enough digits with the % // Failed to unescape (there is not enough digits with the %
if (i >= value.length() - 2) if (i >= value.length() - 2) return "";
return "";
sscanf(value.substr(i + 1, 2).c_str(), "%x", &hex_extract); sscanf(value.substr(i + 1, 2).c_str(), "%x", &hex_extract);
unescaped << hex_extract; unescaped << hex_extract;
i += 2; // Skip the two elements that were read i += 2; // Skip the two elements that were read
} else { } else {
unescaped << value[i]; unescaped << value[i];
} }
...@@ -134,7 +133,7 @@ std::string Url::escape(const std::string& value) { ...@@ -134,7 +133,7 @@ std::string Url::escape(const std::string& value) {
continue; continue;
} }
escaped << std::uppercase; escaped << std::uppercase;
escaped << '%' << std::setw(2) << int((unsigned char) c); escaped << '%' << std::setw(2) << int(static_cast<unsigned char>(c));
escaped << std::nouppercase; escaped << std::nouppercase;
} }
return escaped.str(); return escaped.str();
...@@ -143,5 +142,5 @@ std::string Url::escape(const std::string& value) { ...@@ -143,5 +142,5 @@ std::string Url::escape(const std::string& value) {
std::string Url::escapeHeader(const std::string& header) { std::string Url::escapeHeader(const std::string& header) {
return Json::valueToQuotedString(header.c_str()); return Json::valueToQuotedString(header.c_str());
} }
} // namespace util } // namespace util
} // namespace cloudstorage } // namespace cloudstorage
...@@ -47,7 +47,7 @@ std::string address(const std::string& url, uint16_t port); ...@@ -47,7 +47,7 @@ std::string address(const std::string& url, uint16_t port);
std::string to_mime_type(const std::string& extension); std::string to_mime_type(const std::string& extension);
class Url { class Url {
public: public:
static std::string unescape(const std::string&); static std::string unescape(const std::string&);
static std::string escape(const std::string&); static std::string escape(const std::string&);
static std::string escapeHeader(const std::string&); static std::string escapeHeader(const std::string&);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment