diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-09-25 12:22:07 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-09-25 12:22:07 +0200 |
| commit | cef2c51df7e782452c8e2cc8f32dcb0931b3ac99 (patch) | |
| tree | f1a57876217afdc67de851cdb5db132b756b7da5 /text-objects.c | |
| parent | 4ca158acffb798436ede54b4942d2e4a5212d1a7 (diff) | |
| download | vis-cef2c51df7e782452c8e2cc8f32dcb0931b3ac99.tar.gz vis-cef2c51df7e782452c8e2cc8f32dcb0931b3ac99.tar.xz | |
Add text_object_word_raw which does not include any whitespaces
Diffstat (limited to 'text-objects.c')
| -rw-r--r-- | text-objects.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/text-objects.c b/text-objects.c index 142c01b..0c819ac 100644 --- a/text-objects.c +++ b/text-objects.c @@ -51,6 +51,38 @@ Filerange text_object_word(Text *txt, size_t pos) { return r; } +Filerange text_object_word_raw(Text *txt, size_t pos) { + char c, prev = '0', next = '0'; + Filerange r = text_range_empty(); + Iterator it = text_iterator_get(txt, pos); + if (!text_iterator_byte_get(&it, &c)) + return r; + if (text_iterator_byte_prev(&it, &prev)) + text_iterator_byte_next(&it, NULL); + text_iterator_byte_next(&it, &next); + if (isspace(c)) { + return r; + } else if (isspace(prev) && isspace(next)) { + /* on a single character */ + r.start = pos; + r.end = text_char_next(txt, pos); + } else if (isspace(prev)) { + /* at start of a word */ + r.start = pos; + r.end = text_char_next(txt, text_word_end_next(txt, pos)); + } else if (isspace(next)) { + /* at end of a word */ + r.start = text_word_start_prev(txt, pos); + r.end = text_char_next(txt, pos); + } else { + /* in the middle of a word */ + r.start = text_word_start_prev(txt, pos); + r.end = text_char_next(txt, text_word_end_next(txt, pos)); + } + + return r; +} + Filerange text_object_line(Text *txt, size_t pos) { Filerange r; r.start = text_line_begin(txt, pos); |
