Skip to content
Snippets Groups Projects
Commit 49086d9b authored by Tom Fischer's avatar Tom Fischer
Browse files

[BL] Impl. getParenthesizedString().

parent f337116f
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,28 @@ bool IsFileExisting(const std::string &strFilename)
return fs::exists(fs::path(strFilename));
}
std::tuple<std::string, std::string::size_type, std::string::size_type>
getParenthesizedString(std::string const& in,
char const open_char,
char const close_char,
std::string::size_type pos)
{
auto const pos_curly_brace_open = in.find_first_of(open_char, pos);
if (pos_curly_brace_open == std::string::npos)
{
return std::make_tuple("", std::string::npos, std::string::npos);
}
auto const pos_curly_brace_close =
in.find_first_of(close_char, pos_curly_brace_open);
if (pos_curly_brace_close == std::string::npos)
{
return std::make_tuple("", std::string::npos, std::string::npos);
}
return std::make_tuple(
in.substr(pos_curly_brace_open + 1,
pos_curly_brace_close - (pos_curly_brace_open + 1)),
pos_curly_brace_open, pos_curly_brace_close);
}
std::string constructFileName(std::string const& prefix,
int const process_id,
int const timestep,
......
......@@ -29,6 +29,17 @@ namespace BaseLib
*/
bool IsFileExisting(const std::string &strFilename);
/**
* Returns the begin and end position of the string enclosed in open_char and
* close_char and the enclosed string itself. Search starts at position pos
* within the string str. Nested open_char and close_char are not handled
* correctly.
*/
std::tuple<std::string, std::string::size_type, std::string::size_type>
getParenthesizedString(std::string const& str,
char const open_char,
char const close_char,
std::string::size_type pos);
std::string constructFileName(std::string const& prefix,
int const process_id,
int const timestep,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment