diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-04-21 08:06:55 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-04-21 11:05:45 +0200 |
| commit | aca46a0da8969f15d9356c149687f961b6852516 (patch) | |
| tree | ffc96967c3110d9a684fec302973845e7de2b23d /text-motions.c | |
| parent | 1b1590ed4f33f3da16ff648c7e0f1a45db6811dd (diff) | |
| download | vis-aca46a0da8969f15d9356c149687f961b6852516.tar.gz vis-aca46a0da8969f15d9356c149687f961b6852516.tar.xz | |
Clean up to/till movements
Diffstat (limited to 'text-motions.c')
| -rw-r--r-- | text-motions.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/text-motions.c b/text-motions.c index d2f272c..59b92e0 100644 --- a/text-motions.c +++ b/text-motions.c @@ -45,11 +45,12 @@ size_t text_char_prev(Text *txt, size_t pos) { return it.pos; } -size_t text_find_char_next(Text *txt, size_t pos, const char *s, size_t len) { - char c; - size_t matched = 0; +size_t text_find_next(Text *txt, size_t pos, const char *s) { + if (!s) + return pos; + size_t len = strlen(s), matched = 0; Iterator it = text_iterator_get(txt, pos); - while (matched < len && text_iterator_byte_get(&it, &c)) { + for (char c; matched < len && text_iterator_byte_get(&it, &c); ) { if (c == s[matched]) matched++; else @@ -59,13 +60,14 @@ size_t text_find_char_next(Text *txt, size_t pos, const char *s, size_t len) { return matched == len ? it.pos - len : pos; } -size_t text_find_char_prev(Text *txt, size_t pos, const char *s, size_t len) { - char c; - size_t matched = len - 1; +size_t text_find_prev(Text *txt, size_t pos, const char *s) { + if (!s) + return pos; + size_t len = strlen(s), matched = len - 1; Iterator it = text_iterator_get(txt, pos); if (len == 0) return pos; - while (text_iterator_byte_get(&it, &c)) { + for (char c; text_iterator_byte_get(&it, &c); ) { if (c == s[matched]) { if (matched == 0) break; |
