2 CLAW - a C++ Library Absolutely Wonderful
4 CLAW is a free library without any particular aim but being useful to
7 Copyright (C) 2005-2011 Julien Jorge
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.
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.
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
23 contact: julien.jorge@gamned.org
26 * \file string_algorithm.tpp
27 * \brief Implementation of the globalization algorithms.
28 * \author Julien Jorge
31/*----------------------------------------------------------------------------*/
33 * \brief Check if a sequence matches a given pattern.
34 * \param pattern_first Iterator on the beginning of the pattern.
35 * \param pattern_last Iterator just past the end of the pattern.
36 * \param first Iterator on the beginning of the sequence.
37 * \param last Iterator just last the end of the sequence.
38 * \param any_sequence A value representing any sequence of values, empty or
40 * \param zero_or_one A value representing any value or no value.
41 * \param any A value representing any value.
43template<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 )
53 if ( (pattern_first == pattern_last) || (first == last) )
55 result = (first == last);
57 for ( ; result && (pattern_first != pattern_last); ++ pattern_first )
59 (*pattern_first == any_sequence) || (*pattern_first == zero_or_one);
61 else if ( *pattern_first == any_sequence )
64 ( pattern_first + 1, pattern_last, first, last, any_sequence, zero_or_one,
67 ( pattern_first, pattern_last, first + 1, last, any_sequence, zero_or_one,
69 else if ( *pattern_first == zero_or_one )
72 ( pattern_first + 1, pattern_last, first, last, any_sequence, zero_or_one,
75 ( pattern_first + 1, pattern_last, first + 1, last, any_sequence,
77 else if ( (*pattern_first == zero_or_one) || (*pattern_first == *first) )
80 ( pattern_first + 1, pattern_last, first + 1, last, any_sequence,
88/*----------------------------------------------------------------------------*/
90 * \brief Check if a sequence may match a given pattern.
91 * \param pattern_first Iterator on the beginning of the pattern.
92 * \param pattern_last Iterator just past the end of the pattern.
93 * \param first Iterator on the beginning of the sequence.
94 * \param last Iterator just last the end of the sequence.
95 * \param any_sequence A value representing any sequence of values, empty or
97 * \param zero_or_one A value representing any value or no value.
98 * \param any A value representing any value.
100template<typename InputIterator1, typename InputIterator2>
101bool claw::glob_potential_match
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 )
111 while ( !stop && (pattern_first != pattern_last) && (first != last) )
112 if ( (*pattern_first == any_sequence) || (*pattern_first == zero_or_one) )
114 else if ( *pattern_first == any )
119 else if ( *pattern_first == *first )
131} // glob_potential_match()