aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-04-05 12:24:50 +0200
committerMarc André Tanner <mat@brain-dump.org>2017-04-08 22:54:36 +0200
commit03ffb2b812022082c681f478da10b095f44dfb97 (patch)
tree28864139aeb0048138fd250aaddd7b61c0bac2e5
parent1ce9b4f9c94cd7aeed7034686c1db11c5726eda7 (diff)
downloadvis-03ffb2b812022082c681f478da10b095f44dfb97.tar.gz
vis-03ffb2b812022082c681f478da10b095f44dfb97.tar.xz
text: fix iterator semantics regarding windows style newlines
At some point we might drop this mess and ask users to rely upon dos2unix(1) and unix2dos(1), respectively.
-rw-r--r--text.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/text.c b/text.c
index f5f5a43..390be98 100644
--- a/text.c
+++ b/text.c
@@ -1483,7 +1483,7 @@ bool text_iterator_char_next(Iterator *it, char *ret) {
if (!text_iterator_codepoint_next(it, ret))
return false;
if (cr && *ret == '\n')
- return text_iterator_byte_next(it, ret);
+ return text_iterator_byte_next(it, ret) && text_iterator_char_get(it, ret);
mbstate_t ps = { 0 };
for (;;) {
char buf[MB_CUR_MAX];
@@ -1496,6 +1496,8 @@ bool text_iterator_char_next(Iterator *it, char *ret) {
return false;
} else if (wclen == 0) {
return true;
+ } else if (wc == L'\r') {
+ return text_iterator_char_get(it, ret);
} else {
int width = wcwidth(wc);
if (width != 0)
@@ -1514,7 +1516,7 @@ bool text_iterator_char_prev(Iterator *it, char *ret) {
if (!text_iterator_codepoint_prev(it, ret))
return false;
if (*ret == '\n') {
- if (text_iterator_byte_prev(it, &c) && c != '\r')
+ if (!text_iterator_byte_prev(it, &c) || c != '\r')
text_iterator_byte_next(it, NULL);
return true;
}