The Gaudi Framework master (934d2c3c)
Loading...
Searching...
No Matches
RegEx.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12// ============================================================================
13// Include files
14// ============================================================================
15#include <algorithm>
16#include <iterator>
17#include <regex>
18#include <string>
19
20/*
21 * Gaudi namespace declaration
22 */
23namespace Gaudi::Utils {
24 // ========================================================================
33 namespace RegEx {
34 class matchList {
36
37 public:
38 template <typename C>
39 matchList( const C& c ) {
40 m_regs.reserve( c.size() );
42 []( typename C::const_reference i ) { return std::regex{ i }; } );
43 }
44
45 bool Or( const std::string& test ) const {
47 [&]( const std::regex& r ) { return std::regex_match( test, r ); } );
48 }
49 bool And( const std::string& test ) const {
51 [&]( const std::regex& r ) { return std::regex_match( test, r ); } );
52 }
53 };
54
63 template <typename T>
64 bool matchOr( const std::string& test, const T& regexps ) {
65 // compares the string in test, to the regexps in a container
66 //
67 return std::any_of( std::begin( regexps ), std::end( regexps ),
68 [&]( typename T::const_reference i ) { return std::regex_match( test, std::regex{ i } ); } );
69 }
70
79 template <typename T>
80 bool matchAnd( const std::string& test, const T& regexps ) {
81 // compares the string in test, to the regexps in a container
82 //
83 return std::all_of( std::begin( regexps ), std::end( regexps ),
84 [&]( typename T::const_reference i ) { return std::regex_match( test, std::regex{ i } ); } );
85 }
86 } // namespace RegEx
87} // namespace Gaudi::Utils
constexpr _OutputIterator transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __unary_op)
constexpr bool all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
constexpr bool any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
basic_regex< char > regex
bool regex_match(_Bi_iter __s, _Bi_iter __e, match_results< _Bi_iter, _Alloc > &__m, const basic_regex< _Ch_type, _Rx_traits > &__re, regex_constants::match_flag_type __flags=regex_constants::match_default)
constexpr back_insert_iterator< _Container > back_inserter(_Container &__x)
constexpr auto begin(_Container &__cont) -> decltype(__cont.begin())
constexpr auto end(_Container &__cont) -> decltype(__cont.end())
constexpr void reserve(size_type __n)
bool Or(const std::string &test) const
Definition RegEx.h:45
bool And(const std::string &test) const
Definition RegEx.h:49
std::vector< std::regex > m_regs
Definition RegEx.h:35
RegeEx: nemspace to hold gaudi regular expression checking.
Definition RegEx.h:33
bool matchOr(const std::string &test, const T &regexps)
return true if the string is in any of the regex's
Definition RegEx.h:64
bool matchAnd(const std::string &test, const T &regexps)
return true if the string is in all of the regex's
Definition RegEx.h:80