mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-06-08 09:27:50 +02:00
cleaner
This commit is contained in:
parent
05810a7607
commit
632c9b5032
@ -130,11 +130,11 @@ printValueTree(FILE* fout, Json::Value& value, const std::string& path = ".") {
|
|||||||
static int parseAndSaveValueTree(const std::string& input,
|
static int parseAndSaveValueTree(const std::string& input,
|
||||||
const std::string& actual,
|
const std::string& actual,
|
||||||
const std::string& kind,
|
const std::string& kind,
|
||||||
Json::Value& root,
|
|
||||||
const Json::Features& features,
|
const Json::Features& features,
|
||||||
bool parseOnly) {
|
bool parseOnly,
|
||||||
|
Json::Value* root) {
|
||||||
Json::Reader reader(features);
|
Json::Reader reader(features);
|
||||||
bool parsingSuccessful = reader.parse(input, root);
|
bool parsingSuccessful = reader.parse(input, *root);
|
||||||
if (!parsingSuccessful) {
|
if (!parsingSuccessful) {
|
||||||
printf("Failed to parse %s file: \n%s\n",
|
printf("Failed to parse %s file: \n%s\n",
|
||||||
kind.c_str(),
|
kind.c_str(),
|
||||||
@ -148,7 +148,7 @@ static int parseAndSaveValueTree(const std::string& input,
|
|||||||
printf("Failed to create %s actual file.\n", kind.c_str());
|
printf("Failed to create %s actual file.\n", kind.c_str());
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
printValueTree(factual, root);
|
printValueTree(factual, *root);
|
||||||
fclose(factual);
|
fclose(factual);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -156,19 +156,19 @@ static int parseAndSaveValueTree(const std::string& input,
|
|||||||
|
|
||||||
static int rewriteValueTree(const std::string& rewritePath,
|
static int rewriteValueTree(const std::string& rewritePath,
|
||||||
const Json::Value& root,
|
const Json::Value& root,
|
||||||
std::string& rewrite) {
|
std::string* rewrite) {
|
||||||
// Json::FastWriter writer;
|
// Json::FastWriter writer;
|
||||||
// writer.enableYAMLCompatibility();
|
// writer.enableYAMLCompatibility();
|
||||||
Json::StyledStreamWriter writer;
|
Json::StyledStreamWriter writer;
|
||||||
std::ostringstream sout;
|
std::ostringstream sout;
|
||||||
writer.write(sout, root);
|
writer.write(sout, root);
|
||||||
rewrite = sout.str();
|
*rewrite = sout.str();
|
||||||
FILE* fout = fopen(rewritePath.c_str(), "wt");
|
FILE* fout = fopen(rewritePath.c_str(), "wt");
|
||||||
if (!fout) {
|
if (!fout) {
|
||||||
printf("Failed to create rewrite file: %s\n", rewritePath.c_str());
|
printf("Failed to create rewrite file: %s\n", rewritePath.c_str());
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
fprintf(fout, "%s\n", rewrite.c_str());
|
fprintf(fout, "%s\n", rewrite->c_str());
|
||||||
fclose(fout);
|
fclose(fout);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -250,24 +250,24 @@ int main(int argc, const char* argv[]) {
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string actualPath = basePath + ".actual";
|
std::string const actualPath = basePath + ".actual";
|
||||||
std::string rewritePath = basePath + ".rewrite";
|
std::string const rewritePath = basePath + ".rewrite";
|
||||||
std::string rewriteActualPath = basePath + ".actual-rewrite";
|
std::string const rewriteActualPath = basePath + ".actual-rewrite";
|
||||||
|
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
exitCode = parseAndSaveValueTree(
|
exitCode = parseAndSaveValueTree(
|
||||||
input, actualPath, "input", root, features, parseOnly);
|
input, actualPath, "input", features, parseOnly, &root);
|
||||||
if (exitCode || parseOnly) {
|
if (exitCode || parseOnly) {
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
std::string rewrite;
|
std::string rewrite;
|
||||||
exitCode = rewriteValueTree(rewritePath, root, rewrite);
|
exitCode = rewriteValueTree(rewritePath, root, &rewrite);
|
||||||
if (exitCode) {
|
if (exitCode) {
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
Json::Value rewriteRoot;
|
Json::Value rewriteRoot;
|
||||||
exitCode = parseAndSaveValueTree(
|
exitCode = parseAndSaveValueTree(
|
||||||
rewrite, rewriteActualPath, "rewrite", rewriteRoot, features, parseOnly);
|
rewrite, rewriteActualPath, "rewrite", features, parseOnly, &rewriteRoot);
|
||||||
if (exitCode) {
|
if (exitCode) {
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user