[core] don't use <sstream> and <iomanip> for string construction
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#include <mbgl/programs/program_parameters.hpp>
|
||||
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <mbgl/util/string.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -9,14 +7,15 @@ ProgramParameters::ProgramParameters(const float pixelRatio,
|
||||
const bool overdraw,
|
||||
optional<std::string> cacheDir_)
|
||||
: defines([&] {
|
||||
std::ostringstream ss;
|
||||
ss.imbue(std::locale("C"));
|
||||
ss.setf(std::ios_base::showpoint);
|
||||
ss << "#define DEVICE_PIXEL_RATIO " << pixelRatio << std::endl;
|
||||
std::string result;
|
||||
result.reserve(32);
|
||||
result += "#define DEVICE_PIXEL_RATIO ";
|
||||
result += util::toString(pixelRatio, true);
|
||||
result += "\n";
|
||||
if (overdraw) {
|
||||
ss << "#define OVERDRAW_INSPECTOR" << std::endl;
|
||||
result += "#define OVERDRAW_INSPECTOR\n";
|
||||
}
|
||||
return ss.str();
|
||||
return result;
|
||||
}()),
|
||||
cacheDir(std::move(cacheDir_)) {
|
||||
}
|
||||
@@ -29,10 +28,15 @@ optional<std::string> ProgramParameters::cachePath(const char* name) const {
|
||||
if (!cacheDir) {
|
||||
return {};
|
||||
} else {
|
||||
std::ostringstream ss;
|
||||
ss << *cacheDir << "/com.mapbox.gl.shader." << name << "." << std::setfill('0')
|
||||
<< std::setw(sizeof(size_t) * 2) << std::hex << std::hash<std::string>()(defines) << ".pbf";
|
||||
return ss.str();
|
||||
std::string result;
|
||||
result.reserve(cacheDir->length() + 64);
|
||||
result += *cacheDir;
|
||||
result += "/com.mapbox.gl.shader.";
|
||||
result += name;
|
||||
result += ".";
|
||||
result += util::toHex(std::hash<std::string>()(defines));
|
||||
result += ".pbf";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#include <mbgl/shaders/shaders.hpp>
|
||||
#include <mbgl/shaders/preludes.hpp>
|
||||
#include <mbgl/programs/program_parameters.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
namespace mbgl {
|
||||
namespace shaders {
|
||||
@@ -18,12 +17,12 @@ std::string vertexSource(const ProgramParameters& parameters, const char* vertex
|
||||
}
|
||||
|
||||
std::string programIdentifier(const std::string& vertexSource, const std::string& fragmentSource) {
|
||||
std::ostringstream ss;
|
||||
ss << std::setfill('0') << std::setw(sizeof(size_t) * 2) << std::hex;
|
||||
ss << std::hash<std::string>()(vertexSource);
|
||||
ss << std::hash<std::string>()(fragmentSource);
|
||||
ss << "v2";
|
||||
return ss.str();
|
||||
std::string result;
|
||||
result.reserve(sizeof(size_t) * 2 * 2 + 2 + 1);
|
||||
result += util::toHex(std::hash<std::string>()(vertexSource));
|
||||
result += util::toHex(std::hash<std::string>()(fragmentSource));
|
||||
result += "v2";
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace shaders
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -6,6 +6,14 @@
|
||||
|
||||
using namespace mbgl::util;
|
||||
|
||||
TEST(URL, percentEncode) {
|
||||
EXPECT_EQ("%22%C3%A9nc%C3%B8%C3%B0ing%22", percentEncode("\"éncøðing\""));
|
||||
}
|
||||
|
||||
TEST(URL, percentDecode) {
|
||||
EXPECT_EQ("\"éncøðing\"", percentDecode("%22%C3%A9nc%C3%B8%C3%B0ing%22"));
|
||||
}
|
||||
|
||||
TEST(URL, Scheme) {
|
||||
EXPECT_EQ(URL::Segment({ 0, 4 }), URL("http://example.com/test?query=foo").scheme);
|
||||
EXPECT_EQ(URL::Segment({ 0, 4 }), URL("http://127.0.0.1:8080/test?query=foo").scheme);
|
||||
|
||||
Reference in New Issue
Block a user