diff options
| author | Quentin Carbonneaux | 2014-07-15 22:45:27 -0400 |
|---|---|---|
| committer | Quentin Carbonneaux | 2014-07-15 22:45:27 -0400 |
| commit | 58e756db8aa0ddf03d12b3869bb4f4c1d21a77b4 (patch) | |
| tree | fbdad30ec0b0cb34dbb23f4e3ea9994351c3de0e | |
| parent | ce812164b0443d6fd770f555546ae5ed80b31542 (diff) | |
use dumb string search algorithm
| -rw-r--r-- | edit.c | 25 | ||||
| -rw-r--r-- | edit.h | 2 |
2 files changed, 9 insertions, 18 deletions
@@ -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; } @@ -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 *); |
