Skip to content

Commit

Permalink
fixup! re-add strbuf methods removed by revert
Browse files Browse the repository at this point in the history
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
derrickstolee committed Oct 12, 2018
1 parent 844d368 commit c2bd0e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ void strbuf_trim_trailing_dir_sep(struct strbuf *sb)
sb->buf[sb->len] = '\0';
}

void strbuf_trim_trailing_newline(struct strbuf *sb)
{
if (sb->len > 0 && sb->buf[sb->len - 1] == '\n') {
if (--sb->len > 0 && sb->buf[sb->len - 1] == '\r')
--sb->len;
sb->buf[sb->len] = '\0';
}
}

void strbuf_ltrim(struct strbuf *sb)
{
char *b = sb->buf;
Expand Down
3 changes: 3 additions & 0 deletions strbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ extern void strbuf_ltrim(struct strbuf *);
/* Strip trailing directory separators */
extern void strbuf_trim_trailing_dir_sep(struct strbuf *);

/* Strip trailing LF or CR/LF */
extern void strbuf_trim_trailing_newline(struct strbuf *sb);

/**
* Replace the contents of the strbuf with a reencoded form. Returns -1
* on error, 0 on success.
Expand Down

0 comments on commit c2bd0e9

Please sign in to comment.