2 * regexp.h: wrappers for regexp handling
4 * Copyright (C) 2009-2016 David Lutterkort
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Author: David Lutterkort <lutter@redhat.com>
32 struct string *pattern;
33 struct re_pattern_buffer *re;
34 unsigned int nocase : 1;
37 void print_regexp(FILE *out, struct regexp *regexp);
39 /* Make a regexp with pattern PAT, which is not copied. Ownership
42 struct regexp *make_regexp(struct info *info, char *pat, int nocase);
44 /* Make a regexp with pattern PAT, which is copied. Ownership of INFO is
45 * taken. Escape sequences like \n in PAT are interpreted.
47 struct regexp *make_regexp_unescape(struct info *info, const char *pat,
50 /* Return 1 if R is an empty pattern, i.e. one consisting of nothing but
51 '(' and ')' characters, 0 otherwise */
52 int regexp_is_empty_pattern(struct regexp *r);
54 /* Make a regexp that matches TEXT literally; the string TEXT
55 * is not used by the returned rgexp and must be freed by the caller
57 struct regexp *make_regexp_literal(struct info *info, const char *text);
59 /* Make a regexp from a glob pattern */
60 struct regexp *make_regexp_from_glob(struct info *info, const char *glob);
62 /* Do not call directly, use UNREF instead */
63 void free_regexp(struct regexp *regexp);
65 /* Compile R->PATTERN into R->RE; return -1 and print an error
66 * if compilation fails. Return 0 otherwise
68 int regexp_compile(struct regexp *r);
70 /* Check the syntax of R->PATTERN; return -1 if the pattern has a syntax
71 * error, and a string indicating the error in *C. Return 0 if the pattern
72 * is a valid regular expression.
74 int regexp_check(struct regexp *r, const char **msg);
76 /* Call RE_MATCH on R->RE and return its result; if R hasn't been compiled
77 * yet, compile it. Return -3 if compilation fails
79 int regexp_match(struct regexp *r, const char *string, const int size,
80 const int start, struct re_registers *regs);
82 /* Return 1 if R matches the empty string, 0 otherwise */
83 int regexp_matches_empty(struct regexp *r);
85 /* Return the number of subexpressions (parentheses) inside R. May cause
86 * compilation of R; return -1 if compilation fails.
88 int regexp_nsub(struct regexp *r);
91 regexp_union(struct info *, struct regexp *r1, struct regexp *r2);
94 regexp_concat(struct info *, struct regexp *r1, struct regexp *r2);
97 regexp_union_n(struct info *, int n, struct regexp **r);
100 regexp_concat_n(struct info *, int n, struct regexp **r);
103 regexp_iter(struct info *info, struct regexp *r, int min, int max);
105 /* Return a new REGEXP that matches all the words matched by R1 but
109 regexp_minus(struct info *info, struct regexp *r1, struct regexp *r2);
112 regexp_maybe(struct info *info, struct regexp *r);
114 struct regexp *regexp_make_empty(struct info *);
116 /* Free up temporary data structures, most importantly compiled
117 regular expressions */
118 void regexp_release(struct regexp *regexp);
120 /* Produce a printable representation of R. The result will in general not
121 be equivalent to the passed regular expression, but be easier for
123 char *regexp_escape(const struct regexp *r);
125 /* If R is case-insensitive, expand its pattern so that it matches the same
126 * string even when used in a case-sensitive match. */
127 char *regexp_expand_nocase(struct regexp *r);
133 * indent-tabs-mode: nil