Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
PCREs: regex matching helpers

Data Structures

struct  N_PCRE
 N_PCRE structure. More...
 

Functions

int _npcre_print_error (int LOG_LEVEL, const char *file, const char *func, int line, int rc)
 print error helper
 
int npcre_clean_match (N_PCRE *pcre)
 clean match results from a previous npcre_match_capture
 
int npcre_delete (N_PCRE **pcre)
 pcre helper, delete/free a compiled regexp
 
int npcre_match (char *str, N_PCRE *pcre)
 thread-safe pcre match, only returns TRUE/FALSE, no captures stored
 
int npcre_match_capture (char *str, N_PCRE *pcre)
 thread-safe pcre match with captures stored in pcre->match_list
 
N_PCREnpcre_new (char *str, int flags)
 pcre helper, compile and optimize regexp
 

Detailed Description


Data Structure Documentation

◆ N_PCRE

struct N_PCRE

N_PCRE structure.

Examples
ex_gui_dictionary.c, and ex_pcre.c.

Definition at line 93 of file n_pcre.h.

+ Collaboration diagram for N_PCRE:
Data Fields
int captured flag for match_list cleaning
pcre2_match_data * match_data match data storage (ovector, etc.)
PCRE2_UCHAR8 ** match_list populated match list (NULL-terminated) after npcre_match_capture() Allocated by PCRE2 via pcre2_substring_list_get() and must be freed with pcre2_substring_list_free().
pcre2_code * regexp regexp
char * regexp_str original regexp string
pthread_rwlock_t rwlock rwlock protecting match_data, match_list, and captured

Function Documentation

◆ _npcre_print_error()

int _npcre_print_error ( int  LOG_LEVEL,
const char *  file,
const char *  func,
int  line,
int  rc 
)

print error helper

print error helper

Parameters
LOG_LEVELThe log level to use when printing errors. Note: non error will always be printed in LOG_DEBUG
filename of the file which called the function
funcname of the calling function
lineline in the file
rcthe code to test
Returns
TRUE if everything was OK and no errors, FALSE if an error was decoded, or if it couldn't get the exact error and printed default

Definition at line 187 of file n_pcre.c.

References _n_log(), LOG_DEBUG, and LOG_LEVEL.

Referenced by npcre_match_capture().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ npcre_clean_match()

int npcre_clean_match ( N_PCRE pcre)

clean match results from a previous npcre_match_capture

clean match results from a previous npcre_match_capture

Parameters
pcreThe N_PCRE regexp holder
Returns
TRUE or FALSE

Definition at line 164 of file n_pcre.c.

References __n_assert, N_PCRE::captured, N_PCRE::match_list, PCRE2_LIST_FREE_CAST, N_PCRE::rwlock, unlock, and write_lock.

Referenced by main(), and main().

+ Here is the caller graph for this function:

◆ npcre_delete()

int npcre_delete ( N_PCRE **  pcre)

pcre helper, delete/free a compiled regexp

pcre helper, delete/free a compiled regexp

Parameters
pcreThe N_PCRE regexp holder
Returns
TRUE or FALSE

Definition at line 134 of file n_pcre.c.

References __n_assert, FreeNoLog, PCRE2_LIST_FREE_CAST, rw_lock_destroy, unlock, and write_lock.

Referenced by load_config_file(), main(), main(), and npcre_new().

+ Here is the caller graph for this function:

◆ npcre_match()

int npcre_match ( char *  str,
N_PCRE pcre 
)

thread-safe pcre match, only returns TRUE/FALSE, no captures stored

thread-safe pcre match, only returns TRUE/FALSE, no captures stored

Uses a local pcre2_match_data so multiple threads can safely share the same compiled N_PCRE pattern. No captures are stored.

Parameters
strString to test against the regexp
pcreThe N_PCRE regexp holder (read-only access to regexp field)
Returns
TRUE or FALSE

Definition at line 226 of file n_pcre.c.

References __n_assert, LOG_ERR, n_log, and N_PCRE::regexp.

◆ npcre_match_capture()

int npcre_match_capture ( char *  str,
N_PCRE pcre 
)

thread-safe pcre match with captures stored in pcre->match_list

thread-safe pcre match with captures stored in pcre->match_list

Thread-safe: uses a rwlock to serialize access to match_data, match_list, captured. The caller must read pcre->match_list/captured before the next call to npcre_match_capture() or npcre_clean_match() on the same N_PCRE, as those will overwrite/free the previous results.

Parameters
strString to test against the regexp
pcreThe N_PCRE regexp holder
Returns
TRUE or FALSE

Definition at line 261 of file n_pcre.c.

References __n_assert, _npcre_print_error(), N_PCRE::captured, LOG_DEBUG, LOG_ERR, N_PCRE::match_data, N_PCRE::match_list, n_log, PCRE2_LIST_FREE_CAST, N_PCRE::regexp, N_PCRE::regexp_str, N_PCRE::rwlock, unlock, and write_lock.

Referenced by load_config_file(), main(), and main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ npcre_new()

N_PCRE * npcre_new ( char *  str,
int  flags 
)

pcre helper, compile and optimize regexp

pcre helper, compile and optimize regexp

matches anything including NL PCRE_DUPNAMES Allow duplicate names for subpatterns PCRE_EXTENDED Ignore white space and # comments PCRE_EXTRA PCRE extra features (not much use currently) PCRE_FIRSTLINE Force matching to be before newline PCRE_JAVASCRIPT_COMPAT JavaScript compatibility PCRE_MULTILINE ^ and $ match newlines within data PCRE_NEWLINE_ANY Recognize any Unicode newline sequence PCRE_NEWLINE_ANYCRLF Recognize CR, LF, and CRLF as newline sequences PCRE_NEWLINE_CR Set CR as the newline sequence PCRE_NEWLINE_CRLF Set CRLF as the newline sequence PCRE_NEWLINE_LF Set LF as the newline sequence PCRE_NO_AUTO_CAPTURE Disable numbered capturing paren- theses (named ones available) PCRE_NO_UTF16_CHECK Do not check the pattern for UTF-16 validity (only relevant if PCRE_UTF16 is set) PCRE_NO_UTF32_CHECK Do not check the pattern for UTF-32 validity (only relevant if PCRE_UTF32 is set) PCRE_NO_UTF8_CHECK Do not check the pattern for UTF-8 validity (only relevant if PCRE_UTF8 is set) PCRE_UCP Use Unicode properties for backslash-d, backslash-w, etc. PCRE_UNGREEDY Invert greediness of quantifiers PCRE_UTF16 Run in pcre16_compile() UTF-16 mode PCRE_UTF32 Run in pcre32_compile() UTF-32 mode PCRE_UTF8 Run in pcre_compile() UTF-8 mode

new N_PCRE object with given parameters

Parameters
strThe string containing the regexp
flagspcre_compile flags
Returns
a filled N_PCRE struct or NULL

Definition at line 80 of file n_pcre.c.

References __n_assert, N_PCRE::captured, init_lock, LOG_ERR, Malloc, N_PCRE::match_data, N_PCRE::match_list, n_log, npcre_delete(), N_PCRE::regexp, N_PCRE::regexp_str, and N_PCRE::rwlock.

Referenced by load_config_file(), main(), and main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: