| 2007 | }; |
| 2008 | |
| 2009 | static int fn_out_diff_words_write_helper(struct diff_options *o, |
| 2010 | struct diff_words_style_elem *st_el, |
| 2011 | const char *newline, |
| 2012 | size_t count, const char *buf) |
| 2013 | { |
| 2014 | int print = 0; |
| 2015 | struct strbuf sb = STRBUF_INIT; |
| 2016 | |
| 2017 | while (count) { |
| 2018 | const char *p = memchr(buf, '\n', count); |
| 2019 | if (print) |
| 2020 | strbuf_addstr(&sb, diff_line_prefix(o)); |
| 2021 | |
| 2022 | if (p != buf) { |
| 2023 | const char *reset = st_el->color && *st_el->color ? |
| 2024 | GIT_COLOR_RESET : NULL; |
| 2025 | if (st_el->color && *st_el->color) |
| 2026 | strbuf_addstr(&sb, st_el->color); |
| 2027 | strbuf_addstr(&sb, st_el->prefix); |
| 2028 | strbuf_add(&sb, buf, p ? p - buf : count); |
| 2029 | strbuf_addstr(&sb, st_el->suffix); |
| 2030 | if (reset) |
| 2031 | strbuf_addstr(&sb, reset); |
| 2032 | } |
| 2033 | if (!p) |
| 2034 | goto out; |
| 2035 | |
| 2036 | strbuf_addstr(&sb, newline); |
| 2037 | count -= p + 1 - buf; |
| 2038 | buf = p + 1; |
| 2039 | print = 1; |
| 2040 | if (count) { |
| 2041 | emit_diff_symbol(o, DIFF_SYMBOL_WORD_DIFF, |
| 2042 | sb.buf, sb.len, 0); |
| 2043 | strbuf_reset(&sb); |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | out: |
| 2048 | if (sb.len) |
| 2049 | emit_diff_symbol(o, DIFF_SYMBOL_WORD_DIFF, |
| 2050 | sb.buf, sb.len, 0); |
| 2051 | strbuf_release(&sb); |
| 2052 | return 0; |
| 2053 | } |
| 2054 | |
| 2055 | /* |
| 2056 | * '--color-words' algorithm can be described as: |
no test coverage detected