root/maint/gnulib/lib/regex-quote.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /* Construct a regular expression from a literal string.
   2    Copyright (C) 1995, 2010-2021 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 <https://www.gnu.org/licenses/>.  */
  17 
  18 #ifndef _REGEX_QUOTE_H
  19 #define _REGEX_QUOTE_H
  20 
  21 #include <stdbool.h>
  22 #include <stdlib.h>
  23 
  24 
  25 /* Specifies a quotation task for converting a fixed string to a regular
  26    expression pattern.  */
  27 struct regex_quote_spec
  28 {
  29   /* True if the regular expression pattern consists of multibyte characters
  30      (in the encoding given by the LC_CTYPE category of the locale),
  31      false if it consists of single bytes or UTF-8 characters.  */
  32   unsigned int /*bool*/ multibyte : 1;
  33   /* True if the regular expression pattern shall match only entire lines.  */
  34   unsigned int /*bool*/ anchored : 1;
  35   /* Set of characters that need to be escaped (all ASCII), as a
  36      NUL-terminated string.  */
  37   char special[30 + 1];
  38 };
  39 
  40 
  41 /* Creates a quotation task that produces a POSIX regular expression, that is,
  42    a pattern that can be compiled with regcomp().
  43    CFLAGS can be 0 or REG_EXTENDED.
  44    If it is 0, the result is a Basic Regular Expression (BRE)
  45    <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03>.
  46    If it is REG_EXTENDED, the result is an Extended Regular Expression (ERE)
  47    <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04>.
  48    If ANCHORED is false, the regular expression will match substrings of lines.
  49    If ANCHORED is true, it will match only complete lines,  */
  50 extern struct regex_quote_spec
  51        regex_quote_spec_posix (int cflags, bool anchored);
  52 
  53 /* Creates a quotation task that produces a regular expression that can be
  54    compiled with the GNU API function re_compile_pattern().
  55    SYNTAX describes the syntax of the regular expression (such as
  56    RE_SYNTAX_POSIX_BASIC, RE_SYNTAX_POSIX_EXTENDED, RE_SYNTAX_EMACS, all
  57    defined in <regex.h>).  It must be the same value as 're_syntax_options'
  58    at the moment of the re_compile_pattern() call.
  59    If ANCHORED is false, the regular expression will match substrings of lines.
  60    If ANCHORED is true, it will match only complete lines,  */
  61 extern struct regex_quote_spec
  62        regex_quote_spec_gnu (unsigned long /*reg_syntax_t*/ syntax, bool anchored);
  63 
  64 /* Creates a quotation task that produces a PCRE regular expression, that is,
  65    a pattern that can be compiled with pcre_compile().
  66    OPTIONS is the same value as the second argument passed to pcre_compile().
  67    If ANCHORED is false, the regular expression will match substrings of lines.
  68    If ANCHORED is true, it will match only complete lines,  */
  69 extern struct regex_quote_spec
  70        regex_quote_spec_pcre (int options, bool anchored);
  71 
  72 
  73 /* Returns the number of bytes needed for the quoted string.  */
  74 extern size_t
  75        regex_quote_length (const char *string, const struct regex_quote_spec *spec);
  76 
  77 /* Copies the quoted string to p and returns the incremented p.
  78    There must be room for regex_quote_length (string, spec) + 1 bytes at p.  */
  79 extern char *
  80        regex_quote_copy (char *restrict p,
  81                          const char *string, const struct regex_quote_spec *spec);
  82 
  83 /* Returns the freshly allocated quoted string.  */
  84 extern char *
  85        regex_quote (const char *string, const struct regex_quote_spec *spec)
  86        _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
  87        _GL_ATTRIBUTE_RETURNS_NONNULL;
  88 
  89 
  90 #endif /* _REGEX_QUOTE_H */

/* [previous][next][first][last][top][bottom][index][help] */