GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
glob-match.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_glob_match_h)
24 #define octave_glob_match_h 1
25 
26 #include <string>
27 
28 #include "Array.h"
29 #include "str-vec.h"
30 
31 class
32 OCTAVE_API
34 {
35 public:
36 
37  enum opts
38  {
39  pathname = 1, // No wildcard can ever match '/'.
40  noescape = 2, // Backslashes don't quote special chars.
41  period = 4 // Leading '.' is matched only explicitly.
42  };
43 
44  glob_match (const std::string& p,
45  unsigned int xopts = pathname|noescape|period)
46  : pat (p), fnmatch_flags (opts_to_fnmatch_flags (xopts)) { }
47 
49  unsigned int xopts = pathname|noescape|period)
50  : pat (p), fnmatch_flags (opts_to_fnmatch_flags (xopts)) { }
51 
52  glob_match (const glob_match& gm)
53  : pat (gm.pat), fnmatch_flags (gm.fnmatch_flags) { }
54 
55  glob_match& operator = (const glob_match& gm)
56  {
57  if (this != &gm)
58  {
59  pat = gm.pat;
60  fnmatch_flags = gm.fnmatch_flags;
61  }
62  return *this;
63  }
64 
65  ~glob_match (void) { }
66 
67  void set_pattern (const std::string& p) { pat = p; }
68 
69  void set_pattern (const string_vector& p) { pat = p; }
70 
71  bool match (const std::string& str) const;
72 
73  Array<bool> match (const string_vector& str) const
74  {
75  int n = str.length ();
76 
77  Array<bool> retval (dim_vector (n, 1));
78 
79  for (int i = 0; i < n; i++)
80  retval(i) = match (str[i]);
81 
82  return retval;
83  }
84 
85  // We forward to glob_internal here to avoid problems with gnulib's
86  // glob.h defining glob to be rpl_glob.
87 
88  string_vector glob (void) const;
89 
90 private:
91 
92  // Globbing pattern(s).
94 
95  // Option flags.
97 
98  int opts_to_fnmatch_flags (unsigned int xopts) const;
99 };
100 
101 #endif