summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-02-23 14:48:56 +0200
committerKonstantin Käfer <mail@kkaefer.com>2017-03-28 13:53:19 +0200
commit9b39013ce4c6f98590b80ced425e0a3bcdb3f77f (patch)
tree6afaab5e122b013f45f5e8763822ccf8ebd7c4e5 /src
parent321d820a87b37ecd4656b8c5adf585f2f00e09e2 (diff)
downloadqtlocation-mapboxgl-9b39013ce4c6f98590b80ced425e0a3bcdb3f77f.tar.gz
[core] Internalize rapidjson.hpp
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/style/conversion/geojson.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/mbgl/style/conversion/geojson.cpp b/src/mbgl/style/conversion/geojson.cpp
new file mode 100644
index 0000000000..0fba6e5b4d
--- /dev/null
+++ b/src/mbgl/style/conversion/geojson.cpp
@@ -0,0 +1,35 @@
+#include <mbgl/style/conversion/geojson.hpp>
+
+#include <mbgl/util/rapidjson.hpp>
+
+#include <string>
+#include <sstream>
+
+namespace mbgl {
+namespace style {
+namespace conversion {
+
+template <>
+optional<GeoJSON> convertGeoJSON(const std::string& string, Error& error) {
+ rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> d;
+ d.Parse(string.c_str());
+
+ if (d.HasParseError()) {
+ std::stringstream message;
+ message << d.GetErrorOffset() << " - " << rapidjson::GetParseError_En(d.GetParseError());
+ error = { message.str() };
+ return {};
+ }
+
+ optional<GeoJSON> geoJSON = conversion::convertGeoJSON<JSValue>(d, error);
+ if (!geoJSON) {
+ error = { error.message };
+ return {};
+ }
+
+ return geoJSON;
+}
+
+} // namespace conversion
+} // namespace style
+} // namespace mbgl