silc_subst
SYNOPSIS
SilcBool silc_subst(SilcBuffer buffer, const char *subst);
DESCRIPTION
Regular expression matching and substitution in `buffer' according to the substitution expression `subst'. This function provides Sed (Stream Editor) style substitution interface. The `subst' may be of following formats:
's/REGEXP/REPLACEMENT/FLAGS'
Matches regular expression REGEXP in each line in the buffer and substitutes the match with REPLACEMENT.
'ADDRs/REGEXP/REPLACEMENT/FLAGS'
Selects lines in the buffer matching the address ADDR and matches the regular expression REGEXP in the line and substitutes the match with REPLACEMENT.
The ADDR may be of following format:
/REGEXP/ Matches only lines matching the regular expression NUMBER Matches only the specified line number (1-n) $ Matches only the last line
The FLAGS may be of following format:
no FLAGS Finds first match in the line and replaces that g Finds and replaces all matches in the line
An '!' may precede the 's'. In that case the ADDR is not matched.
Returns TRUE if the match and replacement was done, FALSE in case of error, and sets the silc_errno.
If you need to match and/or replace '/' characters, they must be escaped with '\' (C-style escaping for '\' is '\\').
If you need more versatile ways to modify the buffer you may consider using the SILC_STR_REGEX in SILC Buffer Format API directly. This function only provides basic matching and substitution.
EXAMPLE
// Replace all foos with bar on all lines in the buffer silc_subst(buffer, "s/foo/bar/g");