Esempio n. 1
0
/**
 * Make sub-string replacing by regular expression matching
 *
 * @param __re - compiled regular expression
 * @param __s - source string
 * @param __mask - mask of replacement
 * @return replaced string on success, NULL otherwise
 * @sideeffect allocate memory for return value
 */
char*
preg_replace (const char *__regexp, const char *__s, const char *__mask)
{
    regexp_t *re;
    char *result;

    re = regexp_compile (__regexp);

    if (!re)
    {
        return NULL;
    }

    result = regexp_replace (re, __s, __mask);

    regexp_free (re);

    return result;
}
Esempio n. 2
0
TEST(no_infinite_loop_on_empty_global_match, IF(not_osx))
{
	/* On OS X, regular expressions which can match empty strings don't
	 * compile. */
	assert_string_equal("zbarfoobar", regexp_replace("barfoobar", "", "z", 1, 0));
}