diff options
-rw-r--r-- | bin/offline.cpp | 21 | ||||
-rw-r--r-- | cmake/core-files.txt | 1 | ||||
-rw-r--r-- | include/mbgl/storage/response.hpp | 2 | ||||
-rw-r--r-- | platform/android/src/conversion/constant.cpp | 17 | ||||
-rw-r--r-- | platform/node/test/js/map.test.js | 4 | ||||
-rw-r--r-- | src/mbgl/algorithm/generate_clip_ids.cpp | 1 | ||||
-rw-r--r-- | src/mbgl/geometry/line_atlas.cpp | 1 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_raster_dem_source.cpp | 1 | ||||
-rw-r--r-- | src/mbgl/sprite/sprite_parser.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/storage/response.cpp | 25 | ||||
-rw-r--r-- | src/mbgl/style/conversion/json.hpp | 5 | ||||
-rw-r--r-- | src/mbgl/style/parser.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/text/shaping.cpp | 1 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/util/mapbox.cpp | 1 | ||||
-rw-r--r-- | src/mbgl/util/rapidjson.cpp | 13 | ||||
-rw-r--r-- | src/mbgl/util/rapidjson.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/util/stopwatch.cpp | 1 | ||||
-rw-r--r-- | src/mbgl/util/stopwatch.hpp | 3 | ||||
-rw-r--r-- | test/map/map.test.cpp | 2 | ||||
-rw-r--r-- | test/style/source.test.cpp | 2 |
21 files changed, 61 insertions, 56 deletions
diff --git a/bin/offline.cpp b/bin/offline.cpp index 5123e7b926..0d0fe57281 100644 --- a/bin/offline.cpp +++ b/bin/offline.cpp @@ -53,6 +53,27 @@ mapbox::geometry::geometry<double> parseGeometry(const std::string& json) { }); } +std::ostream& operator<<(std::ostream& os, mbgl::Response::Error::Reason r) { + switch (r) { + case mbgl::Response::Error::Reason::Success: + return os << "Response::Error::Reason::Success"; + case mbgl::Response::Error::Reason::NotFound: + return os << "Response::Error::Reason::NotFound"; + case mbgl::Response::Error::Reason::Server: + return os << "Response::Error::Reason::Server"; + case mbgl::Response::Error::Reason::Connection: + return os << "Response::Error::Reason::Connection"; + case mbgl::Response::Error::Reason::RateLimit: + return os << "Response::Error::Reason::RateLimit"; + case mbgl::Response::Error::Reason::Other: + return os << "Response::Error::Reason::Other"; + } + + // The above switch is exhaustive, but placate GCC nonetheless: + assert(false); + return os; +} + int main(int argc, char *argv[]) { args::ArgumentParser argumentParser("Mapbox GL offline tool"); args::HelpFlag helpFlag(argumentParser, "help", "Display this help menu", {'h', "help"}); diff --git a/cmake/core-files.txt b/cmake/core-files.txt index 9e83ceb66c..e7fd7d81c2 100644 --- a/cmake/core-files.txt +++ b/cmake/core-files.txt @@ -752,6 +752,7 @@ src/mbgl/util/math.hpp src/mbgl/util/offscreen_texture.cpp src/mbgl/util/offscreen_texture.hpp src/mbgl/util/premultiply.cpp +src/mbgl/util/rapidjson.cpp src/mbgl/util/rapidjson.hpp src/mbgl/util/rect.hpp src/mbgl/util/std.hpp diff --git a/include/mbgl/storage/response.hpp b/include/mbgl/storage/response.hpp index 508400141b..07b059e435 100644 --- a/include/mbgl/storage/response.hpp +++ b/include/mbgl/storage/response.hpp @@ -69,6 +69,4 @@ public: Error(Reason, std::string = "", optional<Timestamp> = {}); }; -std::ostream& operator<<(std::ostream&, Response::Error::Reason); - } // namespace mbgl diff --git a/platform/android/src/conversion/constant.cpp b/platform/android/src/conversion/constant.cpp index eaff434dbc..a609dc7c60 100644 --- a/platform/android/src/conversion/constant.cpp +++ b/platform/android/src/conversion/constant.cpp @@ -1,7 +1,7 @@ #include "constant.hpp" #include "collection.hpp" -#include <sstream> +#include <mbgl/util/string.hpp> namespace mbgl { namespace android { @@ -24,9 +24,18 @@ Result<jni::Local<jni::Object<>>> Converter<jni::Local<jni::Object<>>, std::stri } Result<jni::Local<jni::Object<>>> Converter<jni::Local<jni::Object<>>, Color>::operator()(jni::JNIEnv& env, const Color& value) const { - std::stringstream sstream; - sstream << "rgba(" << value.r << ", " << value.g << ", " << value.b << ", " << value.a << ")"; - return jni::Make<jni::String>(env, sstream.str()); + std::string result; + result.reserve(32); + result += "rgba("; + result += util::toString(value.r); + result += ", "; + result += util::toString(value.g); + result += ", "; + result += util::toString(value.b); + result += ", "; + result += util::toString(value.a); + result += ")"; + return jni::Make<jni::String>(env, result); } Result<jni::Local<jni::Object<>>> Converter<jni::Local<jni::Object<>>, style::expression::Formatted>::operator()(jni::JNIEnv& env, const style::expression::Formatted& value) const { diff --git a/platform/node/test/js/map.test.js b/platform/node/test/js/map.test.js index 4a71d72046..b21c1519e3 100644 --- a/platform/node/test/js/map.test.js +++ b/platform/node/test/js/map.test.js @@ -317,7 +317,7 @@ test('Map', function(t) { t.throws(function() { map.load('foo bar'); - }, /Failed to parse style: 1 - Invalid value./); + }, /Failed to parse style: Invalid value. at offset 1/); t.throws(function() { map.load('""'); @@ -349,7 +349,7 @@ test('Map', function(t) { t.throws(function() { map.load('invalid'); - }, /Failed to parse style: 0 - Invalid value./); + }, /Failed to parse style: Invalid value. at offset 0/); }); t.test('accepts an empty stylesheet string', function(t) { diff --git a/src/mbgl/algorithm/generate_clip_ids.cpp b/src/mbgl/algorithm/generate_clip_ids.cpp index 287d2a408e..aefa55b929 100644 --- a/src/mbgl/algorithm/generate_clip_ids.cpp +++ b/src/mbgl/algorithm/generate_clip_ids.cpp @@ -7,7 +7,6 @@ #include <vector> #include <bitset> #include <cassert> -#include <iostream> #include <algorithm> #include <iterator> diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp index ba14655cab..1bd6f987e1 100644 --- a/src/mbgl/geometry/line_atlas.cpp +++ b/src/mbgl/geometry/line_atlas.cpp @@ -4,7 +4,6 @@ #include <mbgl/util/platform.hpp> #include <mbgl/util/hash.hpp> -#include <sstream> #include <cmath> namespace mbgl { diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.cpp b/src/mbgl/renderer/sources/render_raster_dem_source.cpp index fbf2c09d19..2283a0e788 100644 --- a/src/mbgl/renderer/sources/render_raster_dem_source.cpp +++ b/src/mbgl/renderer/sources/render_raster_dem_source.cpp @@ -4,7 +4,6 @@ #include <mbgl/algorithm/update_tile_masks.hpp> #include <mbgl/geometry/dem_data.hpp> #include <mbgl/renderer/buckets/hillshade_bucket.hpp> -#include <iostream> namespace mbgl { diff --git a/src/mbgl/sprite/sprite_parser.cpp b/src/mbgl/sprite/sprite_parser.cpp index 1a36e3e990..99e2b0c8ca 100644 --- a/src/mbgl/sprite/sprite_parser.cpp +++ b/src/mbgl/sprite/sprite_parser.cpp @@ -9,7 +9,6 @@ #include <cmath> #include <limits> -#include <sstream> namespace mbgl { @@ -91,9 +90,7 @@ std::vector<std::unique_ptr<style::Image>> parseSprite(const std::string& encode JSDocument doc; doc.Parse<0>(json.c_str()); if (doc.HasParseError()) { - std::stringstream message; - message << "Failed to parse JSON: " << rapidjson::GetParseError_En(doc.GetParseError()) << " at offset " << doc.GetErrorOffset(); - throw std::runtime_error(message.str()); + throw std::runtime_error("Failed to parse JSON: " + formatJSONParseError(doc)); } else if (!doc.IsObject()) { throw std::runtime_error("Sprite JSON root must be an object"); } else { diff --git a/src/mbgl/storage/response.cpp b/src/mbgl/storage/response.cpp index 222f55db84..ba075c3262 100644 --- a/src/mbgl/storage/response.cpp +++ b/src/mbgl/storage/response.cpp @@ -1,8 +1,4 @@ #include <mbgl/storage/response.hpp> -#include <mbgl/util/chrono.hpp> - -#include <iostream> -#include <cassert> namespace mbgl { @@ -26,25 +22,4 @@ Response::Error::Error(Reason reason_, std::string message_, optional<Timestamp> : reason(reason_), message(std::move(message_)), retryAfter(std::move(retryAfter_)) { } -std::ostream& operator<<(std::ostream& os, Response::Error::Reason r) { - switch (r) { - case Response::Error::Reason::Success: - return os << "Response::Error::Reason::Success"; - case Response::Error::Reason::NotFound: - return os << "Response::Error::Reason::NotFound"; - case Response::Error::Reason::Server: - return os << "Response::Error::Reason::Server"; - case Response::Error::Reason::Connection: - return os << "Response::Error::Reason::Connection"; - case Response::Error::Reason::RateLimit: - return os << "Response::Error::Reason::RateLimit"; - case Response::Error::Reason::Other: - return os << "Response::Error::Reason::Other"; - } - - // The above switch is exhaustive, but placate GCC nonetheless: - assert(false); - return os; -} - } // namespace mbgl diff --git a/src/mbgl/style/conversion/json.hpp b/src/mbgl/style/conversion/json.hpp index 3a7bf2b557..503f60a382 100644 --- a/src/mbgl/style/conversion/json.hpp +++ b/src/mbgl/style/conversion/json.hpp @@ -4,7 +4,6 @@ #include <mbgl/style/rapidjson_conversion.hpp> #include <string> -#include <sstream> namespace mbgl { namespace style { @@ -16,9 +15,7 @@ optional<T> convertJSON(const std::string& json, Error& error, Args&&...args) { document.Parse<0>(json.c_str()); if (document.HasParseError()) { - std::stringstream message; - message << document.GetErrorOffset() << " - " << rapidjson::GetParseError_En(document.GetParseError()); - error = { message.str() }; + error = { formatJSONParseError(document) }; return {}; } diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp index 114a666f08..77cf23bad0 100644 --- a/src/mbgl/style/parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -18,7 +18,6 @@ #include <algorithm> #include <set> -#include <sstream> namespace mbgl { namespace style { @@ -30,11 +29,7 @@ StyleParseResult Parser::parse(const std::string& json) { document.Parse<0>(json.c_str()); if (document.HasParseError()) { - std::stringstream message; - message << document.GetErrorOffset() << " - " - << rapidjson::GetParseError_En(document.GetParseError()); - - return std::make_exception_ptr(std::runtime_error(message.str())); + return std::make_exception_ptr(std::runtime_error(formatJSONParseError(document))); } if (!document.IsObject()) { diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp index 6d10085ad3..3a6335955b 100644 --- a/src/mbgl/text/shaping.cpp +++ b/src/mbgl/text/shaping.cpp @@ -5,6 +5,7 @@ #include <mbgl/text/bidi.hpp> #include <algorithm> +#include <list> #include <cmath> namespace mbgl { diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index 9743cd3f7d..80b3e970bd 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -19,8 +19,6 @@ #include <mbgl/util/logging.hpp> #include <mbgl/actor/scheduler.hpp> -#include <iostream> - namespace mbgl { using namespace style; diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp index b823b727a7..6c36c152cd 100644 --- a/src/mbgl/util/mapbox.cpp +++ b/src/mbgl/util/mapbox.cpp @@ -6,7 +6,6 @@ #include <stdexcept> #include <vector> -#include <iostream> #include <cstring> namespace { diff --git a/src/mbgl/util/rapidjson.cpp b/src/mbgl/util/rapidjson.cpp new file mode 100644 index 0000000000..32a3c0b929 --- /dev/null +++ b/src/mbgl/util/rapidjson.cpp @@ -0,0 +1,13 @@ +#include <mbgl/util/rapidjson.hpp> +#include <mbgl/util/string.hpp> + +namespace mbgl { + +std::string formatJSONParseError(const JSDocument& doc) { + return std::string{ rapidjson::GetParseError_En(doc.GetParseError()) } + " at offset " + + util::toString(doc.GetErrorOffset()); +} + +} // namespace mbgl + + diff --git a/src/mbgl/util/rapidjson.hpp b/src/mbgl/util/rapidjson.hpp index 7262e8545c..2fb2a07c9f 100644 --- a/src/mbgl/util/rapidjson.hpp +++ b/src/mbgl/util/rapidjson.hpp @@ -8,4 +8,6 @@ namespace mbgl { using JSDocument = rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator>; using JSValue = rapidjson::GenericValue<rapidjson::UTF8<>, rapidjson::CrtAllocator>; +std::string formatJSONParseError(const JSDocument&); + } // namespace mbgl diff --git a/src/mbgl/util/stopwatch.cpp b/src/mbgl/util/stopwatch.cpp index 3883d8535f..6db9da07e1 100644 --- a/src/mbgl/util/stopwatch.cpp +++ b/src/mbgl/util/stopwatch.cpp @@ -4,7 +4,6 @@ #include <mbgl/util/chrono.hpp> #include <mbgl/util/logging.hpp> -#include <iostream> #include <atomic> namespace mbgl { diff --git a/src/mbgl/util/stopwatch.hpp b/src/mbgl/util/stopwatch.hpp index 0c91342a57..daa313f702 100644 --- a/src/mbgl/util/stopwatch.hpp +++ b/src/mbgl/util/stopwatch.hpp @@ -4,7 +4,10 @@ #include <mbgl/util/chrono.hpp> #include <string> + +#ifdef MBGL_TIMING #include <sstream> +#endif namespace mbgl { namespace util { diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index cd15c5c278..a21f9c7e75 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -237,7 +237,7 @@ TEST(Map, SetStyleInvalidJSON) { auto observer = Log::removeObserver(); auto flo = static_cast<FixtureLogObserver*>(observer.get()); EXPECT_EQ(1u, flo->count({ EventSeverity::Error, Event::ParseStyle, -1, - "Failed to parse style: 0 - Invalid value." })); + "Failed to parse style: Invalid value. at offset 0" })); auto unchecked = flo->unchecked(); EXPECT_TRUE(unchecked.empty()) << unchecked; } diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp index 6cb01146f6..abd4350231 100644 --- a/test/style/source.test.cpp +++ b/test/style/source.test.cpp @@ -127,7 +127,7 @@ TEST(Source, LoadingCorrupt) { test.styleObserver.sourceError = [&] (Source& source, std::exception_ptr error) { EXPECT_EQ("source", source.getID()); - EXPECT_EQ("0 - Invalid value.", util::toString(error)); + EXPECT_EQ("Invalid value. at offset 0", util::toString(error)); test.end(); }; |