refactor: add space around arithmetic operators '+' and '-'

This commit is contained in:
zeertzjq
2022-08-05 16:45:01 +08:00
committed by GitHub
parent ce7df6759c
commit 5190f82a52

View File

@@ -602,15 +602,15 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
int64_t lnum = start_row + i;
const char *bufline = (char *)ml_get_buf(buf, lnum, false);
old_byte += (bcount_t)(strlen(bufline))+1;
old_byte += (bcount_t)(strlen(bufline)) + 1;
}
old_byte += (bcount_t)end_col+1;
old_byte += (bcount_t)end_col + 1;
}
String first_item = replacement.items[0].data.string;
String last_item = replacement.items[replacement.size-1].data.string;
String last_item = replacement.items[replacement.size - 1].data.string;
size_t firstlen = (size_t)start_col+first_item.size;
size_t firstlen = (size_t)start_col + first_item.size;
size_t last_part_len = strlen(str_at_end) - (size_t)end_col;
if (replacement.size == 1) {
firstlen += last_part_len;
@@ -618,32 +618,32 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
char *first = xmallocz(firstlen);
char *last = NULL;
memcpy(first, str_at_start, (size_t)start_col);
memcpy(first+start_col, first_item.data, first_item.size);
memchrsub(first+start_col, NUL, NL, first_item.size);
memcpy(first + start_col, first_item.data, first_item.size);
memchrsub(first + start_col, NUL, NL, first_item.size);
if (replacement.size == 1) {
memcpy(first+start_col+first_item.size, str_at_end+end_col, last_part_len);
memcpy(first + start_col + first_item.size, str_at_end + end_col, last_part_len);
} else {
last = xmallocz(last_item.size+last_part_len);
last = xmallocz(last_item.size + last_part_len);
memcpy(last, last_item.data, last_item.size);
memchrsub(last, NUL, NL, last_item.size);
memcpy(last+last_item.size, str_at_end+end_col, last_part_len);
memcpy(last + last_item.size, str_at_end + end_col, last_part_len);
}
char **lines = xcalloc(new_len, sizeof(char *));
lines[0] = first;
new_byte += (bcount_t)(first_item.size);
for (size_t i = 1; i < new_len-1; i++) {
for (size_t i = 1; i < new_len - 1; i++) {
const String l = replacement.items[i].data.string;
// Fill lines[i] with l's contents. Convert NULs to newlines as required by
// NL-used-for-NUL.
lines[i] = xmemdupz(l.data, l.size);
memchrsub(lines[i], NUL, NL, l.size);
new_byte += (bcount_t)(l.size)+1;
new_byte += (bcount_t)(l.size) + 1;
}
if (replacement.size > 1) {
lines[replacement.size-1] = last;
new_byte += (bcount_t)(last_item.size)+1;
lines[replacement.size - 1] = last;
new_byte += (bcount_t)(last_item.size) + 1;
}
try_start();
@@ -663,7 +663,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
}
ptrdiff_t extra = 0; // lines added to text, can be negative
size_t old_len = (size_t)(end_row-start_row+1);
size_t old_len = (size_t)(end_row - start_row + 1);
// If the size of the range is reducing (ie, new_len < old_len) we
// need to delete some old_len. We do this at the start, by
@@ -731,9 +731,9 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
colnr_T col_extent = (colnr_T)(end_col
- ((end_row == start_row) ? start_col : 0));
extmark_splice(buf, (int)start_row-1, (colnr_T)start_col,
(int)(end_row-start_row), col_extent, old_byte,
(int)new_len-1, (colnr_T)last_item.size, new_byte,
extmark_splice(buf, (int)start_row - 1, (colnr_T)start_col,
(int)(end_row - start_row), col_extent, old_byte,
(int)new_len - 1, (colnr_T)last_item.size, new_byte,
kExtmarkUndo);