From e4fc2780f776db0a2134655247a080e48f77e05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 12 Feb 2016 18:34:39 +0100 Subject: text-object: simplify text_object_range implementation We can copy the initial iterator and use it in reverse direction. --- text-objects.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'text-objects.c') diff --git a/text-objects.c b/text-objects.c index a6d2230..d1abecb 100644 --- a/text-objects.c +++ b/text-objects.c @@ -292,13 +292,12 @@ Filerange text_object_backtick(Text *txt, size_t pos) { Filerange text_object_range(Text *txt, size_t pos, int (*isboundary)(int)) { char c; size_t start; - Iterator it = text_iterator_get(txt, pos); - if (!text_iterator_byte_get(&it, &c) || boundary(c)) + Iterator it = text_iterator_get(txt, pos), rit = it; + if (!text_iterator_byte_get(&rit, &c) || boundary(c)) return text_range_empty(); - do start = it.pos; while (text_iterator_char_prev(&it, &c) && !boundary(c)); - it = text_iterator_get(txt, pos); - text_iterator_byte_get(&it, &c); - while (!boundary(c) && text_iterator_byte_next(&it, &c)); + char tmp = c; + do start = rit.pos; while (text_iterator_char_prev(&rit, &c) && !boundary(c)); + for (c = tmp; !boundary(c) && text_iterator_byte_next(&it, &c);); return text_range_new(start, it.pos); } -- cgit v1.2.3