add star_subst() utility function that replaces a '*' in a string with a number

This commit is contained in:
Axel Kohlmeyer
2022-03-28 22:40:15 -04:00
parent d80fe166d1
commit 3ba7b8c24c
4 changed files with 50 additions and 2 deletions

View File

@ -791,11 +791,23 @@ std::string utils::trim(const std::string &line)
std::string utils::trim_comment(const std::string &line)
{
auto end = line.find_first_of('#');
auto end = line.find('#');
if (end != std::string::npos) { return line.substr(0, end); }
return {line};
}
/* ----------------------------------------------------------------------
Replace '*' with number and optional zero-padding
------------------------------------------------------------------------- */
std::string utils::star_subst(const std::string &name, bigint step, int pad)
{
auto star = name.find('*');
if (star == std::string::npos) return name;
return fmt::format("{}{:0{}}{}",name.substr(0,star),step,pad,name.substr(star+1));
}
/* ----------------------------------------------------------------------
Replace UTF-8 encoded chars with known ASCII equivalents
------------------------------------------------------------------------- */