From 2f8c4fd21e700eb3a87b36dc405bcd2360c99eba Mon Sep 17 00:00:00 2001 From: andersen Date: Fri, 29 Oct 1999 00:07:31 +0000 Subject: Stuff git-svn-id: svn://busybox.net/trunk/busybox@65 69ca8d6d-28ef-0310-b511-8ec308f3f277 --- regexp.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'regexp.c') diff --git a/regexp.c b/regexp.c index 6017d79b4..deee238ec 100644 --- a/regexp.c +++ b/regexp.c @@ -25,6 +25,28 @@ extern int find_match(char *haystack, char *needle, int ignoreCase) return( status); } +/* This performs substitutions after a regexp match has been found. + * The new string is returned. It is malloc'ed, and do must be freed. */ +extern char* replace_match(char *haystack, char *needle, char *newNeedle, int ignoreCase) +{ + int status; + char* newHaystack; + struct regexp* re; + newHaystack = (char *)malloc((unsigned)(strlen(haystack) - + strlen(needle) + strlen(newNeedle)); + re = regcomp( needle); + status = regexec(re, haystack, FALSE, ignoreCase); + + return( newHaystack) +} + + +extern void regsub(regexp* re, char* src, char* dst) + + free( re); + return( status); +} + /* code swiped from elvis-tiny 1.4 (a clone of vi) and adjusted to * suit the needs of busybox by Erik Andersen. -- cgit v1.2.3-55-g6feb