summaryrefslogtreecommitdiff
path: root/src/mbgl/util/url.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-10-17 16:28:31 +0200
committerKonstantin Käfer <mail@kkaefer.com>2018-10-23 12:23:40 +0200
commitc87c25cc8407c33e4d88390836a9a52a1626c19e (patch)
tree25bc1f903144ad754116037f04de8c2e5cbbec7c /src/mbgl/util/url.cpp
parent2766e64973b5f9eadf2e8a1cbbe43334e3e76d76 (diff)
downloadqtlocation-mapboxgl-c87c25cc8407c33e4d88390836a9a52a1626c19e.tar.gz
[core] don't use <sstream> and <iomanip> for string construction
Diffstat (limited to 'src/mbgl/util/url.cpp')
-rw-r--r--src/mbgl/util/url.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/mbgl/util/url.cpp b/src/mbgl/util/url.cpp
index a4263502ef..37a70007ca 100644
--- a/src/mbgl/util/url.cpp
+++ b/src/mbgl/util/url.cpp
@@ -1,8 +1,6 @@
#include <mbgl/util/url.hpp>
#include <mbgl/util/token.hpp>
-#include <iomanip>
-#include <sstream>
#include <string>
#include <cstdlib>
#include <algorithm>
@@ -24,26 +22,30 @@ inline bool isSchemeCharacter(char c) {
return isAlphaNumericCharacter(c) || c == '-' || c == '+' || c == '.';
}
+inline char toLowerHex(char c) {
+ c &= 0x0F;
+ return '0' + c + (c > 9 ? 7 : 0);
+}
+
} // namespace
namespace mbgl {
namespace util {
std::string percentEncode(const std::string& input) {
- std::ostringstream encoded;
-
- encoded.fill('0');
- encoded << std::hex;
+ std::string encoded;
for (auto c : input) {
if (isAlphaNumericCharacter(c) || c == '-' || c == '_' || c == '.' || c == '~') {
- encoded << c;
+ encoded += c;
} else {
- encoded << '%' << std::setw(2) << int(c);
+ encoded += '%';
+ encoded += toLowerHex(c >> 4);
+ encoded += toLowerHex(c);
}
}
- return encoded.str();
+ return encoded;
}
std::string percentDecode(const std::string& input) {