PCREs: regex matching helpers
Structures
| Name | |
|---|---|
| struct | N_PCRE N_PCRE structure. |
Functions
| Name | |
|---|---|
| N_STR * | npcre_replace(N_PCRE * pcre, const char * subject, size_t subject_len, const char * replacement) thread-safe regex substitute: replace every match in subject (binary-safe, subject_len bytes) using a replacement template with $N / ${N} capture-group references (pcre2_substitute, global). |
| N_PCRE * | npcre_new(char * str, int flags) pcre helper, compile and optimize regexp |
| int | npcre_match_capture(char * str, N_PCRE * pcre) thread-safe pcre match with captures stored in pcre->match_list |
| int | npcre_match(char * str, N_PCRE * pcre) thread-safe pcre match, only returns TRUE/FALSE, no captures stored |
| int | npcre_delete(N_PCRE ** pcre) pcre helper, delete/free a compiled regexp |
| int | npcre_clean_match(N_PCRE * pcre) clean match results from a previous npcre_match_capture |
| int | _npcre_print_error(int LOG_LEVEL, const char * file, const char * func, int line, int rc) print error helper |
Functions Documentation
function npcre_replace
N_STR * npcre_replace(
N_PCRE * pcre,
const char * subject,
size_t subject_len,
const char * replacement
)
thread-safe regex substitute: replace every match in subject (binary-safe, subject_len bytes) using a replacement template with $N / ${N} capture-group references (pcre2_substitute, global).
Returns a new N_STR (free with free_nstr), or NULL on error.
function npcre_new
N_PCRE * npcre_new(
char * str,
int flags
)
pcre helper, compile and optimize regexp
Parameters:
- str The string containing the regexp
- flags pcre_compile flags
Return: a filled N_PCRE struct or NULL
From pcre doc, the flag bits are: PCRE_ANCHORED Force pattern anchoring PCRE_AUTO_CALLOUT Compile automatic callouts PCRE_BSR_ANYCRLF \R matches only CR, LF, or CRLF PCRE_BSR_UNICODE \R matches all Unicode line endings PCRE_CASELESS Do caseless matching PCRE_DOLLAR_ENDONLY $ not to match newline at end PCRE_DOTALL .
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
function npcre_match_capture
int npcre_match_capture(
char * str,
N_PCRE * pcre
)
thread-safe pcre match with captures stored in pcre->match_list
Parameters:
- str String to test against the regexp
- pcre The N_PCRE regexp holder
Return: TRUE or FALSE
Return TRUE if str matches regexp, and make captures.
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.
function npcre_match
int npcre_match(
char * str,
N_PCRE * pcre
)
thread-safe pcre match, only returns TRUE/FALSE, no captures stored
Parameters:
- str String to test against the regexp
- pcre The N_PCRE regexp holder (read-only access to regexp field)
Return: TRUE or FALSE
Thread-safe match: returns TRUE/FALSE without modifying the N_PCRE struct.
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.
function npcre_delete
int npcre_delete(
N_PCRE ** pcre
)
pcre helper, delete/free a compiled regexp
Parameters:
- pcre The N_PCRE regexp holder
Return: TRUE or FALSE
Free a N_PCRE pointer.
pcre helper, delete/free a compiled regexp
function npcre_clean_match
int npcre_clean_match(
N_PCRE * pcre
)
clean match results from a previous npcre_match_capture
Parameters:
- pcre The N_PCRE regexp holder
Return: TRUE or FALSE
clean the match list of the last capture, if any
clean match results from a previous npcre_match_capture
function _npcre_print_error
int _npcre_print_error(
int LOG_LEVEL,
const char * file,
const char * func,
int line,
int rc
)
print error helper
Parameters:
- LOG_LEVEL The log level to use when printing errors. Note: non error will always be printed in LOG_DEBUG
- file name of the file which called the function
- func name of the calling function
- line line in the file
- rc the code to test
Return: 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
print error associated to pcre error code
print error helper
Modules
- AABB3D
- ACCEPT_POOL
- ALLEGRO4
- ALLEGRO5
- ANIM_LIB
- ASTAR
- ATLAS_LIB
- AVRO
- CLOCK_SYNC
- COMMONS
- CONFIGFILE
- CYPHER_BASE64
- CYPHER_VIGENERE
- DEAD_RECKONING
- ENUMS
- EXCEPTIONS
- GAME_ENV
- GIT
- GUI
- HASH_TABLE
- ISOMETRIC_ENGINE
- LIST
- LOG
- LOGNODUP
- LZ4
- NETWORKING
- NETWORK_MSG
- N_COOKIES
- N_DIFF
- N_DIGEST
- N_DISK_CACHE
- N_DNS
- N_ECC
- N_ENTROPY
- N_FILES
- N_FLUIDS
- N_GUI_COLOR
- N_GUI_COLORWHEEL
- N_GUI_CURVE
- N_GUI_GRID
- N_GUI_POPUP
- N_HEX
- N_HTTP3
- N_HTTP_COOKIE
- N_HTTP_FORM
- N_HTTP_MIME
- N_HTTP_REQ
- N_HTTP_RESP
- N_HTTP_ROUTER
- N_HTTP_SERVER
- N_ICC
- N_JSON
- N_KAFKA
- N_LINALG
- N_MODULE
- N_OPENSSL_COMPAT
- N_PRETTY
- N_PTH
- N_QUERY
- N_RANDOM
- N_SHA256
- N_STR
- N_TIFF
- N_TIME
- N_USER
- N_X509
- N_ZIP
- PARTICLES
- PCRE
- PHYSICS
- SIGNALS
- STACK
- THREADS
- TRAJECTORY
- TREE
- ZLIB