GNU Octave 7.1.0
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-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_glob_match_h)
27#define octave_glob_match_h 1
28
29#include "octave-config.h"
30
31#include <string>
32
33#include "Array.h"
34#include "str-vec.h"
35
36class
39{
40public:
41
42 enum opts
43 {
44 pathname = 1, // No wildcard can ever match '/'.
45 noescape = 2, // Backslashes don't quote special chars.
46 period = 4 // Leading '.' is matched only explicitly.
47 };
48
49 glob_match (const std::string& p,
50 unsigned int xopts = pathname | noescape | period)
51 : m_pat (p), m_fnmatch_flags (opts_to_fnmatch_flags (xopts))
52 { }
53
55 unsigned int xopts = pathname | noescape | period)
56 : m_pat (p), m_fnmatch_flags (opts_to_fnmatch_flags (xopts))
57 { }
58
59 glob_match (const glob_match& gm) = default;
60
61 glob_match& operator = (const glob_match& gm) = default;
62
63 ~glob_match (void) = default;
64
65 void set_pattern (const std::string& p) { m_pat = p; }
66
67 void set_pattern (const string_vector& p) { m_pat = p; }
68
69 bool match (const std::string& str) const;
70
71 Array<bool> match (const string_vector& str) const
72 {
73 int n = str.numel ();
74
75 Array<bool> retval (dim_vector (n, 1));
76
77 for (int i = 0; i < n; i++)
78 retval(i) = match (str[i]);
79
80 return retval;
81 }
82
83 // We forward to glob_internal here to avoid problems with gnulib's
84 // glob.h defining glob to be rpl_glob.
85
86 string_vector glob (void) const;
87
88private:
89
90 // Globbing pattern(s).
92
93 // Option flags.
95
96 int opts_to_fnmatch_flags (unsigned int xopts) const;
97};
98
99#endif
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
glob_match(const std::string &p, unsigned int xopts=pathname|noescape|period)
Definition: glob-match.h:49
~glob_match(void)=default
glob_match(const glob_match &gm)=default
string_vector m_pat
Definition: glob-match.h:91
void set_pattern(const std::string &p)
Definition: glob-match.h:65
int m_fnmatch_flags
Definition: glob-match.h:94
Array< bool > match(const string_vector &str) const
Definition: glob-match.h:71
glob_match(const string_vector &p=string_vector(), unsigned int xopts=pathname|noescape|period)
Definition: glob-match.h:54
void set_pattern(const string_vector &p)
Definition: glob-match.h:67
octave_idx_type numel(void) const
Definition: str-vec.h:100
#define OCTAVE_API
Definition: main.in.cc:55
string_vector glob(const string_vector &pat)
Definition: oct-glob.cc:82