|
NAMEsed_compile , sed_exec ,
sed_free —
string editor
SYNOPSIS#include <strfunc.h>
char *
svect *
void
DESCRIPTIONThese routines implement a subset of sed(1) or Perl's s///, y/// and // functionality.You must compule your expression with
EXPRESSIONSCurrently, this library supports two types of string transformations and one type of string match.
Expressions of this type are defined in the following BNF: <delim> := '/' | <other_character> <regex> := <regular_expression, re_format(7)> <to> := <string> <flags> := *( 'g' | 'i' | 'e' | 'r' | 'm' | 'n' ) <expr> := s <delim> <regex> <delim> <to> <delim> <flags>
<delim> := '/' | <other_character> <flags> := *( 'i' ) <expr> := y <delim> <string> <delim> <string> <delim> <flags>
<delim> := '/' | <other_character> <flags> := *( 'i' | 'r' | 'm' | 'n' ) <reply> := <string> <expr> := <delim> <string> <delim> [ <reply> <delim>] <flags> sed_exec ()
will return a NULL pointer, <reply> otherwise. s/// and y/// functions
will never return a NULL pointer.
Flags are common to those transformations.
EXAMPLEvoid main() { sed_t *se1; sed_t *se2; sed_t *se3; char *r1, *r2, r3; /* Compile expressions */ se1 = sed_compile("s/(tree) (apple)/\\2 \\1/igr"); se2 = sed_compile("y/abc/AbC/i"); se3 = sed_compile("/apple/i"); r1 = sed_exec(se1, "Tree Apple"); r2 = sed_exec(se2, "abcabc"); r3 = sed_exec(se3, "another apple tree"); /* ** This will produce: ** "Apple Tree\nAbCAbC\n1\n" */ printf("%s\n%s\n%d\n", r1, r2, r3?1:0); /* ** This will produce: ** "[Tree Apple], [Tree], [Apple]\n" */ printf("[%s]\n", sjoin(sed_results(se1), "], [")); /* Free the resources */ sed_free(se1); sed_free(se2); sed_free(se3); }; SEE ALSOstrfunc(3).AUTHORSLev Walkin <vlm@lionet.info>
Visit the GSP FreeBSD Man Page Interface. |