Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:46

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIUTILS_REGEX_H
0012 #define GAUDIUTILS_REGEX_H
0013 // ============================================================================
0014 // Include files
0015 // ============================================================================
0016 #include <boost/regex.hpp>
0017 #include <string>
0018 
0019 /*
0020  *  Gaudi namespace declaration
0021  */
0022 namespace Gaudi {
0023   namespace Utils {
0024     // ========================================================================
0025     /** RegeEx: nemspace to hold gaudi regular expression checking
0026      *
0027      *  @param matchOr: return true if test is in any of the regexps
0028      *  @param matchAnd: return true if test is in all of the regexps
0029      *
0030      *  @author Rob Lambert Rob.Lambert@cern.ch
0031      *  @date   2009-07-29
0032      */
0033     namespace RegEx {
0034       class matchList {
0035         std::vector<boost::regex> m_regs;
0036 
0037       public:
0038         template <typename C>
0039         matchList( const C& c ) {
0040           m_regs.reserve( c.size() );
0041           std::transform( std::begin( c ), std::end( c ), std::back_inserter( m_regs ),
0042                           []( typename C::const_reference i ) { return boost::regex{ i }; } );
0043         }
0044 
0045         bool Or( const std::string& test ) const {
0046           return std::any_of( std::begin( m_regs ), std::end( m_regs ),
0047                               [&]( const boost::regex& r ) { return boost::regex_match( test, r ); } );
0048         }
0049         bool And( const std::string& test ) const {
0050           return std::all_of( std::begin( m_regs ), std::end( m_regs ),
0051                               [&]( const boost::regex& r ) { return boost::regex_match( test, r ); } );
0052         }
0053       };
0054 
0055       /** return true if the string is in any of the regex's
0056        *  @param  std::string test [IN]:  string to match
0057        *  @param  container<std::string> regexps  [IN]:  container of regex strings
0058        *         can be any container with a const_iterator, begin and end
0059        *
0060        *  If you need to do this more than once, please first create a matchList
0061        *  object, and then invoke its Or method.
0062        */
0063       template <typename T>
0064       bool matchOr( const std::string& test, const T& regexps ) {
0065         // compares the string in test, to the regexps in a container
0066         //
0067         return std::any_of( std::begin( regexps ), std::end( regexps ), [&]( typename T::const_reference i ) {
0068           return boost::regex_match( test, boost::regex{ i } );
0069         } );
0070       }
0071 
0072       /** return true if the string is in all of the regex's
0073        *  @param  std::string test [IN]:  string to match
0074        *  @param  container<std::string> regexps  [IN]:  container of regex strings
0075        *        can be any container with a const_iterator, begin and end
0076        *
0077        *  If you need to do this more than once, please first create a matchList
0078        *  object, and then invoke its And method.
0079        */
0080       template <typename T>
0081       bool matchAnd( const std::string& test, const T& regexps ) {
0082         // compares the string in test, to the regexps in a container
0083         //
0084         return std::all_of( std::begin( regexps ), std::end( regexps ), [&]( typename T::const_reference i ) {
0085           return boost::regex_match( test, boost::regex{ i } );
0086         } );
0087       }
0088     } // namespace RegEx
0089   }   // namespace Utils
0090 } // namespace Gaudi
0091 #endif