commit 654d694e39c367cefc8e6b5f480179a5acb8fb7e
parent 19a6120dc827273f6aa7a45de97fe2322bb409da
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Thu, 9 Apr 2020 12:52:36 +0200
tweaks: simplify the counting of characters in a section
The line after the given section is always NULL (or when it is not,
it is intended to be NULL), so always subtract 1 at the end.
Diffstat:
3 files changed, 3 insertions(+), 12 deletions(-)
diff --git a/src/text.c b/src/text.c
@@ -2920,10 +2920,9 @@ void do_wordlinechar_count(void)
get_region(&topline, &top_x, &botline, &bot_x);
if (topline != botline)
- chars = number_of_characters_in(topline->next, botline);
+ chars = number_of_characters_in(topline->next, botline) + 1;
chars += mbstrlen(topline->data + top_x) - mbstrlen(botline->data + bot_x);
- chars += (botline->next == NULL) ? 1 : 0;
} else {
topline = openfile->filetop;
top_x = 0;
diff --git a/src/utils.c b/src/utils.c
@@ -521,10 +521,6 @@ size_t number_of_characters_in(const linestruct *begin, const linestruct *end)
for (line = begin; line != end->next; line = line->next)
count += mbstrlen(line->data) + 1;
- /* The last line of a file doesn't have a newline -- otherwise it
- * wouldn't be the last line -- so subtract 1 when at EOF. */
- if (line == NULL)
- count--;
-
- return count;
+ /* Do not count the final newline. */
+ return (count - 1);
}
diff --git a/src/winio.c b/src/winio.c
@@ -3342,10 +3342,6 @@ void do_cursorpos(bool force)
openfile->current->data[openfile->current_x] = saved_byte;
- /* When not at EOF, subtract 1 for an overcounted newline. */
- if (openfile->current != openfile->filebot)
- sum--;
-
/* Display the current cursor position on the status bar. */
linepct = 100 * openfile->current->lineno / openfile->filebot->lineno;
colpct = 100 * cur_xpt / cur_lenpt;