Previous: , Up: regexps   [Contents][Index]


3.5 Inspecting regular expressions related errors

Function: int cre2_error_code (const cre2_regexp_t * rex)

In case an error occurred while building rex: return an integer representing the associated error code. Return zero if no error occurred.

Function: const char * cre2_error_string (const cre2_regexp_t * rex)

If an error occurred while building rex: return a pointer to an ASCIIZ string representing the associated error message. The returned pointer is valid only while rex is alive: if cre2_delete() is applied to rex the pointer becomes invalid.

If rex is a successfully built regular expression object: return a pointer to an empty string.

The following code:

cre2_regexp_t *   rex;

rex = cre2_new("ci(ao", 5, NULL);
{
  printf("error: code=%d, msg=\"%s\"\n",
         cre2_error_code(rex),
         cre2_error_string(rex));
}
cre2_delete(rex);

prints:

error: code=6, msg="missing ): ci(ao"
Function: void cre2_error_arg (const cre2_regexp_t * rex, cre2_string_t * arg)

If an error occurred while building rex: fill the structure referenced by arg with the interval of bytes representing the offending portion of the pattern.

If rex is a successfully built regular expression object: arg references an empty string.

The following code:

cre2_regexp_t *   rex;
cre2_string_t     S;

rex = cre2_new("ci(ao", 5, NULL);
{
  cre2_error_arg(rex, &S);
  printf("arg: len=%d, data=\"%s\"\n", S.length, S.data);
}
cre2_delete(rex);

prints:

arg: len=5 data="ci(ao"

Previous: , Up: regexps   [Contents][Index]

This document describes version 0.4.0-devel.2 of CRE2.