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.master
parent
19a6120dc8
commit
654d694e39
|
@ -2920,10 +2920,9 @@ void do_wordlinechar_count(void)
|
||||||
get_region(&topline, &top_x, &botline, &bot_x);
|
get_region(&topline, &top_x, &botline, &bot_x);
|
||||||
|
|
||||||
if (topline != botline)
|
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 += mbstrlen(topline->data + top_x) - mbstrlen(botline->data + bot_x);
|
||||||
chars += (botline->next == NULL) ? 1 : 0;
|
|
||||||
} else {
|
} else {
|
||||||
topline = openfile->filetop;
|
topline = openfile->filetop;
|
||||||
top_x = 0;
|
top_x = 0;
|
||||||
|
|
|
@ -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)
|
for (line = begin; line != end->next; line = line->next)
|
||||||
count += mbstrlen(line->data) + 1;
|
count += mbstrlen(line->data) + 1;
|
||||||
|
|
||||||
/* The last line of a file doesn't have a newline -- otherwise it
|
/* Do not count the final newline. */
|
||||||
* wouldn't be the last line -- so subtract 1 when at EOF. */
|
return (count - 1);
|
||||||
if (line == NULL)
|
|
||||||
count--;
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3342,10 +3342,6 @@ void do_cursorpos(bool force)
|
||||||
|
|
||||||
openfile->current->data[openfile->current_x] = saved_byte;
|
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. */
|
/* Display the current cursor position on the status bar. */
|
||||||
linepct = 100 * openfile->current->lineno / openfile->filebot->lineno;
|
linepct = 100 * openfile->current->lineno / openfile->filebot->lineno;
|
||||||
colpct = 100 * cur_xpt / cur_lenpt;
|
colpct = 100 * cur_xpt / cur_lenpt;
|
||||||
|
|
Loading…
Reference in New Issue