Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-13 09:22:35

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsPlugins/Root/TGeoPrimitivesHelper.hpp"
0010 
0011 #include <algorithm>
0012 
0013 bool ActsPlugins::TGeoPrimitivesHelper::match(const char* first,
0014                                               const char* second) {
0015   // If we reach at the end of both strings, we are done
0016   if (*first == '\0' && *second == '\0') {
0017     return true;
0018   }
0019 
0020   // Make sure that the characters after '*' are present
0021   // in second string. This function assumes that the first
0022   // string will not contain two consecutive '*'
0023   if (*first == '*' && *(first + 1) != '\0' && *second == '\0') {
0024     return false;
0025   }
0026 
0027   // If the first string contains '?', or current characters
0028   // of both strings match
0029   if (*first == '?' || *first == *second) {
0030     return match(first + 1, second + 1);
0031   }
0032 
0033   // If there is *, then there are two possibilities
0034   // a) We consider current character of second string
0035   // b) We ignore current character of second string.
0036   if (*first == '*') {
0037     return match(first + 1, second) || match(first, second + 1);
0038   }
0039   return false;
0040 }
0041 
0042 bool ActsPlugins::TGeoPrimitivesHelper::match(
0043     const std::vector<std::string>& first, const char* second) {
0044   return std::ranges::any_of(
0045       first, [&](const std::string& f) { return match(f.c_str(), second); });
0046 }