Merge branch 'upstream' into stable
[gnulib.git] / lib / regex-quote.h
1 /* Construct a regular expression from a literal string.
2    Copyright (C) 1995, 2010 Free Software Foundation, Inc.
3    Written by Bruno Haible <haible@clisp.cons.org>, 2010.
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18 #include <stddef.h>
19
20 /* regex_quote converts a literal string to a regular expression that will
21    look for this literal string.
22    cflags can be 0 or REG_EXTENDED.
23    If it is 0, the result is a Basic Regular Expression (BRE)
24    <http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03>.
25    If it is REG_EXTENDED, the result is an Extended Regular Expression (ERE)
26    <http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04>.
27    The result is not anchored; if you want it to match only complete lines,
28    you need to add "^" at the beginning of the result and "$" at the end of the
29    result.
30  */
31
32 /* Returns the number of bytes needed for the quoted string.  */
33 extern size_t regex_quote_length (const char *string, int cflags);
34
35 /* Copies the quoted string to p and returns the incremented p.
36    There must be room for regex_quote_length (string, cflags) + 1 bytes at p.
37  */
38 extern char * regex_quote_copy (char *p, const char *string, int cflags);
39
40 /* Returns the freshly allocated quoted string.  */
41 extern char * regex_quote (const char *string, int cflags);