1 // Copyright (c) 2014-2018 Dr. Colin Hirsch and Daniel Frey
2 // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
3 
4 #ifndef TAO_PEGTL_INTERNAL_ONE_HPP
5 #define TAO_PEGTL_INTERNAL_ONE_HPP
6 
7 #include <algorithm>
8 #include <utility>
9 
10 #include "../config.hpp"
11 
12 #include "bump_help.hpp"
13 #include "result_on_found.hpp"
14 #include "skip_control.hpp"
15 
16 #include "../analysis/generic.hpp"
17 
18 namespace tao
19 {
20    namespace TAO_PEGTL_NAMESPACE
21    {
22       namespace internal
23       {
24          template< typename Char >
contains(const Char c,const std::initializer_list<Char> & l)25          bool contains( const Char c, const std::initializer_list< Char >& l ) noexcept
26          {
27             return std::find( l.begin(), l.end(), c ) != l.end();
28          }
29 
30          template< result_on_found R, typename Peek, typename Peek::data_t... Cs >
31          struct one
32          {
33             using analyze_t = analysis::generic< analysis::rule_type::ANY >;
34 
35             template< typename Input >
matchtao::TAO_PEGTL_NAMESPACE::internal::one36             static bool match( Input& in ) noexcept( noexcept( in.empty() ) )
37             {
38                if( !in.empty() ) {
39                   if( const auto t = Peek::peek( in ) ) {
40                      if( contains( t.data, { Cs... } ) == bool( R ) ) {
41                         bump_help< R, Input, typename Peek::data_t, Cs... >( in, t.size );
42                         return true;
43                      }
44                   }
45                }
46                return false;
47             }
48          };
49 
50          template< result_on_found R, typename Peek, typename Peek::data_t C >
51          struct one< R, Peek, C >
52          {
53             using analyze_t = analysis::generic< analysis::rule_type::ANY >;
54 
55             template< typename Input >
matchtao::TAO_PEGTL_NAMESPACE::internal::one56             static bool match( Input& in ) noexcept( noexcept( in.empty() ) )
57             {
58                if( !in.empty() ) {
59                   if( const auto t = Peek::peek( in ) ) {
60                      if( ( t.data == C ) == bool( R ) ) {
61                         bump_help< R, Input, typename Peek::data_t, C >( in, t.size );
62                         return true;
63                      }
64                   }
65                }
66                return false;
67             }
68          };
69 
70          template< result_on_found R, typename Peek, typename Peek::data_t... Cs >
71          struct skip_control< one< R, Peek, Cs... > > : std::true_type
72          {
73          };
74 
75       }  // namespace internal
76 
77    }  // namespace TAO_PEGTL_NAMESPACE
78 
79 }  // namespace tao
80 
81 #endif
82