xref: /netbsd-src/external/gpl3/gdb.old/dist/gdbsupport/gdb_regex.h (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
1*6881a400Schristos /* Portable <regex.h>.
2*6881a400Schristos    Copyright (C) 2000-2023 Free Software Foundation, Inc.
3*6881a400Schristos 
4*6881a400Schristos    This file is part of GDB.
5*6881a400Schristos 
6*6881a400Schristos    This program is free software; you can redistribute it and/or modify
7*6881a400Schristos    it under the terms of the GNU General Public License as published by
8*6881a400Schristos    the Free Software Foundation; either version 3 of the License, or
9*6881a400Schristos    (at your option) any later version.
10*6881a400Schristos 
11*6881a400Schristos    This program is distributed in the hope that it will be useful,
12*6881a400Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*6881a400Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*6881a400Schristos    GNU General Public License for more details.
15*6881a400Schristos 
16*6881a400Schristos    You should have received a copy of the GNU General Public License
17*6881a400Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18*6881a400Schristos 
19*6881a400Schristos #ifndef GDB_REGEX_H
20*6881a400Schristos #define GDB_REGEX_H 1
21*6881a400Schristos 
22*6881a400Schristos # include "xregex.h"
23*6881a400Schristos 
24*6881a400Schristos /* A compiled regex.  This is mainly a wrapper around regex_t.  The
25*6881a400Schristos    the constructor throws on regcomp error and the destructor is
26*6881a400Schristos    responsible for calling regfree.  The former means that it's not
27*6881a400Schristos    possible to create an instance of compiled_regex that isn't
28*6881a400Schristos    compiled, hence the name.  */
29*6881a400Schristos class compiled_regex
30*6881a400Schristos {
31*6881a400Schristos public:
32*6881a400Schristos   /* Compile a regexp and throw an exception on error, including
33*6881a400Schristos      MESSAGE.  REGEX and MESSAGE must not be NULL.  */
34*6881a400Schristos   compiled_regex (const char *regex, int cflags,
35*6881a400Schristos 		  const char *message)
36*6881a400Schristos     ATTRIBUTE_NONNULL (2) ATTRIBUTE_NONNULL (4);
37*6881a400Schristos 
38*6881a400Schristos   ~compiled_regex ();
39*6881a400Schristos 
40*6881a400Schristos   DISABLE_COPY_AND_ASSIGN (compiled_regex);
41*6881a400Schristos 
42*6881a400Schristos   /* Wrapper around ::regexec.  */
43*6881a400Schristos   int exec (const char *string,
44*6881a400Schristos 	    size_t nmatch, regmatch_t pmatch[],
45*6881a400Schristos 	    int eflags) const;
46*6881a400Schristos 
47*6881a400Schristos   /* Wrapper around ::re_search.  (Not const because re_search's
48*6881a400Schristos      regex_t parameter isn't either.)  */
49*6881a400Schristos   int search (const char *string, int size, int startpos,
50*6881a400Schristos 	      int range, struct re_registers *regs);
51*6881a400Schristos 
52*6881a400Schristos private:
53*6881a400Schristos   /* The compiled pattern.  */
54*6881a400Schristos   regex_t m_pattern;
55*6881a400Schristos };
56*6881a400Schristos 
57*6881a400Schristos #endif /* not GDB_REGEX_H */
58