diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-02-23 14:48:56 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-03-28 13:53:19 +0200 |
commit | 9b39013ce4c6f98590b80ced425e0a3bcdb3f77f (patch) | |
tree | 6afaab5e122b013f45f5e8763822ccf8ebd7c4e5 /src/mbgl | |
parent | 321d820a87b37ecd4656b8c5adf585f2f00e09e2 (diff) | |
download | qtlocation-mapboxgl-9b39013ce4c6f98590b80ced425e0a3bcdb3f77f.tar.gz |
[core] Internalize rapidjson.hpp
Diffstat (limited to 'src/mbgl')
-rw-r--r-- | src/mbgl/style/conversion/geojson.cpp | 35 |
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 |