Skip to content

Commit c2bd0e9

Browse files
committed
fixup! re-add strbuf methods removed by revert
Signed-off-by: Derrick Stolee <[email protected]>
1 parent 844d368 commit c2bd0e9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

strbuf.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ void strbuf_trim_trailing_dir_sep(struct strbuf *sb)
120120
sb->buf[sb->len] = '\0';
121121
}
122122

123+
void strbuf_trim_trailing_newline(struct strbuf *sb)
124+
{
125+
if (sb->len > 0 && sb->buf[sb->len - 1] == '\n') {
126+
if (--sb->len > 0 && sb->buf[sb->len - 1] == '\r')
127+
--sb->len;
128+
sb->buf[sb->len] = '\0';
129+
}
130+
}
131+
123132
void strbuf_ltrim(struct strbuf *sb)
124133
{
125134
char *b = sb->buf;

strbuf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ extern void strbuf_ltrim(struct strbuf *);
190190
/* Strip trailing directory separators */
191191
extern void strbuf_trim_trailing_dir_sep(struct strbuf *);
192192

193+
/* Strip trailing LF or CR/LF */
194+
extern void strbuf_trim_trailing_newline(struct strbuf *sb);
195+
193196
/**
194197
* Replace the contents of the strbuf with a reencoded form. Returns -1
195198
* on error, 0 on success.

0 commit comments

Comments
 (0)