MCPcopy Create free account
hub / github.com/git/git / strbuf_addstr_without_crud

Function strbuf_addstr_without_crud

ident.c:229–266  ·  view source on GitHub ↗

* Copy over a string to the destination, but avoid special * characters ('\n', '<' and '>') and remove crud at the end */

Source from the content-addressed store, hash-verified

227 * characters ('\n', '<' and '>') and remove crud at the end
228 */
229static void strbuf_addstr_without_crud(struct strbuf *sb, const char *src)
230{
231 size_t i, len;
232 unsigned char c;
233
234 /* Remove crud from the beginning.. */
235 while ((c = *src) != 0) {
236 if (!crud(c))
237 break;
238 src++;
239 }
240
241 /* Remove crud from the end.. */
242 len = strlen(src);
243 while (len > 0) {
244 c = src[len-1];
245 if (!crud(c))
246 break;
247 --len;
248 }
249
250 /*
251 * Copy the rest to the buffer, but avoid the special
252 * characters '\n' '<' and '>' that act as delimiters on
253 * an identification line. We can only remove crud, never add it,
254 * so 'len' is our maximum.
255 */
256 strbuf_grow(sb, len);
257 for (i = 0; i < len; i++) {
258 c = *src++;
259 switch (c) {
260 case '\n': case '<': case '>':
261 continue;
262 }
263 sb->buf[sb->len++] = c;
264 }
265 sb->buf[sb->len] = '\0';
266}
267
268/*
269 * Reverse of fmt_ident(); given an ident line, split the fields

Callers 1

fmt_identFunction · 0.85

Calls 2

crudFunction · 0.85
strbuf_growFunction · 0.85

Tested by

no test coverage detected