Merge branch 'jc/strbuf-getline'
The preliminary clean-up for jc/peace-with-crlf topic. * jc/strbuf-getline: strbuf: give strbuf_getline() to the "most text friendly" variant checkout-index: there are only two possible line terminations update-index: there are only two possible line terminations check-ignore: there are only two possible line terminations check-attr: there are only two possible line terminations mktree: there are only two possible line terminations strbuf: introduce strbuf_getline_{lf,nul}() strbuf: make strbuf_getline_crlf() global strbuf: miniscule style fix
This commit is contained in:
28
strbuf.c
28
strbuf.c
@ -512,15 +512,37 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
|
||||
}
|
||||
#endif
|
||||
|
||||
int strbuf_getline(struct strbuf *sb, FILE *fp, int term)
|
||||
static int strbuf_getdelim(struct strbuf *sb, FILE *fp, int term)
|
||||
{
|
||||
if (strbuf_getwholeline(sb, fp, term))
|
||||
return EOF;
|
||||
if (sb->buf[sb->len-1] == term)
|
||||
strbuf_setlen(sb, sb->len-1);
|
||||
if (sb->buf[sb->len - 1] == term)
|
||||
strbuf_setlen(sb, sb->len - 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int strbuf_getline(struct strbuf *sb, FILE *fp)
|
||||
{
|
||||
if (strbuf_getwholeline(sb, fp, '\n'))
|
||||
return EOF;
|
||||
if (sb->buf[sb->len - 1] == '\n') {
|
||||
strbuf_setlen(sb, sb->len - 1);
|
||||
if (sb->len && sb->buf[sb->len - 1] == '\r')
|
||||
strbuf_setlen(sb, sb->len - 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int strbuf_getline_lf(struct strbuf *sb, FILE *fp)
|
||||
{
|
||||
return strbuf_getdelim(sb, fp, '\n');
|
||||
}
|
||||
|
||||
int strbuf_getline_nul(struct strbuf *sb, FILE *fp)
|
||||
{
|
||||
return strbuf_getdelim(sb, fp, '\0');
|
||||
}
|
||||
|
||||
int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
|
||||
{
|
||||
strbuf_reset(sb);
|
||||
|
Reference in New Issue
Block a user