GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
glob-match.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_glob_match_h)
24 #define octave_glob_match_h 1
25 
26 #include "octave-config.h"
27 
28 #include <string>
29 
30 #include "Array.h"
31 #include "str-vec.h"
32 
33 class
34 OCTAVE_API
36 {
37 public:
38 
39  enum opts
40  {
41  pathname = 1, // No wildcard can ever match '/'.
42  noescape = 2, // Backslashes don't quote special chars.
43  period = 4 // Leading '.' is matched only explicitly.
44  };
45 
47  unsigned int xopts = pathname | noescape | period)
48  : pat (p), fnmatch_flags (opts_to_fnmatch_flags (xopts)) { }
49 
51  unsigned int xopts = pathname | noescape | period)
52  : pat (p), fnmatch_flags (opts_to_fnmatch_flags (xopts)) { }
53 
54  glob_match (const glob_match& gm)
55  : pat (gm.pat), fnmatch_flags (gm.fnmatch_flags) { }
56 
57  glob_match& operator = (const glob_match& gm)
58  {
59  if (this != &gm)
60  {
61  pat = gm.pat;
62  fnmatch_flags = gm.fnmatch_flags;
63  }
64  return *this;
65  }
66 
67  ~glob_match (void) = default;
68 
69  void set_pattern (const std::string& p) { pat = p; }
70 
71  void set_pattern (const string_vector& p) { pat = p; }
72 
73  bool match (const std::string& str) const;
74 
76  {
77  int n = str.numel ();
78 
79  Array<bool> retval (dim_vector (n, 1));
80 
81  for (int i = 0; i < n; i++)
82  retval(i) = match (str[i]);
83 
84  return retval;
85  }
86 
87  // We forward to glob_internal here to avoid problems with gnulib's
88  // glob.h defining glob to be rpl_glob.
89 
90  string_vector glob (void) const;
91 
92 private:
93 
94  // Globbing pattern(s).
96 
97  // Option flags.
99 
100  int opts_to_fnmatch_flags (unsigned int xopts) const;
101 };
102 
103 #endif
void set_pattern(const string_vector &p)
Definition: glob-match.h:71
glob_match(const string_vector &p=string_vector(), unsigned int xopts=pathname|noescape|period)
Definition: glob-match.h:50
Array< bool > match(const string_vector &str) const
Definition: glob-match.h:75
glob_match(const std::string &p, unsigned int xopts=pathname|noescape|period)
Definition: glob-match.h:46
std::string str
Definition: hash.cc:118
octave_value retval
Definition: data.cc:6246
int fnmatch_flags
Definition: glob-match.h:98
p
Definition: lu.cc:138
void set_pattern(const std::string &p)
Definition: glob-match.h:69
glob_match(const glob_match &gm)
Definition: glob-match.h:54
for i
Definition: data.cc:5264
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
string_vector pat
Definition: glob-match.h:95
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
string_vector glob(const string_vector &pat)
Definition: oct-glob.cc:70