diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp index 7bacc0dfb93241e62dc2d5022ff5113862c921bc..1c22671c26d1062b669f28a4c61d5b650eb541ab 100644 --- a/BaseLib/FileTools.cpp +++ b/BaseLib/FileTools.cpp @@ -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, diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h index d8c3e9d5738d21d4cdb29e44a8eadfd4e1dfaa6e..e2b432171a4bae5192ab60964f2f0f75181300ae 100644 --- a/BaseLib/FileTools.h +++ b/BaseLib/FileTools.h @@ -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,