Commit bfed7386 authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

Insert matching ), ], and } characters

No related merge requests found
Showing with 14 additions and 7 deletions
+14 -7
......@@ -1862,14 +1862,21 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
continue;
/* Make room for the new character and copy it into the line. */
openfile->current->data = charealloc(openfile->current->data,
current_len + char_len + 1);
charmove(openfile->current->data + openfile->current_x + char_len,
openfile->current->data + openfile->current_x,
char matching_char =
*onechar == '(' ? ')' :
*onechar == '[' ? ']' :
*onechar == '{' ? '}' : '\0';
size_t insert_length = matching_char ? char_len + 1 : char_len;
openfile->current->data =
charealloc(openfile->current->data, current_len + insert_length + 1);
char *insert_start = openfile->current->data + openfile->current_x;
charmove(insert_start + insert_length, insert_start,
current_len - openfile->current_x + 1);
strncpy(openfile->current->data + openfile->current_x, onechar,
char_len);
current_len += char_len;
strncpy(insert_start, onechar, char_len);
if (matching_char) {
insert_start[char_len] = matching_char;
}
current_len += insert_length;
openfile->totsize++;
set_modified();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment