aboutsummaryrefslogtreecommitdiff
path: root/text-motions.c
diff options
context:
space:
mode:
Diffstat (limited to 'text-motions.c')
-rw-r--r--text-motions.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/text-motions.c b/text-motions.c
index 210e1f4..bca923d 100644
--- a/text-motions.c
+++ b/text-motions.c
@@ -115,12 +115,10 @@ size_t text_line_find_prev(Text *txt, size_t pos, const char *s) {
size_t text_line_prev(Text *txt, size_t pos) {
char c;
Iterator it = text_iterator_get(txt, pos);
- if (!text_iterator_byte_get(&it, &c))
+ if (!text_iterator_char_get(&it, &c))
return pos;
if (c == '\n')
- text_iterator_byte_prev(&it, &c);
- if (c == '\r')
- text_iterator_byte_prev(&it, &c);
+ text_iterator_char_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')
@@ -131,12 +129,10 @@ size_t text_line_prev(Text *txt, size_t pos) {
size_t text_line_begin(Text *txt, size_t pos) {
char c;
Iterator it = text_iterator_get(txt, pos);
- if (!text_iterator_byte_get(&it, &c))
+ if (!text_iterator_char_get(&it, &c))
return pos;
if (c == '\n')
- text_iterator_byte_prev(&it, &c);
- if (c == '\r')
- text_iterator_byte_prev(&it, &c);
+ text_iterator_char_prev(&it, &c);
while (text_iterator_byte_get(&it, &c)) {
if (c == '\n') {
it.pos++;
@@ -159,9 +155,9 @@ size_t text_line_finish(Text *txt, size_t pos) {
char c;
size_t end = text_line_end(txt, pos);
Iterator it = text_iterator_get(txt, end);
- if (!text_iterator_char_prev(&it, &c) || c == '\n')
+ if (!text_iterator_byte_prev(&it, &c) || c == '\n')
return end;
- while (blank(c) && text_iterator_char_prev(&it, &c));
+ while (blank(c) && text_iterator_byte_prev(&it, &c));
return it.pos + (c == '\n');
}
@@ -186,7 +182,7 @@ size_t text_line_offset(Text *txt, size_t pos, size_t off) {
char c;
size_t bol = text_line_begin(txt, pos);
Iterator it = text_iterator_get(txt, bol);
- while (off-- > 0 && text_iterator_byte_get(&it, &c) && c != '\r' && c != '\n')
+ while (off-- > 0 && text_iterator_char_get(&it, &c) && c != '\n')
text_iterator_byte_next(&it, NULL);
return it.pos;
}
@@ -195,8 +191,8 @@ size_t text_line_char_set(Text *txt, size_t pos, int count) {
char c;
size_t bol = text_line_begin(txt, pos);
Iterator it = text_iterator_get(txt, bol);
- while (count-- > 0 && text_iterator_byte_get(&it, &c) && c != '\r' && c != '\n')
- text_iterator_char_next(&it, NULL);
+ if (text_iterator_char_get(&it, &c) && c != '\n')
+ while (count-- > 0 && text_iterator_char_next(&it, &c) && c != '\n');
return it.pos;
}
@@ -205,9 +201,9 @@ int text_line_char_get(Text *txt, size_t pos) {
int count = 0;
size_t bol = text_line_begin(txt, pos);
Iterator it = text_iterator_get(txt, bol);
- while (text_iterator_byte_get(&it, &c) && it.pos < pos && c != '\r' && c != '\n') {
- text_iterator_char_next(&it, NULL);
- count++;
+ if (text_iterator_char_get(&it, &c) && c != '\n') {
+ while (it.pos < pos && c != '\n' && text_iterator_char_next(&it, &c))
+ count++;
}
return count;
}
@@ -289,7 +285,7 @@ size_t text_line_width_set(Text *txt, size_t pos, int width) {
size_t text_line_char_next(Text *txt, size_t pos) {
char c;
Iterator it = text_iterator_get(txt, pos);
- if (!text_iterator_byte_get(&it, &c) || c == '\r' || c == '\n')
+ if (!text_iterator_char_get(&it, &c) || c == '\n')
return pos;
text_iterator_char_next(&it, NULL);
return it.pos;
@@ -473,8 +469,8 @@ size_t text_paragraph_next(Text *txt, size_t pos) {
char c;
Iterator it = text_iterator_get(txt, pos);
- while (text_iterator_byte_get(&it, &c) && (c == '\n' || c == '\r'))
- text_iterator_byte_next(&it, NULL);
+ while (text_iterator_char_get(&it, &c) && c == '\n')
+ text_iterator_char_next(&it, NULL);
return text_line_empty_next(txt, it.pos);
}
@@ -483,8 +479,8 @@ size_t text_paragraph_prev(Text *txt, size_t pos) {
Iterator it = text_iterator_get(txt, pos);
/* c == \0 catches starting the search at EOF */
- while (text_iterator_byte_get(&it, &c) && (c == '\n' || c == '\r' || c == '\0'))
- text_iterator_byte_prev(&it, NULL);
+ while (text_iterator_char_get(&it, &c) && (c == '\n' || c == '\0'))
+ text_iterator_char_prev(&it, NULL);
return text_line_empty_prev(txt, it.pos);
}