regify utility  2.0.0-0
Regular Expressions

These functions facilitate regular expression functionality as it is provided by ICU http://site.icu-project.org/. More...

Typedefs

typedef enum ruRegexFlag_ ruRegexFlag
 Constants for Regular Expression Match Modes. More...
 
typedef void * ruRegex
 Opaque pointer to regular expression object. More...
 

Enumerations

enum  ruRegexFlag_ {
  RUREGEX_NULL = 0 , RUREGEX_CANON_EQ = 128 , RUREGEX_CASE_INSENSITIVE = 2 , RUREGEX_COMMENTS = 4 ,
  RUREGEX_DOTALL = 32 , RUREGEX_LITERAL = 16 , RUREGEX_MULTILINE = 8 , RUREGEX_UNIX_LINES = 1 ,
  RUREGEX_UWORD = 256 , RUREGEX_ERROR_ON_UNKNOWN_ESCAPES = 512
}
 Constants for Regular Expression Match Modes. More...
 

Functions

RUAPI ruRegex ruRegexFree (ruRegex rr)
 Frees up the resources of the given ruRegex object. More...
 
RUAPI ruRegex ruRegexNew (const char *pattern, ruRegexFlag flags, int32_t *code)
 Creates a new regular expression object to be used with ruRegex(Replace|Match|...) free with ruRegexFree after use. More...
 
RUAPI char * ruRegexReplace (ruRegex rr, const char *original, const char *replacement, int32_t *code)
 Replace the found expression instances in original with the content found in replacement and return the result. More...
 
RUAPI bool ruRegexMatch (ruRegex rr, const char *original, int32_t *code)
 Indicates whether the given original matches the entire expression in rr. More...
 
RUAPI bool ruRegexFind (ruRegex rr, const char *original, int32_t *code)
 Indicates whether the given original matches the part of the expression in rr. More...
 
RUAPI ruList ruRegexMatchGroups (ruRegex rr, const char *original, int32_t *code)
 Returns the matches found in the given original if it matched the entire expression in rr. More...
 
RUAPI ruList ruRegexFindGroups (ruRegex rr, const char *original, int32_t *code)
 Returns the matches found in the given original if it matched part of the expression in rr. More...
 

Detailed Description

These functions facilitate regular expression functionality as it is provided by ICU http://site.icu-project.org/.

Example:

int32_t exp = RUE_OK;
ruRegex rr = NULL;
ruList matches = NULL;
do {
rr = ruRegexNew("^(\\w+)^", RUREGEX_CASE_INSENSITIVE, &ret);
if (ret != RUE_OK) break;
char *orig = "text with a ^tag^ in it.";
matches = ruRegexFindGroups(rr, orig, &ret);
if (ret != RUE_OK) break;
char *entry = ruListIdx(matches, 1, char*, &ret);
if (ret != RUE_OK) break;
printf("group 1: %s", entry);
} while(0);
// clean up
if (matches) ruListFree(matches);
if (rr) ruRegexFree(rr);
RUAPI ruList ruListFree(ruList rl)
Frees the given list object.
void * ruList
Opaque pointer to list object. See List Collection.
Definition: list.h:103
#define ruListIdx(rl, index, type, code)
Returns the data payload of the element at given 0 based index casted to type.
Definition: list.h:427
RUAPI ruRegex ruRegexFree(ruRegex rr)
Frees up the resources of the given ruRegex object.
RUAPI ruList ruRegexFindGroups(ruRegex rr, const char *original, int32_t *code)
Returns the matches found in the given original if it matched part of the expression in rr.
void * ruRegex
Opaque pointer to regular expression object.
Definition: regex.h:131
RUAPI ruRegex ruRegexNew(const char *pattern, ruRegexFlag flags, int32_t *code)
Creates a new regular expression object to be used with ruRegex(Replace|Match|...) free with ruRegexF...
@ RUREGEX_CASE_INSENSITIVE
Definition: regex.h:79
#define RUE_OK
Definition: errors.h:66

Typedef Documentation

◆ ruRegex

typedef void* ruRegex

Opaque pointer to regular expression object.

◆ ruRegexFlag

typedef enum ruRegexFlag_ ruRegexFlag

Constants for Regular Expression Match Modes.

These are mirrored from ICU to avoid having to pull the entire includes folders when using regify-utils.

Enumeration Type Documentation

◆ ruRegexFlag_

Constants for Regular Expression Match Modes.

These are mirrored from ICU to avoid having to pull the entire includes folders when using regify-utils.

Enumerator
RUREGEX_NULL 

Represents no flags when passing this type as a parameter.

RUREGEX_CANON_EQ 

Forces normalization of pattern and strings. Not implemented yet, just a placeholder, hence draft.

RUREGEX_CASE_INSENSITIVE 

Enable case insensitive matching.

RUREGEX_COMMENTS 

Allow white space and comments within patterns

RUREGEX_DOTALL 

If set, '.' matches line terminators, otherwise '.' matching stops at line end.

RUREGEX_LITERAL 

If set, treat the entire pattern as a literal string. Metacharacters or escape sequences in the input sequence will be given no special meaning.

The flag RUREGEX_CASE_INSENSITIVE retains its impact on matching when used in conjunction with this flag. The other flags become superfluous.

RUREGEX_MULTILINE 

Control behavior of "$" and "^" If set, recognize line terminators within string, otherwise, match only at start and end of input string.

RUREGEX_UNIX_LINES 

Unix-only line endings. When this mode is enabled, only \u000a is recognized as a line ending in the behavior of ., ^, and $.

RUREGEX_UWORD 

Unicode word boundaries. If set, uses the Unicode TR 29 definition of word boundaries. Warning: Unicode word boundaries are quite different from traditional regular expression word boundaries. See http://unicode.org/reports/tr29/#Word_Boundaries

RUREGEX_ERROR_ON_UNKNOWN_ESCAPES 

Error on Unrecognized backslash escapes. If set, fail with an error on patterns that contain backslash-escaped ASCII letters without a known special meaning. If this flag is not set, these escaped letters represent themselves.

Function Documentation

◆ ruRegexFind()

RUAPI bool ruRegexFind ( ruRegex  rr,
const char *  original,
int32_t *  code 
)

Indicates whether the given original matches the part of the expression in rr.

Parameters
rrThe ruRegex object to use.
originalThe source string to match.
code(Optional) Where the return result of this operation such as RUE_OK on success will be stored.
Returns
true or false depending on whether there was a match.

◆ ruRegexFindGroups()

RUAPI ruList ruRegexFindGroups ( ruRegex  rr,
const char *  original,
int32_t *  code 
)

Returns the matches found in the given original if it matched part of the expression in rr.

Parameters
rrThe ruRegex object to use.
originalThe source string to match.
code(Optional) Where the return result of this operation such as RUE_OK on success will be stored.
Returns
List of matches or NULL if there was no match. List must be freed after use.

◆ ruRegexFree()

RUAPI ruRegex ruRegexFree ( ruRegex  rr)

Frees up the resources of the given ruRegex object.

Parameters
rrobject to free.

◆ ruRegexMatch()

RUAPI bool ruRegexMatch ( ruRegex  rr,
const char *  original,
int32_t *  code 
)

Indicates whether the given original matches the entire expression in rr.

Parameters
rrThe ruRegex object to use.
originalThe source string to match.
code(Optional) Where the return result of this operation such as RUE_OK on success will be stored.
Returns
true or false depending on whether there was a match.

◆ ruRegexMatchGroups()

RUAPI ruList ruRegexMatchGroups ( ruRegex  rr,
const char *  original,
int32_t *  code 
)

Returns the matches found in the given original if it matched the entire expression in rr.

Parameters
rrThe ruRegex object to use.
originalThe source string to match.
code(Optional) Where the return result of this operation such as RUE_OK on success will be stored.
Returns
List of matches or NULL if there was no match. List must be freed after use.

◆ ruRegexNew()

RUAPI ruRegex ruRegexNew ( const char *  pattern,
ruRegexFlag  flags,
int32_t *  code 
)

Creates a new regular expression object to be used with ruRegex(Replace|Match|...) free with ruRegexFree after use.

Parameters
patternThe pattern representing the regular expression without delimiters.
flagsFlags influencing the behavior of the expression. These are from ICU and we provide ruRegexFlag.
code(Optional) Where the return result of this operation such as RUE_OK on success will be stored.
Returns
The newly created ruRegex object or NULL on failure.

◆ ruRegexReplace()

RUAPI char* ruRegexReplace ( ruRegex  rr,
const char *  original,
const char *  replacement,
int32_t *  code 
)

Replace the found expression instances in original with the content found in replacement and return the result.

Parameters
rrThe ruRegex object to use.
originalThe source string to replace
replacementThe replacement string for found matches in original.
code(Optional) Where the return result of this operation such as RUE_OK on success will be stored.
Returns
A newly allocated string that results out of the replacement. Free with ruFree.