Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ap_regex.h File Reference

Apache Regex defines. More...

#include "apr.h"
Include dependency graph for ap_regex.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ap_regex_t
 
struct  ap_regmatch_t
 
struct  ap_rxplus_t
 

Macros

#define AP_REG_ICASE   0x01
 
#define AP_REG_NEWLINE   0x02
 
#define AP_REG_NOTBOL   0x04
 
#define AP_REG_NOTEOL   0x08
 
#define AP_REG_EXTENDED   (0)
 
#define AP_REG_NOSUB   (0)
 
#define AP_REG_MULTI   0x10
 
#define AP_REG_NOMEM   0x20
 
#define AP_REG_DOTALL   0x40
 
#define AP_REG_MATCH   "MATCH_"
 

Enumerations

enum  { AP_REG_PCRE_COMPILED = 0, AP_REG_PCRE_LOADED }
 
enum  { AP_REG_ASSERT = 1, AP_REG_ESPACE, AP_REG_INVARG, AP_REG_NOMATCH }
 

Functions

const char * ap_pcre_version_string (int which)
 
int ap_regcomp (ap_regex_t *preg, const char *regex, int cflags)
 
int ap_regexec (const ap_regex_t *preg, const char *string, apr_size_t nmatch, ap_regmatch_t *pmatch, int eflags)
 
int ap_regexec_len (const ap_regex_t *preg, const char *buff, apr_size_t len, apr_size_t nmatch, ap_regmatch_t *pmatch, int eflags)
 
apr_size_t ap_regerror (int errcode, const ap_regex_t *preg, char *errbuf, apr_size_t errbuf_size)
 
int ap_regname (const ap_regex_t *preg, apr_array_header_t *names, const char *prefix, int upper)
 
void ap_regfree (ap_regex_t *preg)
 
ap_rxplus_tap_rxplus_compile (apr_pool_t *pool, const char *pattern)
 
int ap_rxplus_exec (apr_pool_t *pool, ap_rxplus_t *rx, const char *pattern, char **newpattern)
 
int ap_rxplus_nmatch (ap_rxplus_t *rx)
 
void ap_rxplus_match (ap_rxplus_t *rx, int n, int *len, const char **match)
 
char * ap_rxplus_pmatch (apr_pool_t *pool, ap_rxplus_t *rx, int n)
 

Detailed Description

Apache Regex defines.

Macro Definition Documentation

#define AP_REG_DOTALL   0x40

perl's /s flag

#define AP_REG_EXTENDED   (0)

unused

#define AP_REG_ICASE   0x01

use a case-insensitive match

#define AP_REG_MATCH   "MATCH_"

suggested prefix for ap_regname

#define AP_REG_MULTI   0x10

perl's /g (needs fixing)

#define AP_REG_NEWLINE   0x02

don't match newlines against '.' etc

#define AP_REG_NOMEM   0x20

nomem in our code

#define AP_REG_NOSUB   (0)

unused

#define AP_REG_NOTBOL   0x04

^ will not match against start-of-string

#define AP_REG_NOTEOL   0x08

$ will not match against end-of-string

Enumeration Type Documentation

anonymous enum
Enumerator
AP_REG_PCRE_COMPILED 
AP_REG_PCRE_LOADED 

PCRE version used during program compilation PCRE version loaded at runtime

anonymous enum
Enumerator
AP_REG_ASSERT 
AP_REG_ESPACE 

internal error ?

AP_REG_INVARG 

failed to get memory

AP_REG_NOMATCH 

invalid argument match failed

Function Documentation

const char* ap_pcre_version_string ( int  which)

Return PCRE version string.

Parameters
whichEither AP_REG_PCRE_COMPILED (PCRE version used during program compilation) or AP_REG_PCRE_LOADED (PCRE version used at runtime)
Returns
The PCRE version string
int ap_regcomp ( ap_regex_t preg,
const char *  regex,
int  cflags 
)

Compile a regular expression.

Parameters
pregReturned compiled regex
regexThe regular expression string
cflagsBitwise OR of AP_REG_* flags (ICASE and NEWLINE supported, other flags are ignored)
Returns
Zero on success or non-zero on error
apr_size_t ap_regerror ( int  errcode,
const ap_regex_t preg,
char *  errbuf,
apr_size_t  errbuf_size 
)

Return the error code returned by regcomp or regexec into error messages

Parameters
errcodethe error code returned by regexec or regcomp
pregThe precompiled regex
errbufA buffer to store the error in
errbuf_sizeThe size of the buffer
int ap_regexec ( const ap_regex_t preg,
const char *  string,
apr_size_t  nmatch,
ap_regmatch_t pmatch,
int  eflags 
)

Match a NUL-terminated string against a pre-compiled regex.

Parameters
pregThe pre-compiled regex
stringThe string to match
nmatchProvide information regarding the location of any matches
pmatchProvide information regarding the location of any matches
eflagsBitwise OR of AP_REG_* flags (NOTBOL and NOTEOL supported, other flags are ignored)
Returns
0 for successful match, AP_REG_NOMATCH otherwise
int ap_regexec_len ( const ap_regex_t preg,
const char *  buff,
apr_size_t  len,
apr_size_t  nmatch,
ap_regmatch_t pmatch,
int  eflags 
)

Match a string with given length against a pre-compiled regex. The string does not need to be NUL-terminated.

Parameters
pregThe pre-compiled regex
buffThe string to match
lenLength of the string to match
nmatchProvide information regarding the location of any matches
pmatchProvide information regarding the location of any matches
eflagsBitwise OR of AP_REG_* flags (NOTBOL and NOTEOL supported, other flags are ignored)
Returns
0 for successful match, AP_REG_NOMATCH otherwise
void ap_regfree ( ap_regex_t preg)

Destroy a pre-compiled regex.

Parameters
pregThe pre-compiled regex to free.
int ap_regname ( const ap_regex_t preg,
apr_array_header_t names,
const char *  prefix,
int  upper 
)

Return an array of named regex backreferences

Parameters
pregThe precompiled regex
namesThe array to which the names will be added
prefixAn optional prefix to add to the returned names. AP_REG_MATCH is the recommended prefix.
upperIf non zero, uppercase the names
ap_rxplus_t* ap_rxplus_compile ( apr_pool_t pool,
const char *  pattern 
)

Compile a pattern into a regexp. supports perl-like formats match-string /match-string/flags s/match-string/replacement-string/flags Intended to support more perl-like stuff as and when round tuits happen match-string is anything supported by ap_regcomp replacement-string is a substitution string as supported in ap_pregsub flags should correspond with perl syntax: treat failure to do so as a bug (documentation TBD)

Parameters
poolPool to allocate from
patternPattern to compile
Returns
Compiled regexp, or NULL in case of compile/syntax error
int ap_rxplus_exec ( apr_pool_t pool,
ap_rxplus_t rx,
const char *  pattern,
char **  newpattern 
)

Apply a regexp operation to a string.

Parameters
poolPool to allocate from
rxThe regex match to apply
patternThe string to apply it to NOTE: This MUST be kept in scope to use regexp memory
newpatternThe modified string (ignored if the operation doesn't modify the string)
Returns
Number of times a match happens. Normally 0 (no match) or 1 (match found), but may be greater if a transforming pattern is applied with the 'g' flag.
void ap_rxplus_match ( ap_rxplus_t rx,
int  n,
int len,
const char **  match 
)

Get a pointer to a match from regex memory NOTE: this relies on the match pattern from the last call to ap_rxplus_exec still being valid (i.e. not freed or out-of-scope)

Parameters
rxThe regexp
nThe match number to retrieve (must be between 0 and nmatch)
lenReturns the length of the match.
matchReturns the match pattern
int ap_rxplus_nmatch ( ap_rxplus_t rx)

Number of matches in the regexp operation's memory This may be 0 if no match is in memory, or up to nmatch from compilation

Parameters
rxThe regexp
Returns
Number of matches in memory
char* ap_rxplus_pmatch ( apr_pool_t pool,
ap_rxplus_t rx,
int  n 
)

Get a match from regex memory in a string copy NOTE: this relies on the match pattern from the last call to ap_rxplus_exec still being valid (i.e. not freed or out-of-scope)

Parameters
poolPool to allocate from
rxThe regexp
nThe match number to retrieve (must be between 0 and nmatch)
Returns
The matched string