X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fregex-quote.h;h=948699518baaa3769d0b5546bb2bcc063abfed7d;hb=cd56634a4a8179fd5a4419fbb3e27211b042ab1c;hp=e1e2a64ac1450e9bf5fc77605570f67aeb75804e;hpb=d60f3b0c6b0f93a601acd1cfd3923f94ca05abb0;p=gnulib.git diff --git a/lib/regex-quote.h b/lib/regex-quote.h index e1e2a64ac..948699518 100644 --- a/lib/regex-quote.h +++ b/lib/regex-quote.h @@ -1,5 +1,5 @@ /* Construct a regular expression from a literal string. - Copyright (C) 1995, 2010-2011 Free Software Foundation, Inc. + Copyright (C) 1995, 2010-2014 Free Software Foundation, Inc. Written by Bruno Haible , 2010. This program is free software: you can redistribute it and/or modify @@ -15,27 +15,74 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef _REGEX_QUOTE_H +#define _REGEX_QUOTE_H + #include +#include + + +/* Specifies a quotation task for converting a fixed string to a regular + expression pattern. */ +struct regex_quote_spec +{ + /* True if the regular expression pattern consists of multibyte characters + (in the encoding given by the LC_CTYPE category of the locale), + false if it consists of single bytes or UTF-8 characters. */ + unsigned int /*bool*/ multibyte : 1; + /* True if the regular expression pattern shall match only entire lines. */ + unsigned int /*bool*/ anchored : 1; + /* Set of characters that need to be escaped (all ASCII), as a + NUL-terminated string. */ + char special[30 + 1]; +}; -/* regex_quote converts a literal string to a regular expression that will - look for this literal string. - cflags can be 0 or REG_EXTENDED. + +/* Creates a quotation task that produces a POSIX regular expression, that is, + a pattern that can be compiled with regcomp(). + CFLAGS can be 0 or REG_EXTENDED. If it is 0, the result is a Basic Regular Expression (BRE) . If it is REG_EXTENDED, the result is an Extended Regular Expression (ERE) . - The result is not anchored; if you want it to match only complete lines, - you need to add "^" at the beginning of the result and "$" at the end of the - result. - */ + If ANCHORED is false, the regular expression will match substrings of lines. + If ANCHORED is true, it will match only complete lines, */ +extern struct regex_quote_spec + regex_quote_spec_posix (int cflags, bool anchored); + +/* Creates a quotation task that produces a regular expression that can be + compiled with the GNU API function re_compile_pattern(). + SYNTAX describes the syntax of the regular expression (such as + RE_SYNTAX_POSIX_BASIC, RE_SYNTAX_POSIX_EXTENDED, RE_SYNTAX_EMACS, all + defined in ). It must be the same value as 're_syntax_options' + at the moment of the re_compile_pattern() call. + If ANCHORED is false, the regular expression will match substrings of lines. + If ANCHORED is true, it will match only complete lines, */ +extern struct regex_quote_spec + regex_quote_spec_gnu (unsigned long /*reg_syntax_t*/ syntax, bool anchored); + +/* Creates a quotation task that produces a PCRE regular expression, that is, + a pattern that can be compiled with pcre_compile(). + OPTIONS is the same value as the second argument passed to pcre_compile(). + If ANCHORED is false, the regular expression will match substrings of lines. + If ANCHORED is true, it will match only complete lines, */ +extern struct regex_quote_spec + regex_quote_spec_pcre (int options, bool anchored); + /* Returns the number of bytes needed for the quoted string. */ -extern size_t regex_quote_length (const char *string, int cflags); +extern size_t + regex_quote_length (const char *string, const struct regex_quote_spec *spec); /* Copies the quoted string to p and returns the incremented p. - There must be room for regex_quote_length (string, cflags) + 1 bytes at p. - */ -extern char * regex_quote_copy (char *p, const char *string, int cflags); + There must be room for regex_quote_length (string, spec) + 1 bytes at p. */ +extern char * + regex_quote_copy (char *p, + const char *string, const struct regex_quote_spec *spec); /* Returns the freshly allocated quoted string. */ -extern char * regex_quote (const char *string, int cflags); +extern char * + regex_quote (const char *string, const struct regex_quote_spec *spec); + + +#endif /* _REGEX_QUOTE_H */