| 2181 | } |
| 2182 | |
| 2183 | static void strbuf_add_tabexpand(struct strbuf *sb, struct grep_opt *opt, |
| 2184 | enum git_colorbool color, int tabwidth, const char *line, |
| 2185 | int linelen) |
| 2186 | { |
| 2187 | const char *tab; |
| 2188 | |
| 2189 | while ((tab = memchr(line, '\t', linelen)) != NULL) { |
| 2190 | int width = pp_utf8_width(line, tab); |
| 2191 | |
| 2192 | /* |
| 2193 | * If it wasn't well-formed utf8, or it |
| 2194 | * had characters with badly defined |
| 2195 | * width (control characters etc), just |
| 2196 | * give up on trying to align things. |
| 2197 | */ |
| 2198 | if (width < 0) |
| 2199 | break; |
| 2200 | |
| 2201 | /* Output the data .. */ |
| 2202 | append_line_with_color(sb, opt, line, tab - line, color, |
| 2203 | GREP_CONTEXT_BODY, |
| 2204 | GREP_HEADER_FIELD_MAX); |
| 2205 | |
| 2206 | /* .. and the de-tabified tab */ |
| 2207 | strbuf_addchars(sb, ' ', tabwidth - (width % tabwidth)); |
| 2208 | |
| 2209 | /* Skip over the printed part .. */ |
| 2210 | linelen -= tab + 1 - line; |
| 2211 | line = tab + 1; |
| 2212 | } |
| 2213 | |
| 2214 | /* |
| 2215 | * Print out everything after the last tab without |
| 2216 | * worrying about width - there's nothing more to |
| 2217 | * align. |
| 2218 | */ |
| 2219 | append_line_with_color(sb, opt, line, linelen, color, GREP_CONTEXT_BODY, |
| 2220 | GREP_HEADER_FIELD_MAX); |
| 2221 | } |
| 2222 | |
| 2223 | /* |
| 2224 | * pp_handle_indent() prints out the indentation, and |
no test coverage detected