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

rpl_str_t rpl_regex_replace ( rpl_regex_t *  re_p,
rpl_str_t  str,
rpl_str_t  subst_str 

Performs text replacement using an RE. TODO: global flag does not work - instead a loop has to be entered to get the global replacements (see quote_ampersand function in parser.c for an example)

re_p The regular expression to use on the text.
str The string to do the replacement on.
subst_str The string to substitute for.

Definition at line 245 of file regex.c.

References rpl_me_malloc(), rpl_regex_capture_info(), and rpl_regex_match().

Referenced by rpl_index_escape_ampersands().

    rpl_str_t replace_str;
    size_t   len, subst_len, new_len;
    int      startPos, endPos;

    assert (re_p != NULL);

    if (!rpl_regex_match (re_p, str, 0))
        return NULL;

    len = strlen (str);
    subst_len = strlen (subst_str);

    rpl_regex_capture_info (re_p, 1, &startPos, &endPos);
    new_len = len + endPos - startPos + subst_len;
    replace_str = (rpl_str_t) rpl_me_malloc (new_len);
    strncpy (replace_str, str, startPos);
    strcat (replace_str, subst_str);
    strncat (replace_str, &str [endPos], len - endPos);

    return replace_str;

Generated by  Doxygen 1.6.0   Back to index