Changeset 41c9a96 for fmtext.c


Ignore:
Timestamp:
Jul 24, 2009, 12:59:23 AM (15 years ago)
Author:
Anders Kaseorg <andersk@mit.edu>
Branches:
master, release-1.10, 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
  • fmtext.c

    r4d86e06 r41c9a96  
    285285  char attr;
    286286  short fg, bg, pair;
    287   int search_results, search_len;
    288287 
    289288  if (w==NULL) {
     
    292291  }
    293292
    294   search_results = (do_search
    295                     ? owl_fmtext_search(f, owl_global_get_search_string(&g))
    296                     : 0);
    297   search_len = (search_results
    298                 ? strlen(owl_global_get_search_string(&g))
    299                 : 0);
    300293  s = f->textbuff;
    301294  /* Set default attributes. */
     
    316309      tmp = p[0];
    317310      p[0] = '\0';
    318       if (search_results) {
     311      if (owl_global_is_search_active(&g)) {
    319312        /* Search is active, so highlight search results. */
    320         char tmp2, *ss;
    321         ss = stristr(s, owl_global_get_search_string(&g));
    322         while (ss) {
     313        char tmp2;
     314        int start, end;
     315        while (owl_regex_compare(owl_global_get_search_re(&g), s, &start, &end) == 0) {
    323316          /* Found search string, highlight it. */
    324317
    325           tmp2 = ss[0];
    326           ss[0] = '\0';
     318          tmp2 = s[start];
     319          s[start] = '\0';
    327320          waddstr(w, s);
    328           ss[0] = tmp2;
     321          s[start] = tmp2;
    329322
    330323          _owl_fmtext_wattrset(w, attr ^ OWL_FMTEXT_ATTR_REVERSE);
    331324          _owl_fmtext_wcolor_set(w, pair);
    332325         
    333           tmp2 = ss[search_len];
    334           ss[search_len] = '\0';
    335           waddstr(w, ss);
    336           ss[search_len] = tmp2;
     326          tmp2 = s[end];
     327          s[end] = '\0';
     328          waddstr(w, s + start);
     329          s[end] = tmp2;
    337330
    338331          _owl_fmtext_wattrset(w, attr);
    339332          _owl_fmtext_wcolor_set(w, pair);
    340333
    341           s = ss + search_len;
    342           ss = stristr(s, owl_global_get_search_string(&g));
     334          s += end;
    343335        }
    344336      }
     
    563555 *  insensitive search.
    564556 */
    565 int owl_fmtext_search(owl_fmtext *f, char *string)
    566 {
    567   if (stristr(f->textbuff, string)) return(1);
     557int owl_fmtext_search(owl_fmtext *f, owl_regex *re)
     558{
     559  if (owl_regex_compare(re, f->textbuff, NULL, NULL) == 0) return(1);
    568560  return(0);
    569561}
Note: See TracChangeset for help on using the changeset viewer.