@@ -861,6 +861,31 @@ std::vector<std::string> TRestTools::GetObservablesInString(const std::string& o
861861 return obsList;
862862}
863863
864+ // //////////////////////////////////////////////////////////
865+ // / \brief Returns a set of strings that match the wanted strings from the stack.
866+ // / The wanted strings can contain wildcards "*" and "?".
867+ // / \param stack: vector of strings to be searched
868+ // / \param wantedStrings: vector of strings with the wanted strings to be matched.
869+ // / \return a set of strings that match the wanted strings
870+ // / e.g.
871+ // / Input: stack = {"x1", "x2", "x11", "y1", "y2", "y11", "z1", "z2"},
872+ // / wantedStrings = {"x*", "y?", "z1"},
873+ // / Output: {"x1", "x11", "x2", "y1", "y2", "z1"}
874+ // /
875+ std::set<std::string> TRestTools::GetMatchingStrings (const std::vector<std::string>& stack,
876+ const std::vector<std::string>& wantedStrings) {
877+ std::set<std::string> result;
878+ for (auto & ws : wantedStrings) {
879+ if (ws.find (" *" ) != std::string::npos || ws.find (" ?" ) != std::string::npos) {
880+ for (auto & c : stack)
881+ if (MatchString (c, ws)) result.insert (c);
882+ } else if (std::find (stack.begin (), stack.end (), ws) != stack.end ())
883+ result.insert (ws);
884+ }
885+ // return std::vector<std::string>(result.begin(), result.end()); // convert to vector
886+ return result;
887+ }
888+
864889// /////////////////////////////////////////////
865890// / \brief Returns the input string but without multiple slashes ("/")
866891// /
0 commit comments