[core] Move rapidjson document creation into StyleParser
This commit is contained in:
@@ -23,9 +23,6 @@
|
||||
|
||||
#include <csscolorparser/csscolorparser.hpp>
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/error/en.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -46,15 +43,8 @@ void Style::setJSON(const std::string& json, const std::string&) {
|
||||
sources.clear();
|
||||
layers.clear();
|
||||
|
||||
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc;
|
||||
doc.Parse<0>((const char *const)json.c_str());
|
||||
if (doc.HasParseError()) {
|
||||
Log::Error(Event::ParseStyle, "Error parsing style JSON at %i: %s", doc.GetErrorOffset(), rapidjson::GetParseError_En(doc.GetParseError()));
|
||||
return;
|
||||
}
|
||||
|
||||
StyleParser parser;
|
||||
parser.parse(doc);
|
||||
parser.parse(json);
|
||||
|
||||
for (auto& source : parser.sources) {
|
||||
addSource(std::move(source));
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
#include <mapbox/geojsonvt.hpp>
|
||||
#include <mapbox/geojsonvt/convert.hpp>
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/error/en.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -96,7 +99,15 @@ void parseTileJSONMember(const JSValue& value, std::array<float, N>& target, con
|
||||
|
||||
StyleParser::~StyleParser() = default;
|
||||
|
||||
void StyleParser::parse(const JSValue& document) {
|
||||
void StyleParser::parse(const std::string& json) {
|
||||
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> document;
|
||||
document.Parse<0>((const char *const)json.c_str());
|
||||
|
||||
if (document.HasParseError()) {
|
||||
Log::Error(Event::ParseStyle, "Error parsing style JSON at %i: %s", document.GetErrorOffset(), rapidjson::GetParseError_En(document.GetParseError()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (document.HasMember("version")) {
|
||||
int version = document["version"].GetInt();
|
||||
if (version != 8) {
|
||||
|
||||
@@ -20,7 +20,7 @@ class StyleParser {
|
||||
public:
|
||||
~StyleParser();
|
||||
|
||||
void parse(const JSValue&);
|
||||
void parse(const std::string&);
|
||||
|
||||
std::string spriteURL;
|
||||
std::string glyphURL;
|
||||
|
||||
@@ -27,16 +27,11 @@ TEST_P(StyleParserTest, ParseStyle) {
|
||||
ASSERT_FALSE(infoDoc.HasParseError());
|
||||
ASSERT_TRUE(infoDoc.IsObject());
|
||||
|
||||
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> styleDoc;
|
||||
styleDoc.Parse<0>(util::read_file(base + ".style.json").c_str());
|
||||
ASSERT_FALSE(styleDoc.HasParseError());
|
||||
ASSERT_TRUE(styleDoc.IsObject());
|
||||
|
||||
FixtureLogObserver* observer = new FixtureLogObserver();
|
||||
Log::setObserver(std::unique_ptr<Log::Observer>(observer));
|
||||
|
||||
StyleParser parser;
|
||||
parser.parse(styleDoc);
|
||||
parser.parse(util::read_file(base + ".style.json"));
|
||||
|
||||
for (auto it = infoDoc.MemberBegin(), end = infoDoc.MemberEnd(); it != end; it++) {
|
||||
const std::string name { it->name.GetString(), it->name.GetStringLength() };
|
||||
|
||||
Reference in New Issue
Block a user