67 pcre -> captured = 0 ;
73 pcre -> match_list = NULL ;
75 pcre -> regexp_str = strdup( str );
78 pcre -> ovecount = max_cap ;
79 Malloc( pcre -> ovector,
int, 3 * max_cap );
82 const char *error = NULL ;
85 pcre -> regexp = pcre_compile( str, flags, &error, &erroroffset, NULL ) ;
88 n_log(
LOG_ERR,
" pcre compilation of %s failed at offset %d : %s", str, erroroffset, error );
93 pcre -> extra = pcre_study( pcre -> regexp, 0, &error );
111 if( (*pcre) -> ovector )
113 Free( (*pcre) -> ovector );
115 if( (*pcre) -> regexp )
117 pcre_free( (*pcre) -> regexp );
118 (*pcre) -> regexp = NULL ;
121 pcre_free_study( (*pcre) -> extra );
122 (*pcre) -> extra = NULL ;
124 pcre_free( (*pcre) -> extra );
125 (*pcre) -> extra = NULL ;
127 if( (*pcre) -> captured > 0 )
129 pcre_free_substring_list( (*pcre) -> match_list );
147 __n_assert( pcre -> match_list,
return FALSE );
149 if( pcre -> captured > 0 )
151 pcre -> captured = 0 ;
152 pcre_free_substring_list( pcre -> match_list );
169 __n_assert( pcre -> regexp_str,
return FALSE );
173 len = ( int )strlen( str ) ;
175 rc = pcre_exec( pcre -> regexp, pcre -> extra, str, len, 0, 0, pcre -> ovector, pcre -> ovecount );
180 case PCRE_ERROR_NOMATCH :
break;
181 case PCRE_ERROR_NULL :
n_log(
LOG_DEBUG ,
"Something was null");
break;
182 case PCRE_ERROR_BADOPTION :
n_log(
LOG_DEBUG ,
"A bad option was passed");
break;
183 case PCRE_ERROR_BADMAGIC :
n_log(
LOG_DEBUG ,
"Magic number bad (compiled re corrupt?)");
break;
184 case PCRE_ERROR_UNKNOWN_NODE :
n_log(
LOG_DEBUG ,
"Something kooky in the compiled regexp");
break;
185 case PCRE_ERROR_NOMEMORY :
n_log(
LOG_DEBUG ,
"Ran out of memory");
break;
193 rc = pcre -> ovecount ;
199 pcre -> captured = rc ;
200 pcre_get_substring_list( str, pcre -> ovector, rc, &pcre -> match_list );
#define FreeNoLog(__ptr)
Free Handler without log.
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define Free(__ptr)
Free Handler to get errors.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
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...
int npcre_match(char *str, N_PCRE *pcre)
Return TRUE if str matches regexp, and make captures up to max_cap.
int npcre_clean_match(N_PCRE *pcre)
clean the match list of the last capture, if any
int npcre_delete(N_PCRE **pcre)
Free a N_PCRE pointer.
PCRE helpers for regex matching.