Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TGeoPrimitivesHelper.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TGeoPrimitivesHelper.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
11 bool Acts::TGeoPrimitivesHelper::match(const char* first, const char* second) {
12  // If we reach at the end of both strings, we are done
13  if (*first == '\0' && *second == '\0') {
14  return true;
15  }
16 
17  // Make sure that the characters after '*' are present
18  // in second string. This function assumes that the first
19  // string will not contain two consecutive '*'
20  if (*first == '*' && *(first + 1) != '\0' && *second == '\0') {
21  return false;
22  }
23 
24  // If the first string contains '?', or current characters
25  // of both strings match
26  if (*first == '?' || *first == *second) {
27  return match(first + 1, second + 1);
28  }
29 
30  // If there is *, then there are two possibilities
31  // a) We consider current character of second string
32  // b) We ignore current character of second string.
33  if (*first == '*') {
34  return match(first + 1, second) || match(first, second + 1);
35  }
36  return false;
37 }
38 
39 bool Acts::TGeoPrimitivesHelper::match(const std::vector<std::string>& first,
40  const char* second) {
41  for (const auto& f : first) {
42  if (match(f.c_str(), second)) {
43  return true;
44  }
45  }
46  return false;
47 }