From 03ffb2b812022082c681f478da10b095f44dfb97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 5 Apr 2017 12:24:50 +0200 Subject: 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. --- text.c | 6 ++++-- 1 file 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; } -- cgit v1.2.3