summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Carbonneaux2014-07-15 22:45:27 -0400
committerQuentin Carbonneaux2014-07-15 22:45:27 -0400
commit58e756db8aa0ddf03d12b3869bb4f4c1d21a77b4 (patch)
treefbdad30ec0b0cb34dbb23f4e3ea9994351c3de0e
parentce812164b0443d6fd770f555546ae5ed80b31542 (diff)
use dumb string search algorithm
-rw-r--r--edit.c25
-rw-r--r--edit.h2
2 files changed, 9 insertions, 18 deletions
diff --git a/edit.c b/edit.c
index 9d83879..5b3a62b 100644
--- a/edit.c
+++ b/edit.c
@@ -296,27 +296,18 @@ eb_getmark(EBuf *eb, Rune name)
}
unsigned
-eb_look(EBuf *eb, unsigned p, Rune *str, int n)
+eb_look(EBuf *eb, unsigned p, Rune *str, unsigned n)
{
- int tbl[n], i, j;
+ unsigned i, j;
assert(str && n >= 0);
- /* String search using Knuth-Morris-Pratt. */
- i = 0, j = -1;
- tbl[i] = j;
- while(i < n) {
- while (j >= 0 && str[i] != str[j])
- j = tbl[j];
- i++, j++;
- tbl[i] = j;
- }
- for (i = 0; p < eb->b.limbo; ) {
- while (i >= 0 && buf_get(&eb->b, p) != str[i])
- i = tbl[i];
- p++, i++;
- if (i == n)
- return p - i;
+ while (p<eb->b.limbo) {
+ i = p++;
+ j = 0;
+ while (buf_get(&eb->b, i++) == str[j++])
+ if (j == n)
+ return p-1;
}
return -1u;
}
diff --git a/edit.h b/edit.h
index 889b393..740d1d3 100644
--- a/edit.h
+++ b/edit.h
@@ -37,7 +37,7 @@ void eb_undo(EBuf *, int, unsigned *);
void eb_yank(EBuf *, unsigned, unsigned, YBuf *);
void eb_setmark(EBuf *, Rune, unsigned);
unsigned eb_getmark(EBuf *, Rune);
-unsigned eb_look(EBuf *, unsigned, Rune *, int);
+unsigned eb_look(EBuf *, unsigned, Rune *, unsigned);
int eb_read(EBuf *, char *);
int eb_write(EBuf *);