aboutsummaryrefslogtreecommitdiff
path: root/text-motions.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-19 12:53:18 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-19 12:53:18 +0200
commitffa12d93c7efc516ead1dfc798f9afc0d3ec1aa1 (patch)
tree574635d1ed446def3fc894379eef036494f42964 /text-motions.c
parentf212b9d4952c87052e23b5161195917410b7c911 (diff)
downloadvis-ffa12d93c7efc516ead1dfc798f9afc0d3ec1aa1.tar.gz
vis-ffa12d93c7efc516ead1dfc798f9afc0d3ec1aa1.tar.xz
Windows style newlines are actually \r\n not \n\r
This is fiddely stuff, hopefully it doesn't break too much
Diffstat (limited to 'text-motions.c')
-rw-r--r--text-motions.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/text-motions.c b/text-motions.c
index 15fdd2d..69afcc7 100644
--- a/text-motions.c
+++ b/text-motions.c
@@ -78,12 +78,14 @@ size_t text_line_prev(Text *txt, size_t pos) {
Iterator it = text_iterator_get(txt, pos);
if (!text_iterator_byte_get(&it, &c))
return pos;
- if (c == '\r')
- text_iterator_byte_prev(&it, &c);
if (c == '\n')
text_iterator_byte_prev(&it, &c);
+ if (c == '\r')
+ text_iterator_byte_prev(&it, &c);
while (text_iterator_byte_get(&it, &c) && c != '\n')
text_iterator_byte_prev(&it, NULL);
+ if (text_iterator_byte_prev(&it, &c) && c != '\r')
+ text_iterator_byte_next(&it, &c);
return it.pos;
}
@@ -92,12 +94,12 @@ size_t text_line_begin(Text *txt, size_t pos) {
Iterator it = text_iterator_get(txt, pos);
if (!text_iterator_byte_get(&it, &c))
return pos;
- if (c == '\r')
- text_iterator_byte_prev(&it, &c);
if (c == '\n')
text_iterator_byte_prev(&it, &c);
+ if (c == '\r')
+ text_iterator_byte_prev(&it, &c);
while (text_iterator_byte_get(&it, &c)) {
- if (c == '\n' || c == '\r') {
+ if (c == '\n') {
it.pos++;
break;
}
@@ -118,7 +120,7 @@ size_t text_line_finish(Text *txt, size_t pos) {
char c;
Iterator it = text_iterator_get(txt, text_line_end(txt, pos));
do text_iterator_byte_prev(&it, NULL);
- while (text_iterator_byte_get(&it, &c) && c != '\n' && c != '\r' && isspace(c));
+ while (text_iterator_byte_get(&it, &c) && c != '\n' && isspace(c));
if (!ISUTF8(c))
text_iterator_char_prev(&it, NULL);
return it.pos;
@@ -127,7 +129,7 @@ size_t text_line_finish(Text *txt, size_t pos) {
size_t text_line_end(Text *txt, size_t pos) {
char c;
Iterator it = text_iterator_get(txt, pos);
- while (text_iterator_byte_get(&it, &c) && c != '\n')
+ while (text_iterator_byte_get(&it, &c) && c != '\r' && c != '\n')
text_iterator_byte_next(&it, NULL);
return it.pos;
}
@@ -137,8 +139,7 @@ size_t text_line_next(Text *txt, size_t pos) {
Iterator it = text_iterator_get(txt, pos);
while (text_iterator_byte_get(&it, &c) && c != '\n')
text_iterator_byte_next(&it, NULL);
- if (text_iterator_byte_next(&it, &c) && c == '\r')
- text_iterator_byte_next(&it, NULL);
+ text_iterator_byte_next(&it, NULL);
return it.pos;
}