Changeset 41c9a96 for regex.c


Ignore:
Timestamp:
Jul 24, 2009, 12:59:23 AM (12 years ago)
Author:
Anders Kaseorg <andersk@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
64c9165
Parents:
ab225e0
git-author:
Anders Kaseorg <andersk@mit.edu> (07/24/09 00:51:10)
git-committer:
Anders Kaseorg <andersk@mit.edu> (07/24/09 00:59:23)
Message:
Reimplement search in terms of owl_regex.

The current implementation of stristr has problems and there isn’t a
good replacement available.  This was its only caller, so we can get
rid of it now.

Also, this will make it possible to search with arbitrary regexes if
someone feels like coming up with a syntax.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • regex.c

    rd43edd2 r41c9a96  
    4646}
    4747
    48 int owl_regex_compare(owl_regex *re, char *string)
     48int owl_regex_compare(owl_regex *re, char *string, int *start, int *end)
    4949{
    5050  int out, ret;
     51  regmatch_t match;
    5152
    5253  /* if the regex is not set we match */
     
    5556  }
    5657 
    57   ret=regexec(&(re->re), string, 0, NULL, 0);
     58  ret=regexec(&(re->re), string, 1, &match, 0);
    5859  out=ret;
    5960  if (re->negate) {
    6061    out=!out;
     62    match.rm_so = 0;
     63    match.rm_eo = strlen(string);
    6164  }
     65  if (start != NULL) *start = match.rm_so;
     66  if (end != NULL) *end = match.rm_eo;
    6267  return(out);
    6368}
     
    7681void owl_regex_copy(owl_regex *a, owl_regex *b)
    7782{
    78   b->negate=a->negate;
    79   b->string=owl_strdup(a->string);
    80   memcpy(&(b->re), &(a->re), sizeof(regex_t));
     83  owl_regex_create(b, a->string);
    8184}
    8285
Note: See TracChangeset for help on using the changeset viewer.