Claw  1.7.3
glob.tpp
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
31 /*----------------------------------------------------------------------------*/
43 template<typename InputIterator1, typename InputIterator2>
45 ( InputIterator1 pattern_first, InputIterator1 pattern_last,
46  InputIterator2 first, InputIterator2 last,
47  typename InputIterator1::value_type any_sequence,
48  typename InputIterator1::value_type zero_or_one,
49  typename InputIterator1::value_type any )
50 {
51  bool result(false);
52 
53  if ( (pattern_first == pattern_last) || (first == last) )
54  {
55  result = (first == last);
56 
57  for ( ; result && (pattern_first != pattern_last); ++ pattern_first )
58  result =
59  (*pattern_first == any_sequence) || (*pattern_first == zero_or_one);
60  }
61  else if ( *pattern_first == any_sequence )
62  result =
64  ( pattern_first + 1, pattern_last, first, last, any_sequence, zero_or_one,
65  any)
66  || glob_match
67  ( pattern_first, pattern_last, first + 1, last, any_sequence, zero_or_one,
68  any );
69  else if ( *pattern_first == zero_or_one )
70  result =
72  ( pattern_first + 1, pattern_last, first, last, any_sequence, zero_or_one,
73  any)
74  || glob_match
75  ( pattern_first + 1, pattern_last, first + 1, last, any_sequence,
76  zero_or_one, any );
77  else if ( (*pattern_first == zero_or_one) || (*pattern_first == *first) )
78  result =
80  ( pattern_first + 1, pattern_last, first + 1, last, any_sequence,
81  zero_or_one, any );
82  else
83  result = false;
84 
85  return result;
86 } // glob_match()
87 
88 /*----------------------------------------------------------------------------*/
100 template<typename InputIterator1, typename InputIterator2>
102 ( InputIterator1 pattern_first, InputIterator1 pattern_last,
103  InputIterator2 first, InputIterator2 last,
104  typename InputIterator1::value_type any_sequence,
105  typename InputIterator1::value_type zero_or_one,
106  typename InputIterator1::value_type any )
107 {
108  bool result(true);
109  bool stop(false);
110 
111  while ( !stop && (pattern_first != pattern_last) && (first != last) )
112  if ( (*pattern_first == any_sequence) || (*pattern_first == zero_or_one) )
113  stop = true;
114  else if ( *pattern_first == any )
115  {
116  ++pattern_first;
117  ++first;
118  }
119  else if ( *pattern_first == *first )
120  {
121  ++pattern_first;
122  ++first;
123  }
124  else
125  {
126  result = false;
127  stop = true;
128  }
129 
130  return result;
131 } // glob_potential_match()