commit 74775723355a0816113bf2c025c37a6c11fe5fd9
parent ff41682701c859b2c10e3be802e6d76b74c5cf12
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Thu, 25 Mar 2021 18:13:13 +0100
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".
Diffstat:
1 file changed, 20 insertions(+), 0 deletions(-)
diff --git a/src/stagit.c b/src/stagit.c
@@ -321,6 +321,26 @@ xmlencodeline(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)
{