MCPcopy Index your code
hub / github.com/git/git / strbuf_stripspace

Function strbuf_stripspace

strbuf.c:1095–1128  ·  view source on GitHub ↗

* Remove empty lines from the beginning and end * and also trailing spaces from every line. * * Turn multiple consecutive empty lines between paragraphs * into just one empty line. * * If the input has only empty lines and spaces, * no output will be produced. * * If last line does not have a newline at the end, one is added. * * Pass a non-NULL comment_prefix to skip every line startin

Source from the content-addressed store, hash-verified

1093 * with it.
1094 */
1095void strbuf_stripspace(struct strbuf *sb, const char *comment_prefix)
1096{
1097 size_t empties = 0;
1098 size_t i, j, len, newlen;
1099 char *eol;
1100
1101 /* We may have to add a newline. */
1102 strbuf_grow(sb, 1);
1103
1104 for (i = j = 0; i < sb->len; i += len, j += newlen) {
1105 eol = memchr(sb->buf + i, '\n', sb->len - i);
1106 len = eol ? eol - (sb->buf + i) + 1 : sb->len - i;
1107
1108 if (comment_prefix && len &&
1109 starts_with(sb->buf + i, comment_prefix)) {
1110 newlen = 0;
1111 continue;
1112 }
1113 newlen = cleanup(sb->buf + i, len);
1114
1115 /* Not just an empty line? */
1116 if (newlen) {
1117 if (empties > 0 && j > 0)
1118 sb->buf[j++] = '\n';
1119 empties = 0;
1120 memmove(sb->buf + j, sb->buf + i, newlen);
1121 sb->buf[newlen + j++] = '\n';
1122 } else {
1123 empties++;
1124 }
1125 }
1126
1127 strbuf_setlen(sb, j);
1128}
1129
1130void strbuf_strip_file_from_path(struct strbuf *sb)
1131{

Callers 14

edit_todo_listFunction · 0.85
cleanup_messageFunction · 0.85
template_untouchedFunction · 0.85
try_to_commitFunction · 0.85
verify_ssh_signed_bufferFunction · 0.85
create_tagFunction · 0.85
parse_mailFunction · 0.85
edit_todo_fileFunction · 0.85
prepare_note_dataFunction · 0.85
concat_messagesFunction · 0.85
cmd_stripspaceFunction · 0.85
prepare_to_commitFunction · 0.85

Calls 4

strbuf_growFunction · 0.85
starts_withFunction · 0.85
strbuf_setlenFunction · 0.85
cleanupFunction · 0.70

Tested by

no test coverage detected