]> git.armaanb.net Git - stagit.git/commitdiff
add function to print a single line, ignoring \r and \n
authorHiltjo Posthuma <hiltjo@codemadness.org>
Thu, 25 Mar 2021 17:13:13 +0000 (18:13 +0100)
committerArmaan Bhojwani <me@armaanb.net>
Thu, 8 Apr 2021 01:54:38 +0000 (21:54 -0400)
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".

src/stagit.c

index 6b45b3601b9f86b36f18aa3655992f02103b6e28..ba154d05333c177a711508414be1c288118ca8c2 100644 (file)
@@ -300,6 +300,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("&lt;",   fp); break;
+               case '>':  fputs("&gt;",   fp); break;
+               case '\'': fputs("&#39;",  fp); break;
+               case '&':  fputs("&amp;",  fp); break;
+               case '"':  fputs("&quot;", fp); break;
+               case '\r': break; /* ignore CR */
+               case '\n': break; /* ignore LF */
+               default:   putc(*s, fp);
+               }
+       }
+}
+
 int
 mkdirp(const char *path)
 {