Fix position output in matcher

This commit is contained in:
Kovid Goyal 2021-08-07 10:45:50 +05:30
parent 064fc17ce3
commit ca1b2454bd
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 5 additions and 4 deletions

View File

@ -66,10 +66,10 @@ static void
output_positions(GlobalData *global, len_t *positions, len_t num) {
wchar_t buf[128];
for (len_t i = 0; i < num; i++) {
int num = swprintf(buf, sizeof(buf)/sizeof(buf[0]), L"%u", positions[i]);
if (num > 0 && ensure_space(global, num + 1)) {
for (int i = 0; i < num; i++) global->output[global->output_pos++] = buf[i];
global->output[global->output_pos++] = (i == num - 1) ? ',' : ':';
int pnum = swprintf(buf, arraysz(buf), L"%u", positions[i]);
if (pnum > 0 && ensure_space(global, pnum + 1)) {
for (int k = 0; k < pnum; k++) global->output[global->output_pos++] = buf[k];
global->output[global->output_pos++] = (i == num - 1) ? ':' : ',';
}
}
}

View File

@ -59,6 +59,7 @@ class TestMatcher(BaseTest):
def test_positions(self):
' Output of positions '
self.basic_test('abc\nac', 'ac', '0,1:ac\n0,2:abc', positions=True)
self.basic_test('abc\nv', 'a', '0:abc', positions=True)
def test_delimiter(self):
' Test using a custom line delimiter '