annotate lib/regex-quote.h @ 40186:8964917f9574

autoupdate
author Karl Berry <karl@freefriends.org>
date Mon, 18 Feb 2019 08:02:49 -0800
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13728
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Construct a regular expression from a literal string.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 1995, 2010-2019 Free Software Foundation, Inc.
13728
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <haible@clisp.cons.org>, 2010.
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 (at your option) any later version.
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
13728
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
14410
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
18 #ifndef _REGEX_QUOTE_H
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
19 #define _REGEX_QUOTE_H
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
20
13728
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <stddef.h>
14410
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
22 #include <stdbool.h>
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
23
13728
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
14410
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
25 /* Specifies a quotation task for converting a fixed string to a regular
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
26 expression pattern. */
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
27 struct regex_quote_spec
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
28 {
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
29 /* True if the regular expression pattern consists of multibyte characters
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
30 (in the encoding given by the LC_CTYPE category of the locale),
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
31 false if it consists of single bytes or UTF-8 characters. */
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
32 unsigned int /*bool*/ multibyte : 1;
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
33 /* True if the regular expression pattern shall match only entire lines. */
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
34 unsigned int /*bool*/ anchored : 1;
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
35 /* Set of characters that need to be escaped (all ASCII), as a
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
36 NUL-terminated string. */
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
37 char special[30 + 1];
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
38 };
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
39
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
40
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
41 /* Creates a quotation task that produces a POSIX regular expression, that is,
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
42 a pattern that can be compiled with regcomp().
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
43 CFLAGS can be 0 or REG_EXTENDED.
13728
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 If it is 0, the result is a Basic Regular Expression (BRE)
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 <http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03>.
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 If it is REG_EXTENDED, the result is an Extended Regular Expression (ERE)
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 <http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04>.
14410
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
48 If ANCHORED is false, the regular expression will match substrings of lines.
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
49 If ANCHORED is true, it will match only complete lines, */
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
50 extern struct regex_quote_spec
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
51 regex_quote_spec_posix (int cflags, bool anchored);
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
52
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
53 /* Creates a quotation task that produces a regular expression that can be
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
54 compiled with the GNU API function re_compile_pattern().
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
55 SYNTAX describes the syntax of the regular expression (such as
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
56 RE_SYNTAX_POSIX_BASIC, RE_SYNTAX_POSIX_EXTENDED, RE_SYNTAX_EMACS, all
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
57 defined in <regex.h>). It must be the same value as 're_syntax_options'
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
58 at the moment of the re_compile_pattern() call.
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
59 If ANCHORED is false, the regular expression will match substrings of lines.
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
60 If ANCHORED is true, it will match only complete lines, */
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
61 extern struct regex_quote_spec
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
62 regex_quote_spec_gnu (unsigned long /*reg_syntax_t*/ syntax, bool anchored);
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
63
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
64 /* Creates a quotation task that produces a PCRE regular expression, that is,
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
65 a pattern that can be compiled with pcre_compile().
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
66 OPTIONS is the same value as the second argument passed to pcre_compile().
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
67 If ANCHORED is false, the regular expression will match substrings of lines.
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
68 If ANCHORED is true, it will match only complete lines, */
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
69 extern struct regex_quote_spec
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
70 regex_quote_spec_pcre (int options, bool anchored);
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
71
13728
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 /* Returns the number of bytes needed for the quoted string. */
14410
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
74 extern size_t
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
75 regex_quote_length (const char *string, const struct regex_quote_spec *spec);
13728
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 /* Copies the quoted string to p and returns the incremented p.
14410
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
78 There must be room for regex_quote_length (string, spec) + 1 bytes at p. */
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
79 extern char *
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
80 regex_quote_copy (char *p,
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
81 const char *string, const struct regex_quote_spec *spec);
13728
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82
e67e8c083d6d New module 'regex-quote'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 /* Returns the freshly allocated quoted string. */
14410
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
84 extern char *
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
85 regex_quote (const char *string, const struct regex_quote_spec *spec);
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
86
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
87
0a972f366396 regex-quote: New API.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
88 #endif /* _REGEX_QUOTE_H */