diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index a34e356c..2684494d 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include "DynamicModel.hh" #include "ParsingDriver.hh" @@ -243,7 +244,7 @@ DynamicModel::writeDynamicPerBlockMFiles(const string &basename) const output << "function [residual, y, T, g1, varargout] = dynamic_" << blk+1 << "(y, x, params, steady_state, T, it_, stochastic_mode)" << endl; output << " % ////////////////////////////////////////////////////////////////////////" << endl - << " % //" << " Block "s.substr(static_cast(log10(blk + 1))) << blk+1 + << " % //" << " Block "sv.substr(static_cast(log10(blk + 1))) << blk+1 << " //" << endl << " % // Simulation type " << BlockSim(simulation_type) << " //" << endl @@ -1528,9 +1529,12 @@ DynamicModel::parseIncludeExcludeEquations(const string &inc_exc_option_value, b for (auto it = sregex_iterator(tags.begin(), tags.end(), s); it != sregex_iterator(); ++it) { - auto str = it->str(); - if (str[0] == '\'' && str[str.size()-1] == '\'') - str = str.substr(1, str.size()-2); + string_view str {it->str()}; + if (str.front() == '\'' && str.back() == '\'') + { + str.remove_prefix(1); + str.remove_suffix(1); + } eq_tag_set.emplace_back(tagname, str); } return eq_tag_set; diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index 2f30e43d..00635431 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -3245,13 +3245,11 @@ ParsingDriver::add_native(string s) } void -ParsingDriver::add_native_remove_charset(string str, const string &token) +ParsingDriver::add_native_remove_charset(string_view str, string_view token) { size_t found = str.find(token); - - assert(found != string::npos); - str.resize(found); - add_native(move(str)); + assert(found != string_view::npos); + add_native(string{str.substr(0, found)}); } void @@ -3261,13 +3259,11 @@ ParsingDriver::add_verbatim(string s) } void -ParsingDriver::add_verbatim_remove_charset(string str, const string &token) +ParsingDriver::add_verbatim_remove_charset(string_view str, string_view token) { size_t found = str.find(token); - - assert(found != string::npos); - str.resize(found); - add_verbatim(str); + assert(found != string_view::npos); + add_verbatim(string{str.substr(0, found)}); } void diff --git a/src/ParsingDriver.hh b/src/ParsingDriver.hh index 51ea1e10..38f69c82 100644 --- a/src/ParsingDriver.hh +++ b/src/ParsingDriver.hh @@ -29,6 +29,7 @@ #include #include #include +#include #include "ModFile.hh" #include "SymbolList.hh" @@ -849,11 +850,11 @@ public: //! Adds a native statement void add_native(string s); //! Adds a native statement, first removing the set of characters passed in token (and everything after) - void add_native_remove_charset(string str, const string &token); + void add_native_remove_charset(string_view str, string_view token); //! Adds a verbatim statement void add_verbatim(string s); //! Adds a verbatim statement, first removing the set of characters passed in token (and everything after) - void add_verbatim_remove_charset(string str, const string &token); + void add_verbatim_remove_charset(string_view str, string_view token); //! Resets data_tree and model_tree pointers to default (i.e. mod_file->expressions_tree) void reset_data_tree(); //! Begin a steady_state_model block diff --git a/src/StaticModel.cc b/src/StaticModel.cc index cc029595..5d325894 100644 --- a/src/StaticModel.cc +++ b/src/StaticModel.cc @@ -124,7 +124,7 @@ StaticModel::writeStaticPerBlockMFiles(const string &basename) const output << "function [residual, y, T, g1] = static_" << blk+1 << "(y, x, params, T)" << endl; output << " % ////////////////////////////////////////////////////////////////////////" << endl - << " % //" << " Block "s.substr(static_cast(log10(blk + 1))) << blk+1 + << " % //" << " Block "sv.substr(static_cast(log10(blk + 1))) << blk+1 << " //" << endl << " % // Simulation type " << BlockSim(simulation_type) << " //" << endl