Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_pcre.c

Nilorea Library pcre api test.

Nilorea Library pcre api test

Author
Castagnier Mickael
Version
1.0
Date
04/12/2019
#include "nilorea/n_log.h"
#include "nilorea/n_pcre.h"
int main(int argc, char** argv) {
n_log(LOG_INFO, "Starting !");
if (argc < 3) {
n_log(LOG_ERR, "Not enough args\nUsage:\n %s \"regexp\" \"string\"", argv[0]);
exit(1);
}
N_PCRE* pcre = npcre_new(argv[1], 99, 0);
if (npcre_match(argv[2], pcre) == TRUE) {
n_log(LOG_INFO, "MATCHED !");
if (pcre->captured > 1) {
n_log(LOG_INFO, "CAPTURED !");
int it = 0;
while (pcre->match_list[it]) {
n_log(LOG_INFO, "Match[%d]:%s", it, pcre->match_list[it]);
it++;
}
}
} else {
n_log(LOG_INFO, "NO MATCH !");
}
npcre_delete(&pcre);
exit(0);
}
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
Definition n_log.h:69
#define LOG_DEBUG
debug-level messages
Definition n_log.h:64
#define LOG_ERR
error conditions
Definition n_log.h:56
#define LOG_STDERR
internal, default LOG_TYPE
Definition n_log.h:30
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
Definition n_log.c:91
#define LOG_INFO
informational
Definition n_log.h:62
int captured
flag for match_list cleaning
Definition n_pcre.h:42
const char ** match_list
populated match list if nPcreCapMatch is called
Definition n_pcre.h:40
N_PCRE * npcre_new(char *str, int max_cap, int flags)
From pcre doc, the flag bits are: PCRE_ANCHORED Force pattern anchoring PCRE_AUTO_CALLOUT Compile aut...
Definition n_pcre.c:58
int npcre_match(char *str, N_PCRE *pcre)
Return TRUE if str matches regexp, and make captures up to max_cap.
Definition n_pcre.c:149
int npcre_delete(N_PCRE **pcre)
Free a N_PCRE pointer.
Definition n_pcre.c:101
N_PCRE structure.
Definition n_pcre.h:27
Generic log system.
PCRE helpers for regex matching.