diff --git a/src/gui/add_csv_window.cpp b/src/gui/add_csv_window.cpp index f63ca508..9fca299e 100644 --- a/src/gui/add_csv_window.cpp +++ b/src/gui/add_csv_window.cpp @@ -167,7 +167,7 @@ void AddCSVWindow::onOk(wxCommandEvent&) { /// Perform the import wxBusyCursor wait; // Read the file - auto file = std::ifstream(file_path->GetValue().ToStdString()); + auto& file = std::ifstream(file_path->GetValue().ToStdString()); if (file.fail()) { queue_message(MESSAGE_ERROR, _ERROR_("add card csv file not found")); EndModal(wxID_ABORT); diff --git a/src/gui/add_json_window.cpp b/src/gui/add_json_window.cpp index c17df358..dba748a8 100644 --- a/src/gui/add_json_window.cpp +++ b/src/gui/add_json_window.cpp @@ -139,14 +139,14 @@ void AddJSONWindow::onBrowseFiles(wxCommandEvent&) { queue_message(MESSAGE_ERROR, _ERROR_("add card json empty array")); return false; } - auto& card = card_array[0]; - if (!card.is_object()) { + const auto& first_card = card_array[0]; + if (!first_card.is_object()) { queue_message(MESSAGE_ERROR, _ERROR_("add card json path not valid")); return false; } // Get headers for (int i = 0; i < count; ++i) { - auto& card = card_array[i].as_object(); + const auto& card = card_array[i].as_object(); for (auto it = card.begin(); it != card.end(); ++it) { boost::json::string_view jview = it->key(); std::string_view stdview = std::string_view(jview.data(), jview.size()); @@ -162,7 +162,7 @@ void AddJSONWindow::onBrowseFiles(wxCommandEvent&) { std::vector row; auto& card = card_array[i].as_object(); for (int h = 0; h < headers_out.size(); ++h) { - auto& value = card[headers_out[h].ToStdString()]; + const auto& value = card[headers_out[h].ToStdString()]; row.push_back(json_to_mse(value, set.get())); } table_out.push_back(row); @@ -174,7 +174,7 @@ void AddJSONWindow::onOk(wxCommandEvent&) { /// Perform the import wxBusyCursor wait; // Read the file - auto file = std::ifstream(file_path->GetValue().ToStdString()); + auto& file = std::ifstream(file_path->GetValue().ToStdString()); if (file.fail()) { queue_message(MESSAGE_ERROR, _ERROR_("add card json file not found")); EndModal(wxID_ABORT); diff --git a/src/script/functions/json.hpp b/src/script/functions/json.hpp index 52b07ed1..3d1b279d 100644 --- a/src/script/functions/json.hpp +++ b/src/script/functions/json.hpp @@ -25,7 +25,7 @@ // ----------------------------------------------------------------------------- : JSON to String -inline static void pretty_print(std::ostream& os, boost::json::value const& jv, std::string* indent = nullptr) +inline static void pretty_print(std::ostream& os, const boost::json::value& jv, std::string* indent = nullptr) { std::string indent_; if(! indent) @@ -106,21 +106,21 @@ inline static void pretty_print(std::ostream& os, boost::json::value const& jv, os << "\n"; } -inline static String json_pretty_print(boost::json::value const& jv, std::string* indent = nullptr) { +inline static String json_pretty_print(const boost::json::value& jv, std::string* indent = nullptr) { std::ostringstream stream; pretty_print(stream, jv, indent); String string = wxString(stream.str().c_str()); return string; } -inline static String json_ugly_print(boost::json::value const& jv) { +inline static String json_ugly_print(const boost::json::value& jv) { String string = wxString(boost::json::serialize(jv).c_str()); return string; } // ----------------------------------------------------------------------------- : JSON to MSE -inline static ScriptValueP json_to_mse(boost::json::value& jv, Set* set); +inline static ScriptValueP json_to_mse(const boost::json::value& jv, Set* set); template static void read(T& out, boost::json::object& jv, const char value_name[]) { @@ -301,7 +301,7 @@ inline static SetP json_to_mse_set(boost::json::object& jv) { return set; } -inline static ScriptValueP json_to_mse(boost::json::value& jv, Set* set) { +inline static ScriptValueP json_to_mse(const boost::json::value& jv, Set* set) { if (jv == nullptr) return script_nil; else if (jv.is_null()) return script_nil; else if (jv.is_bool()) return to_script(jv.get_bool()); @@ -358,7 +358,7 @@ inline static ScriptValueP json_to_mse(boost::json::value& jv, Set* set) { return script_nil; } } -inline static ScriptValueP json_to_mse(String& string, Set* set) { +inline static ScriptValueP json_to_mse(const String& string, Set* set) { try { boost::system::error_code ec; boost::json::parse_options options; @@ -372,7 +372,7 @@ inline static ScriptValueP json_to_mse(String& string, Set* set) { return script_nil; } } -inline static ScriptValueP json_to_mse(ScriptValueP& sv, Set* set) { +inline static ScriptValueP json_to_mse(const ScriptValueP& sv, Set* set) { try { String string = sv->toString(); return json_to_mse(string, set); @@ -386,7 +386,7 @@ inline static ScriptValueP json_to_mse(ScriptValueP& sv, Set* set) { // ----------------------------------------------------------------------------- : MSE to JSON template -static void write(boost::json::object& out, const String& name, T& value) { +static void write(boost::json::object& out, const String& name, const T& value) { wxStringOutputStream stream; Writer writer(stream); writer.indentation = -1000;