vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 914bdcd17a7f16518f6f66851213384ff4c2e6c2
parent a3cee0d120b3794f53e696bda8e50ddaaa2115f7
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed,  3 Feb 2016 13:02:07 +0100

text-object: hide ugly casts for isspace behind a #define

Diffstat:
Mtext-objects.c | 9+++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/text-objects.c b/text-objects.c @@ -20,6 +20,7 @@ #include "text-util.h" #include "util.h" +#define space(c) (isspace((unsigned char)c)) #define isboundry is_word_boundry Filerange text_object_entire(Text *txt, size_t pos) { @@ -48,7 +49,7 @@ static Filerange text_object_customword(Text *txt, size_t pos, int (*isboundry)( if (text_iterator_byte_prev(&it, &prev)) text_iterator_byte_next(&it, NULL); text_iterator_byte_next(&it, &next); - if (isspace((unsigned char)c)) { + if (space(c)) { r.start = text_char_next(txt, text_customword_end_prev(txt, pos, isboundry)); r.end = text_customword_start_next(txt, pos, isboundry); } else if (isboundry(prev) && isboundry(next)) { @@ -94,7 +95,7 @@ static Filerange text_object_customword_outer(Text *txt, size_t pos, int (*isbou if (text_iterator_byte_prev(&it, &prev)) text_iterator_byte_next(&it, NULL); text_iterator_byte_next(&it, &next); - if (isspace((unsigned char)c)) { + if (space(c)) { /* middle of two words, include leading white space */ r.start = text_char_next(txt, text_customword_end_prev(txt, pos, isboundry)); r.end = text_char_next(txt, text_customword_end_next(txt, pos, isboundry)); @@ -304,10 +305,10 @@ Filerange text_range_inner(Text *txt, Filerange *rin) { char c; Filerange r = *rin; Iterator it = text_iterator_get(txt, rin->start); - while (text_iterator_byte_get(&it, &c) && isspace((unsigned char)c)) + while (text_iterator_byte_get(&it, &c) && space(c)) text_iterator_byte_next(&it, NULL); r.start = it.pos; it = text_iterator_get(txt, rin->end); - do r.end = it.pos; while (text_iterator_byte_prev(&it, &c) && isspace((unsigned char)c)); + do r.end = it.pos; while (text_iterator_byte_prev(&it, &c) && space(c)); return r; }