mirror of
git://git.sv.gnu.org/nano.git
synced 2025-01-25 02:32:16 +03:00
tabs: compute the number of required spaces without iterating
This commit is contained in:
parent
1a4ec6c2d3
commit
68acc1dfc5
21
src/text.c
21
src/text.c
@ -247,25 +247,18 @@ void do_tab(void)
|
||||
{
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(TABS_TO_SPACES)) {
|
||||
char *output;
|
||||
size_t output_len = 0, new_pww = xplustabs();
|
||||
char *spaces = charalloc(tabsize + 1);
|
||||
size_t length = tabsize - (xplustabs() % tabsize);
|
||||
|
||||
do {
|
||||
new_pww++;
|
||||
output_len++;
|
||||
} while (new_pww % tabsize != 0);
|
||||
charset(spaces, ' ', length);
|
||||
spaces[length] = '\0';
|
||||
|
||||
output = charalloc(output_len + 1);
|
||||
do_output(spaces, length, TRUE);
|
||||
|
||||
charset(output, ' ', output_len);
|
||||
output[output_len] = '\0';
|
||||
|
||||
do_output(output, output_len, TRUE);
|
||||
|
||||
free(output);
|
||||
free(spaces);
|
||||
} else
|
||||
#endif
|
||||
do_output((char *) "\t", 1, TRUE);
|
||||
do_output((char *)"\t", 1, TRUE);
|
||||
}
|
||||
|
||||
#ifndef NANO_TINY
|
||||
|
Loading…
Reference in New Issue
Block a user