]> granicus.if.org Git - graphviz/commitdiff
implement a 'gvputs' alternative that does XML-escaping
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 3 Oct 2021 16:35:36 +0000 (09:35 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 8 Oct 2021 14:50:57 +0000 (07:50 -0700)
This will be used in an upcoming commit to replace `gvputs` when used in
combination with `xml_string`.

Related to #1868.

lib/gvc/gvc.def
lib/gvc/gvdevice.c
lib/gvc/gvio.h

index 842ebde885c05161a5c865ae77073e55315890e4..45d2b8d84981a28566324dc4d1a8b983a044436a 100644 (file)
@@ -151,6 +151,7 @@ gvprintpointf
 gvprintpointflist    
 gvputc    
 gvputs    
+gvputs_xml
 gvRender    
 gvRenderData    
 gvFreeRenderData    
index 3328e2c3cf71a33a604ea9d26955bc6e62b4ebc8..5f3d670b94f80a74a1366a490cd0a1902ae55c77 100644 (file)
@@ -52,6 +52,7 @@ static uint64_t crc;
 #include <gvc/gvcint.h>
 #include <gvc/gvcproc.h>
 #include <common/logic.h>
+#include <common/utils.h>
 #include <gvc/gvio.h>
 
 static const int PAGE_ALIGN = 4095;            /* align to a 4K boundary (less one), typical for Linux, Mac OS X and Windows memory allocation */
@@ -272,6 +273,11 @@ int gvputs(GVJ_t * job, const char *s)
     return 1;
 }
 
+int gvputs_xml(GVJ_t *job, const char *s) {
+  const xml_flags_t flags = {.dash = 1, .nbsp = 1};
+  return xml_escape(s, flags, (int (*)(void *, const char *))gvputs, job);
+}
+
 int gvputc(GVJ_t * job, int c)
 {
     const char cc = c;
index e3a8cf50f15851d20b0c0a77b6802668e7784712..fadc431f7ac4f9462485bba3ee9a9091c09f607f 100644 (file)
@@ -39,6 +39,10 @@ extern "C" {
     GVIO_API int gvferror (FILE *stream);
     GVIO_API int gvputc(GVJ_t * job, int c);
     GVIO_API int gvputs(GVJ_t * job, const char *s);
+
+    // `gvputs`, but XML-escape the input string
+    GVIO_API int gvputs_xml(GVJ_t* job, const char *s);
+
     GVIO_API int gvflush (GVJ_t * job);
     GVIO_API void gvprintf(GVJ_t * job, const char *format, ...);
     GVIO_API void gvprintdouble(GVJ_t * job, double num);