mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
cmJSONState: Allow strictMode toggle
During the refactoring to cmJSONState, some callsites will need to use "relaxed" parsing to maintain compatibility.
This commit is contained in:
+11
-6
@@ -17,7 +17,8 @@
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
|
||||
cmJSONState::cmJSONState(std::string jsonFile, Json::Value* root)
|
||||
cmJSONState::cmJSONState(std::string jsonFile, Json::Value* root,
|
||||
StrictMode strictMode)
|
||||
: Filename(std::move(jsonFile))
|
||||
{
|
||||
cmsys::ifstream fin(this->Filename.c_str(), std::ios::in | std::ios::binary);
|
||||
@@ -28,12 +29,13 @@ cmJSONState::cmJSONState(std::string jsonFile, Json::Value* root)
|
||||
// If there's a BOM, toss it.
|
||||
cmsys::FStream::ReadBOM(fin);
|
||||
|
||||
this->ReadJSONStream(fin, root);
|
||||
this->ReadJSONStream(fin, root, strictMode);
|
||||
}
|
||||
|
||||
cmJSONState::cmJSONState(std::istream& jsonIStream, Json::Value* root)
|
||||
cmJSONState::cmJSONState(std::istream& jsonIStream, Json::Value* root,
|
||||
StrictMode strictMode)
|
||||
{
|
||||
this->ReadJSONStream(jsonIStream, root);
|
||||
this->ReadJSONStream(jsonIStream, root, strictMode);
|
||||
}
|
||||
|
||||
void cmJSONState::AddError(std::string const& errMsg)
|
||||
@@ -120,7 +122,8 @@ void cmJSONState::pop_stack()
|
||||
this->parseStack.pop_back();
|
||||
}
|
||||
|
||||
void cmJSONState::ReadJSONStream(std::istream& jsonIStream, Json::Value* root)
|
||||
void cmJSONState::ReadJSONStream(std::istream& jsonIStream, Json::Value* root,
|
||||
StrictMode strictMode)
|
||||
{
|
||||
// Save the entire document.
|
||||
std::streampos inBegin = jsonIStream.tellg();
|
||||
@@ -133,7 +136,9 @@ void cmJSONState::ReadJSONStream(std::istream& jsonIStream, Json::Value* root)
|
||||
jsonIStream.seekg(inBegin);
|
||||
|
||||
Json::CharReaderBuilder builder;
|
||||
Json::CharReaderBuilder::strictMode(&builder.settings_);
|
||||
if (strictMode == StrictMode::Strict) {
|
||||
Json::CharReaderBuilder::strictMode(&builder.settings_);
|
||||
}
|
||||
std::string errMsg;
|
||||
|
||||
#if JSONCPP_VERSION_HEXA >= 0x01090600
|
||||
|
||||
+14
-3
@@ -24,9 +24,19 @@ class cmJSONState
|
||||
|
||||
public:
|
||||
using JsonPair = std::pair<std::string const, Json::Value const*>;
|
||||
|
||||
enum class StrictMode
|
||||
{
|
||||
Strict,
|
||||
Relaxed,
|
||||
};
|
||||
|
||||
cmJSONState() = default;
|
||||
cmJSONState(std::string jsonFile, Json::Value* root);
|
||||
cmJSONState(std::istream& jsonIStream, Json::Value* root);
|
||||
cmJSONState(std::string jsonFile, Json::Value* root,
|
||||
StrictMode strictMode = StrictMode::Strict);
|
||||
cmJSONState(std::istream& jsonIStream, Json::Value* root,
|
||||
StrictMode strictMode = StrictMode::Strict);
|
||||
|
||||
void AddError(std::string const& errMsg);
|
||||
void AddErrorAtValue(std::string const& errMsg, Json::Value const* value);
|
||||
void AddErrorAtOffset(std::string const& errMsg, std::ptrdiff_t offset);
|
||||
@@ -60,7 +70,8 @@ public:
|
||||
bool allowComments = false;
|
||||
|
||||
private:
|
||||
void ReadJSONStream(std::istream& jsonIStream, Json::Value* root);
|
||||
void ReadJSONStream(std::istream& jsonIStream, Json::Value* root,
|
||||
StrictMode strictMode);
|
||||
std::string GetJsonContext(Location loc);
|
||||
Location LocateInDocument(ptrdiff_t offset);
|
||||
std::string Filename;
|
||||
|
||||
Reference in New Issue
Block a user