tweaks: rename a function, to be more general and clearer
parent
f4a33b868a
commit
19a6120dc8
|
@ -294,7 +294,7 @@ void extract_segment(linestruct *top, size_t top_x, linestruct *bot, size_t bot_
|
|||
}
|
||||
|
||||
/* Subtract the size of the excised text from the buffer size. */
|
||||
openfile->totsize -= get_totsize(taken, last);
|
||||
openfile->totsize -= number_of_characters_in(taken, last);
|
||||
|
||||
/* If the cutbuffer is currently empty, just move all the text directly
|
||||
* into it; otherwise, append the text to what is already there. */
|
||||
|
@ -357,7 +357,7 @@ void ingraft_buffer(linestruct *topline)
|
|||
botline = botline->next;
|
||||
|
||||
/* Add the size of the text to be grafted to the buffer size. */
|
||||
openfile->totsize += get_totsize(topline, botline);
|
||||
openfile->totsize += number_of_characters_in(topline, botline);
|
||||
|
||||
if (topline != botline)
|
||||
length = xpos;
|
||||
|
|
|
@ -574,7 +574,7 @@ bool mark_is_before_cursor(void);
|
|||
void get_region(linestruct **top, size_t *top_x, linestruct **bot, size_t *bot_x);
|
||||
void get_range(linestruct **top, linestruct **bot);
|
||||
#endif
|
||||
size_t get_totsize(const linestruct *begin, const linestruct *end);
|
||||
size_t number_of_characters_in(const linestruct *begin, const linestruct *end);
|
||||
#ifndef NANO_TINY
|
||||
linestruct *line_from_number(ssize_t lineno);
|
||||
#endif
|
||||
|
|
|
@ -2920,7 +2920,7 @@ void do_wordlinechar_count(void)
|
|||
get_region(&topline, &top_x, &botline, &bot_x);
|
||||
|
||||
if (topline != botline)
|
||||
chars = get_totsize(topline->next, botline);
|
||||
chars = number_of_characters_in(topline->next, botline);
|
||||
|
||||
chars += mbstrlen(topline->data + top_x) - mbstrlen(botline->data + bot_x);
|
||||
chars += (botline->next == NULL) ? 1 : 0;
|
||||
|
|
10
src/utils.c
10
src/utils.c
|
@ -512,19 +512,19 @@ linestruct *line_from_number(ssize_t number)
|
|||
#endif /* !NANO_TINY */
|
||||
|
||||
/* Count the number of characters from begin to end, and return it. */
|
||||
size_t get_totsize(const linestruct *begin, const linestruct *end)
|
||||
size_t number_of_characters_in(const linestruct *begin, const linestruct *end)
|
||||
{
|
||||
const linestruct *line;
|
||||
size_t totsize = 0;
|
||||
size_t count = 0;
|
||||
|
||||
/* Sum the number of characters (plus a newline) in each line. */
|
||||
for (line = begin; line != end->next; line = line->next)
|
||||
totsize += mbstrlen(line->data) + 1;
|
||||
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)
|
||||
totsize--;
|
||||
count--;
|
||||
|
||||
return totsize;
|
||||
return count;
|
||||
}
|
||||
|
|
|
@ -3338,7 +3338,7 @@ void do_cursorpos(bool force)
|
|||
saved_byte = openfile->current->data[openfile->current_x];
|
||||
openfile->current->data[openfile->current_x] = '\0';
|
||||
|
||||
sum = get_totsize(openfile->filetop, openfile->current);
|
||||
sum = number_of_characters_in(openfile->filetop, openfile->current);
|
||||
|
||||
openfile->current->data[openfile->current_x] = saved_byte;
|
||||
|
||||
|
|
Loading…
Reference in New Issue