Skip to content

Commit

Permalink
Implement parser of multiple files of object
Browse files Browse the repository at this point in the history
  • Loading branch information
kenji0923 committed Jun 22, 2023
1 parent 4deaf1e commit d0f5faa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions json11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,19 @@ Json Json::parse_file(const std::string& Filename)
return Json::parse(strParameters, strbuf);
}

Json Json::parse_object_files(const std::vector<std::string>& Filename)
{
object obj;
for (const auto& name : Filename) {
Json new_object = parse_file(name);
if (!new_object.is_object()) {
throw std::runtime_error("Json is not an object");
}
obj.insert(new_object.object_items().begin(), new_object.object_items().end());
}
return Json(obj);
}

/* * * * * * * * * * * * * * * * * * * *
* Shape-checking
*/
Expand Down
3 changes: 3 additions & 0 deletions json11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,11 @@ class Json final {
std::string::size_type parser_stop_pos;
return parse_multi(in, parser_stop_pos, err, strategy);
}

static Json parse_file(const std::string& Filename);

static Json parse_object_files(const std::vector<std::string>& Filenames);

bool operator== (const Json &rhs) const;
bool operator< (const Json &rhs) const;
bool operator!= (const Json &rhs) const { return !(*this == rhs); }
Expand Down

0 comments on commit d0f5faa

Please sign in to comment.