Logo Search packages:      
Sourcecode: rapple version File versions  Download package

rpl_regex_t* rpl_regex_create ( rpl_str_t  pattern,
unsigned  flags 
)

Creates a regular expression object.

Parameters:
pattern String containing the RE pattern.
flags The flags to be used by the RE.

Definition at line 46 of file regex.c.

References rpl_me_malloc(), RPL_REGEX_FLAG_IGNORE_CASE, and RPL_REGEX_FLAG_MULTILINE.

Referenced by rpl_index_escape_ampersands().

{
    int           pcreflags = 0;
    rpl_c_str_t    perrormsg_p;
    int           errorOffset;
    rpl_regex_t * re_p
        = (rpl_regex_t *) rpl_me_malloc (sizeof (struct rpl_regex_s));

    if (flags & RPL_REGEX_FLAG_IGNORE_CASE)
    {
        pcreflags |= PCRE_CASELESS;
    }

    if (flags & RPL_REGEX_FLAG_MULTILINE)
    {
        pcreflags |= PCRE_MULTILINE;
    }

    re_p->pcre_pm = pcre_compile (pattern,
                                  pcreflags,
                                  &perrormsg_p,
                                  &errorOffset,
                                  NULL);

    /* pcre_compile() failed with perrormsg_p */
    assert (re_p->pcre_pm != NULL);

    // Get number of subpatterns that will be returned
    pcre_fullinfo (re_p->pcre_pm,
                   NULL,
                   PCRE_INFO_CAPTURECOUNT,
                   &re_p->num_sub_patterns_m);

    re_p->ovec_size_m = (re_p->num_sub_patterns_m + 1) * 3; // see pcre docs
    re_p->ovector_pam = (int *) rpl_me_malloc (re_p->ovec_size_m * sizeof (int));
    return re_p;
}


Generated by  Doxygen 1.6.0   Back to index