/* * Copy over a string to the destination, but avoid special * characters ('\n', '<' and '>') and remove crud at the end */ static void strbuf_addstr_without_crud(struct strbuf *sb, const char *src) { size_t i, len; unsigned char c; /* Remove crud from the beginning.. */ while ((c = *src) != 0) { if (!crud(c)) break; src++; } /* Remove crud from the end.. */ len = strlen(src); while (len > 0) { c = src[len-1]; if (!crud(c)) break; --len; } /* * Copy the rest to the buffer, but avoid the special * characters '\n' '<' and '>' that act as delimiters on * an identification line. We can only remove crud, never add it, * so 'len' is our maximum. */ strbuf_grow(sb, len); for (i = 0; i < len; i++) { c = *src++; switch (c) { case '\n': case '<': case '>': continue; } sb->buf[sb->len++] = c; } sb->buf[sb->len] = '\0'; }
/* * Copy over a string to the destination, but avoid special * characters ('\n', '<' and '>') and remove crud at the end */ static int copy(char *buf, size_t size, int offset, const char *src) { size_t i, len; unsigned char c; /* Remove crud from the beginning.. */ while ((c = *src) != 0) { if (!crud(c)) break; src++; } /* Remove crud from the end.. */ len = strlen(src); while (len > 0) { c = src[len-1]; if (!crud(c)) break; --len; } /* * Copy the rest to the buffer, but avoid the special * characters '\n' '<' and '>' that act as delimiters on * an identification line */ for (i = 0; i < len; i++) { c = *src++; switch (c) { case '\n': case '<': case '>': continue; } if (offset >= size) return size; buf[offset++] = c; } return offset; }