Moved TRMNL stuff to its own file
This commit is contained in:
21
helpers.cpp
21
helpers.cpp
@@ -6,6 +6,7 @@ using nlohmann::json;
|
||||
|
||||
using std::endl;
|
||||
using std::ifstream;
|
||||
using std::ofstream;
|
||||
using std::istream;
|
||||
using std::ostream;
|
||||
using std::string;
|
||||
@@ -18,7 +19,7 @@ bool read_file_json(json& j, const string& filename, ostream* log)
|
||||
{
|
||||
if (nullptr != log)
|
||||
{
|
||||
*log << "Could not open file" << endl;
|
||||
*log << "Could not open file to read - " << filename << endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -45,6 +46,24 @@ bool read_stream_json(json& j, istream& in, ostream* log)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool write_file_json(const json& j, const string& filename, ostream* log)
|
||||
{
|
||||
ofstream file(filename);
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
if (nullptr != log)
|
||||
{
|
||||
*log << "Could not open file to write - " << filename << endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
file << j.dump(4) << endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool json_extract(const json& j, const string& key, string& out)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
Reference in New Issue
Block a user