* Copy over a string to the destination, but avoid special * characters ('\n', '<' and '>') and remove crud at the end */
| 227 | * characters ('\n', '<' and '>') and remove crud at the end |
| 228 | */ |
| 229 | static 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 |
no test coverage detected