add function to print a single line, ignoring \r and \n
This can happen when there is no newline at end of file in the diff which is served by libgit2 as: "\n\ No newline at end of file\n".
This commit is contained in:
parent
be8665e6c3
commit
ad63c0a6a4
1 changed files with 22 additions and 1 deletions
23
stagit.c
23
stagit.c
|
@ -377,6 +377,26 @@ xmlencode(FILE *fp, const char *s, size_t len)
|
|||
}
|
||||
}
|
||||
|
||||
/* Escape characters below as HTML 2.0 / XML 1.0, ignore printing '\n', '\r' */
|
||||
void
|
||||
xmlencodeline(FILE *fp, const char *s, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; *s && i < len; s++, i++) {
|
||||
switch(*s) {
|
||||
case '<': fputs("<", fp); break;
|
||||
case '>': fputs(">", fp); break;
|
||||
case '\'': fputs("'", fp); break;
|
||||
case '&': fputs("&", fp); break;
|
||||
case '"': fputs(""", fp); break;
|
||||
case '\r': break; /* ignore CR */
|
||||
case '\n': break; /* ignore LF */
|
||||
default: putc(*s, fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
mkdirp(const char *path)
|
||||
{
|
||||
|
@ -678,7 +698,8 @@ printshowfile(FILE *fp, struct commitinfo *ci)
|
|||
i, j, k, i, j, k);
|
||||
else
|
||||
putc(' ', fp);
|
||||
xmlencode(fp, line->content, line->content_len);
|
||||
xmlencodeline(fp, line->content, line->content_len);
|
||||
putc('\n', fp);
|
||||
if (line->old_lineno == -1 || line->new_lineno == -1)
|
||||
fputs("</a>", fp);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue