* This function splits the words in buffer->text, stores the list with * newline separator into out, and saves the offsets of the original words * in buffer->orig. */
| 2189 | * in buffer->orig. |
| 2190 | */ |
| 2191 | static void diff_words_fill(struct diff_words_buffer *buffer, mmfile_t *out, |
| 2192 | regex_t *word_regex) |
| 2193 | { |
| 2194 | int i, j; |
| 2195 | long alloc = 0; |
| 2196 | |
| 2197 | out->size = 0; |
| 2198 | out->ptr = NULL; |
| 2199 | |
| 2200 | /* fake an empty "0th" word */ |
| 2201 | ALLOC_GROW(buffer->orig, 1, buffer->orig_alloc); |
| 2202 | buffer->orig[0].begin = buffer->orig[0].end = buffer->text.ptr; |
| 2203 | buffer->orig_nr = 1; |
| 2204 | |
| 2205 | for (i = 0; i < buffer->text.size; i++) { |
| 2206 | if (find_word_boundaries(&buffer->text, word_regex, &i, &j)) |
| 2207 | return; |
| 2208 | |
| 2209 | /* store original boundaries */ |
| 2210 | ALLOC_GROW(buffer->orig, buffer->orig_nr + 1, |
| 2211 | buffer->orig_alloc); |
| 2212 | buffer->orig[buffer->orig_nr].begin = buffer->text.ptr + i; |
| 2213 | buffer->orig[buffer->orig_nr].end = buffer->text.ptr + j; |
| 2214 | buffer->orig_nr++; |
| 2215 | |
| 2216 | /* store one word */ |
| 2217 | ALLOC_GROW(out->ptr, out->size + j - i + 1, alloc); |
| 2218 | memcpy(out->ptr + out->size, buffer->text.ptr + i, j - i); |
| 2219 | out->ptr[out->size + j - i] = '\n'; |
| 2220 | out->size += j - i + 1; |
| 2221 | |
| 2222 | i = j - 1; |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | /* this executes the word diff on the accumulated buffers */ |
| 2227 | static void diff_words_show(struct diff_words_data *diff_words) |
no test coverage detected