tweaks: rename a variable, reshuffle declarations, and drop an assert
parent
71d0847b19
commit
247dd8f052
13
src/search.c
13
src/search.c
|
@ -457,21 +457,20 @@ int replace_regexp(char *string, bool create)
|
||||||
/* Return a copy of the current line with one needle replaced. */
|
/* Return a copy of the current line with one needle replaced. */
|
||||||
char *replace_line(const char *needle)
|
char *replace_line(const char *needle)
|
||||||
{
|
{
|
||||||
char *copy;
|
size_t new_size = strlen(openfile->current->data) + 1;
|
||||||
size_t match_len;
|
size_t match_len;
|
||||||
size_t new_line_size = strlen(openfile->current->data) + 1;
|
char *copy;
|
||||||
|
|
||||||
/* First adjust the size of the new line for the change. */
|
/* First adjust the size of the new line for the change. */
|
||||||
if (ISSET(USE_REGEXP)) {
|
if (ISSET(USE_REGEXP)) {
|
||||||
match_len = regmatches[0].rm_eo - regmatches[0].rm_so;
|
match_len = regmatches[0].rm_eo - regmatches[0].rm_so;
|
||||||
new_line_size += replace_regexp(NULL, FALSE) - match_len;
|
new_size += replace_regexp(NULL, FALSE) - match_len;
|
||||||
} else {
|
} else {
|
||||||
match_len = strlen(needle);
|
match_len = strlen(needle);
|
||||||
new_line_size += strlen(answer) - match_len;
|
new_size += strlen(answer) - match_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the buffer. */
|
copy = charalloc(new_size);
|
||||||
copy = charalloc(new_line_size);
|
|
||||||
|
|
||||||
/* Copy the head of the original line. */
|
/* Copy the head of the original line. */
|
||||||
strncpy(copy, openfile->current->data, openfile->current_x);
|
strncpy(copy, openfile->current->data, openfile->current_x);
|
||||||
|
@ -482,8 +481,6 @@ char *replace_line(const char *needle)
|
||||||
else
|
else
|
||||||
strcpy(copy + openfile->current_x, answer);
|
strcpy(copy + openfile->current_x, answer);
|
||||||
|
|
||||||
assert(openfile->current_x + match_len <= strlen(openfile->current->data));
|
|
||||||
|
|
||||||
/* Copy the tail of the original line. */
|
/* Copy the tail of the original line. */
|
||||||
strcat(copy, openfile->current->data + openfile->current_x + match_len);
|
strcat(copy, openfile->current->data + openfile->current_x + match_len);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue