File tree 2 files changed +12
-0
lines changed 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,15 @@ void strbuf_trim_trailing_dir_sep(struct strbuf *sb)
120
120
sb -> buf [sb -> len ] = '\0' ;
121
121
}
122
122
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
+
123
132
void strbuf_ltrim (struct strbuf * sb )
124
133
{
125
134
char * b = sb -> buf ;
Original file line number Diff line number Diff line change @@ -190,6 +190,9 @@ extern void strbuf_ltrim(struct strbuf *);
190
190
/* Strip trailing directory separators */
191
191
extern void strbuf_trim_trailing_dir_sep (struct strbuf * );
192
192
193
+ /* Strip trailing LF or CR/LF */
194
+ extern void strbuf_trim_trailing_newline (struct strbuf * sb );
195
+
193
196
/**
194
197
* Replace the contents of the strbuf with a reencoded form. Returns -1
195
198
* on error, 0 on success.
You can’t perform that action at this time.
0 commit comments