aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-02-03 12:58:55 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-02-03 16:22:44 +0100
commit5eb46c36bdedb72ef844479568772f0e0f390fe6 (patch)
tree115034e75612d2cdbe6226de4b53d07c5e7366d8
parent5832ac7bc1f249d6fb48b0c438157e8b227fbee0 (diff)
downloadvis-5eb46c36bdedb72ef844479568772f0e0f390fe6.tar.gz
vis-5eb46c36bdedb72ef844479568772f0e0f390fe6.tar.xz
text-motion: hide ugly casts for isboundary behind a #define
-rw-r--r--text-motions.c33
-rw-r--r--text-motions.h8
2 files changed, 21 insertions, 20 deletions
diff --git a/text-motions.c b/text-motions.c
index 7091c22..6ca2f8f 100644
--- a/text-motions.c
+++ b/text-motions.c
@@ -20,6 +20,7 @@
#include "util.h"
#define space(c) (isspace((unsigned char)c))
+#define boundary(c) (isboundary((unsigned char)c))
// TODO: specify this per file type?
int is_word_boundry(int c) {
@@ -279,50 +280,50 @@ size_t text_range_line_prev(Text *txt, Filerange *r, size_t pos) {
return newpos != pos && r->start <= newpos ? newpos : EPOS;
}
-size_t text_customword_start_next(Text *txt, size_t pos, int (*isboundry)(int)) {
+size_t text_customword_start_next(Text *txt, size_t pos, int (*isboundary)(int)) {
char c;
Iterator it = text_iterator_get(txt, pos);
if (!text_iterator_byte_get(&it, &c))
return pos;
- if (isboundry((unsigned char)c))
- while (isboundry((unsigned char)c) && !space(c) && text_iterator_char_next(&it, &c));
+ if (boundary(c))
+ while (boundary(c) && !space(c) && text_iterator_char_next(&it, &c));
else
- while (!isboundry((unsigned char)c) && text_iterator_char_next(&it, &c));
+ while (!boundary(c) && text_iterator_char_next(&it, &c));
while (space(c) && text_iterator_char_next(&it, &c));
return it.pos;
}
-size_t text_customword_start_prev(Text *txt, size_t pos, int (*isboundry)(int)) {
+size_t text_customword_start_prev(Text *txt, size_t pos, int (*isboundary)(int)) {
char c;
Iterator it = text_iterator_get(txt, pos);
while (text_iterator_char_prev(&it, &c) && space(c));
- if (isboundry((unsigned char)c))
- do pos = it.pos; while (text_iterator_char_prev(&it, &c) && isboundry((unsigned char)c) && !space(c));
+ if (boundary(c))
+ do pos = it.pos; while (text_iterator_char_prev(&it, &c) && boundary(c) && !space(c));
else
- do pos = it.pos; while (text_iterator_char_prev(&it, &c) && !isboundry((unsigned char)c));
+ do pos = it.pos; while (text_iterator_char_prev(&it, &c) && !boundary(c));
return pos;
}
-size_t text_customword_end_next(Text *txt, size_t pos, int (*isboundry)(int)) {
+size_t text_customword_end_next(Text *txt, size_t pos, int (*isboundary)(int)) {
char c;
Iterator it = text_iterator_get(txt, pos);
while (text_iterator_char_next(&it, &c) && space(c));
- if (isboundry((unsigned char)c))
- do pos = it.pos; while (text_iterator_char_next(&it, &c) && isboundry((unsigned char)c) && !space(c));
+ if (boundary(c))
+ do pos = it.pos; while (text_iterator_char_next(&it, &c) && boundary(c) && !space(c));
else
- do pos = it.pos; while (text_iterator_char_next(&it, &c) && !isboundry((unsigned char)c));
+ do pos = it.pos; while (text_iterator_char_next(&it, &c) && !isboundary(c));
return pos;
}
-size_t text_customword_end_prev(Text *txt, size_t pos, int (*isboundry)(int)) {
+size_t text_customword_end_prev(Text *txt, size_t pos, int (*isboundary)(int)) {
char c;
Iterator it = text_iterator_get(txt, pos);
if (!text_iterator_byte_get(&it, &c))
return pos;
- if (isboundry((unsigned char)c))
- while (isboundry((unsigned char)c) && !space(c) && text_iterator_char_prev(&it, &c));
+ if (boundary(c))
+ while (boundary(c) && !space(c) && text_iterator_char_prev(&it, &c));
else
- while (!isboundry((unsigned char)c) && text_iterator_char_prev(&it, &c));
+ while (!boundary(c) && text_iterator_char_prev(&it, &c));
while (space(c) && text_iterator_char_prev(&it, &c));
return it.pos;
}
diff --git a/text-motions.h b/text-motions.h
index b1388c8..cf108b3 100644
--- a/text-motions.h
+++ b/text-motions.h
@@ -79,10 +79,10 @@ size_t text_word_start_prev(Text*, size_t pos);
/*
* More general versions of the above, define your own word boundaries.
*/
-size_t text_customword_start_next(Text*, size_t pos, int (*isboundry)(int));
-size_t text_customword_start_prev(Text*, size_t pos, int (*isboundry)(int));
-size_t text_customword_end_next(Text*, size_t pos, int (*isboundry)(int));
-size_t text_customword_end_prev(Text*, size_t pos, int (*isboundry)(int));
+size_t text_customword_start_next(Text*, size_t pos, int (*isboundary)(int));
+size_t text_customword_start_prev(Text*, size_t pos, int (*isboundary)(int));
+size_t text_customword_end_next(Text*, size_t pos, int (*isboundary)(int));
+size_t text_customword_end_prev(Text*, size_t pos, int (*isboundary)(int));
/* TODO: implement the following semantics
* A sentence is defined as ending at a '.', '!' or '?' followed by either the
* end of a line, or by a space or tab. Any number of closing ')', ']', '"'