Lazy RE
Classes | Macros | Functions
lazy_re.c File Reference

Lazy RE. More...

#include <sys/types.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lazy_re.h"

Classes

struct  RegexCache
 Represents Regex cache. More...
 

Macros

#define REGEX_ASSERT(condition, msg)   assert((condition) || !printf("REGEX_ERROR: %s\n", msg))
 Assert to check regex functions input parameters. More...
 

Functions

void Regex_compile (regex_t *regex, const char *pattern, const int cflags)
 Compiles regex. More...
 
void Regex_free (regex_t *regex)
 Frees memory allocated for regex. More...
 
bool Regex_test (const char *pattern, const char *string)
 Test whether pattern presents in a string. More...
 
RegexMatchRegex_compiledSearch (regex_t *regex, const char *string, const int eflags)
 Search a first occurrence of a regex in a string. More...
 
RegexMatchRegex_search (const char *pattern, const char *string, const int eflags)
 Search first occurrence of a pattern in a string. More...
 
RegexMatchRegex_searchNext ()
 Performs next search from cache of the last successful one. More...
 

Detailed Description

Lazy RE.

It is based on POSIX regular expression:

http://www.regular-expressions.info/posix.html

Special characters: .[{}()\*+?|^$

Macro Definition Documentation

#define REGEX_ASSERT (   condition,
  msg 
)    assert((condition) || !printf("REGEX_ERROR: %s\n", msg))

Assert to check regex functions input parameters.

Parameters
conditionAssert condition.
msgPointer to string with message.

Function Documentation

void Regex_compile ( regex_t *  regex,
const char *  pattern,
const int  cflags 
)

Compiles regex.

Regex cflags reference http://www.gnu.org/software/libc/manual/html_node/Flags-for-POSIX-Regexps.html#Flags-for-POSIX-Regexps

Parameters
regexPointer to a struct with regex.
patternString containing regex.
cflagsRegex flags with which regex is created.
RegexMatch* Regex_compiledSearch ( regex_t *  regex,
const char *  string,
const int  eflags 
)

Search a first occurrence of a regex in a string.

Regex eflags reference http://www.gnu.org/software/libc/manual/html_node/Matching-POSIX-Regexps.html#Matching-POSIX-Regexps

Parameters
regexRegex which will be used to match.
stringString against which to perform match.
eflagsRegex flags with which to match.
Returns
Match with groups if pattern is found. 0 Otherwise.
void Regex_free ( regex_t *  regex)

Frees memory allocated for regex.

Parameters
regexRegex struct.
RegexMatch* Regex_search ( const char *  pattern,
const char *  string,
const int  eflags 
)

Search first occurrence of a pattern in a string.

Regex eflags reference http://www.gnu.org/software/libc/manual/html_node/Matching-POSIX-Regexps.html#Matching-POSIX-Regexps

Parameters
regexPattern which will be used to match.
stringString against which to perform match.
eflagsRegex flags with which to match.
Returns
Match with groups if pattern is found. 0 Otherwise.
RegexMatch* Regex_searchNext ( )

Performs next search from cache of the last successful one.

Note
Make sure to call Regex_search before calling this one.
Returns
Match with groups if pattern is found. 0 Otherwise.
bool Regex_test ( const char *  pattern,
const char *  string 
)

Test whether pattern presents in a string.

Parameters
regexPattern which will be used to match.
stringString against which to perform match.
Return values
trueIf pattern is found.
falseotherwise.