mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-20 18:10:07 +00:00
regex iterate
This commit is contained in:
parent
a399b382fa
commit
f2d7ef2945
2 changed files with 6 additions and 3 deletions
|
|
@ -9,8 +9,8 @@ typedef mv_t lrec_evaluator_func_t(lrec_t* prec, context_t* pctx, void* pvstate)
|
|||
|
||||
typedef struct _lrec_evaluator_t {
|
||||
void* pvstate;
|
||||
// xxx needs a pfree_func too
|
||||
lrec_evaluator_func_t* pevaluator_func;
|
||||
// xxx needs a pfree_func too
|
||||
} lrec_evaluator_t;
|
||||
|
||||
#endif // LREC_EVALUATOR_H
|
||||
|
|
|
|||
|
|
@ -847,6 +847,7 @@ mv_t ge_op_func(mv_t* pval1, mv_t* pval2) { return (ge_dispositions[pval1->type]
|
|||
mv_t lt_op_func(mv_t* pval1, mv_t* pval2) { return (lt_dispositions[pval1->type][pval2->type])(pval1, pval2); }
|
||||
mv_t le_op_func(mv_t* pval1, mv_t* pval2) { return (le_dispositions[pval1->type][pval2->type])(pval1, pval2); }
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
mv_t matches_op_func(mv_t* pval1, mv_t* pval2) {
|
||||
char* s1 = pval1->u.strv;
|
||||
char* s2 = pval2->u.strv;
|
||||
|
|
@ -855,7 +856,7 @@ mv_t matches_op_func(mv_t* pval1, mv_t* pval2) {
|
|||
regex_t reg;
|
||||
char* sstr = s1;
|
||||
char* sregex = s2;
|
||||
int cflags = REG_EXTENDED; // also support REG_ICASE somehow
|
||||
int cflags = REG_EXTENDED | REG_NOSUB; // xxx also support REG_ICASE somehow
|
||||
regmatch_t pmatch[1];
|
||||
int eflags = 0;
|
||||
int rc;
|
||||
|
|
@ -870,16 +871,18 @@ mv_t matches_op_func(mv_t* pval1, mv_t* pval2) {
|
|||
}
|
||||
|
||||
rc = regexec(®, sstr, 1, pmatch, eflags);
|
||||
regfree(®);
|
||||
if (rc == 0) {
|
||||
regfree(®);
|
||||
return (mv_t) {.type = MT_BOOL, .u.boolv = TRUE};
|
||||
} else if (rc == REG_NOMATCH) {
|
||||
regfree(®);
|
||||
return (mv_t) {.type = MT_BOOL, .u.boolv = FALSE};
|
||||
} else {
|
||||
size_t nbytes = regerror(rc, ®, NULL, 0);
|
||||
char* errbuf = malloc(nbytes);
|
||||
(void)regerror(rc, ®, errbuf, nbytes);
|
||||
printf("regexec failure: %s\n", errbuf);
|
||||
regfree(®);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue