Use std::string_view in a few places where it makes sense
parent
4c58451d83
commit
5c33051990
|
@ -25,6 +25,7 @@
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include "DynamicModel.hh"
|
#include "DynamicModel.hh"
|
||||||
#include "ParsingDriver.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 << "function [residual, y, T, g1, varargout] = dynamic_" << blk+1 << "(y, x, params, steady_state, T, it_, stochastic_mode)" << endl;
|
||||||
|
|
||||||
output << " % ////////////////////////////////////////////////////////////////////////" << endl
|
output << " % ////////////////////////////////////////////////////////////////////////" << endl
|
||||||
<< " % //" << " Block "s.substr(static_cast<int>(log10(blk + 1))) << blk+1
|
<< " % //" << " Block "sv.substr(static_cast<int>(log10(blk + 1))) << blk+1
|
||||||
<< " //" << endl
|
<< " //" << endl
|
||||||
<< " % // Simulation type "
|
<< " % // Simulation type "
|
||||||
<< BlockSim(simulation_type) << " //" << endl
|
<< 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);
|
for (auto it = sregex_iterator(tags.begin(), tags.end(), s);
|
||||||
it != sregex_iterator(); ++it)
|
it != sregex_iterator(); ++it)
|
||||||
{
|
{
|
||||||
auto str = it->str();
|
string_view str {it->str()};
|
||||||
if (str[0] == '\'' && str[str.size()-1] == '\'')
|
if (str.front() == '\'' && str.back() == '\'')
|
||||||
str = str.substr(1, str.size()-2);
|
{
|
||||||
|
str.remove_prefix(1);
|
||||||
|
str.remove_suffix(1);
|
||||||
|
}
|
||||||
eq_tag_set.emplace_back(tagname, str);
|
eq_tag_set.emplace_back(tagname, str);
|
||||||
}
|
}
|
||||||
return eq_tag_set;
|
return eq_tag_set;
|
||||||
|
|
|
@ -3245,13 +3245,11 @@ ParsingDriver::add_native(string s)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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);
|
size_t found = str.find(token);
|
||||||
|
assert(found != string_view::npos);
|
||||||
assert(found != string::npos);
|
add_native(string{str.substr(0, found)});
|
||||||
str.resize(found);
|
|
||||||
add_native(move(str));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -3261,13 +3259,11 @@ ParsingDriver::add_verbatim(string s)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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);
|
size_t found = str.find(token);
|
||||||
|
assert(found != string_view::npos);
|
||||||
assert(found != string::npos);
|
add_verbatim(string{str.substr(0, found)});
|
||||||
str.resize(found);
|
|
||||||
add_verbatim(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include "ModFile.hh"
|
#include "ModFile.hh"
|
||||||
#include "SymbolList.hh"
|
#include "SymbolList.hh"
|
||||||
|
@ -849,11 +850,11 @@ public:
|
||||||
//! Adds a native statement
|
//! Adds a native statement
|
||||||
void add_native(string s);
|
void add_native(string s);
|
||||||
//! Adds a native statement, first removing the set of characters passed in token (and everything after)
|
//! 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
|
//! Adds a verbatim statement
|
||||||
void add_verbatim(string s);
|
void add_verbatim(string s);
|
||||||
//! Adds a verbatim statement, first removing the set of characters passed in token (and everything after)
|
//! 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)
|
//! Resets data_tree and model_tree pointers to default (i.e. mod_file->expressions_tree)
|
||||||
void reset_data_tree();
|
void reset_data_tree();
|
||||||
//! Begin a steady_state_model block
|
//! Begin a steady_state_model block
|
||||||
|
|
|
@ -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 << "function [residual, y, T, g1] = static_" << blk+1 << "(y, x, params, T)" << endl;
|
||||||
|
|
||||||
output << " % ////////////////////////////////////////////////////////////////////////" << endl
|
output << " % ////////////////////////////////////////////////////////////////////////" << endl
|
||||||
<< " % //" << " Block "s.substr(static_cast<int>(log10(blk + 1))) << blk+1
|
<< " % //" << " Block "sv.substr(static_cast<int>(log10(blk + 1))) << blk+1
|
||||||
<< " //" << endl
|
<< " //" << endl
|
||||||
<< " % // Simulation type "
|
<< " % // Simulation type "
|
||||||
<< BlockSim(simulation_type) << " //" << endl
|
<< BlockSim(simulation_type) << " //" << endl
|
||||||
|
|
Loading…
Reference in New Issue