mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
Merge topic 'json-bom'
afa4e5f749cmJSONState: Move BOM handling to shared helper18a335e062cmPListParser: Hand JSONState a seekable stream Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !12466
This commit is contained in:
@@ -26,8 +26,6 @@ cmJSONState::cmJSONState(std::string jsonFile, Json::Value* root,
|
||||
this->AddError(cmStrCat("File not found: ", this->Filename));
|
||||
return;
|
||||
}
|
||||
// If there's a BOM, toss it.
|
||||
cmsys::FStream::ReadBOM(fin);
|
||||
|
||||
this->ReadJSONStream(fin, root, strictMode);
|
||||
}
|
||||
@@ -127,6 +125,9 @@ void cmJSONState::pop_stack()
|
||||
void cmJSONState::ReadJSONStream(std::istream& jsonIStream, Json::Value* root,
|
||||
StrictMode strictMode)
|
||||
{
|
||||
// If there's a BOM, toss it.
|
||||
cmsys::FStream::ReadBOM(jsonIStream);
|
||||
|
||||
// Save the entire document.
|
||||
std::streampos inBegin = jsonIStream.tellg();
|
||||
this->doc = std::string(std::istreambuf_iterator<char>(jsonIStream),
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
file LICENSE.rst or https://cmake.org/licensing for details. */
|
||||
#include "cmPlistParser.h"
|
||||
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm3p/json/value.h>
|
||||
@@ -25,10 +28,16 @@ cm::optional<Json::Value> cmParsePlist(std::string const& filename)
|
||||
return cm::nullopt;
|
||||
}
|
||||
|
||||
Json::Value value;
|
||||
// Buffer plutil's output into a seekable stream. cmJSONState must be able
|
||||
// peek at a leading BOM, which the process pipe behind cmUVIStream can't
|
||||
// handle.
|
||||
cmUVIStream outputStream(chain.OutputStream());
|
||||
cmJSONState parseState(outputStream, &value,
|
||||
cmJSONState::StrictMode::Relaxed);
|
||||
std::string output{ std::istreambuf_iterator<char>(outputStream),
|
||||
std::istreambuf_iterator<char>() };
|
||||
std::istringstream jsonStream(output);
|
||||
|
||||
Json::Value value;
|
||||
cmJSONState parseState(jsonStream, &value, cmJSONState::StrictMode::Relaxed);
|
||||
if (!parseState.errors.empty()) {
|
||||
return cm::nullopt;
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
array.json -text -whitespace
|
||||
bom.json -text -whitespace
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user