]> granicus.if.org Git - graphviz/commitdiff
common: remove 'xml_url_string'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 4 Oct 2021 00:19:44 +0000 (17:19 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 8 Oct 2021 14:57:43 +0000 (07:57 -0700)
As of the previous commit, all calls to `xml_url_string` have been replaced with
calls to `xml_escape`.

Related to #1868.

lib/common/utils.h
lib/common/xml.c
lib/gvc/gvc.def

index 37cd023976f4555f03d73794b6940159626e1c82..bbb78c7aad1cf444f7cf86894edc4e37c8251dc2 100644 (file)
@@ -65,7 +65,6 @@ extern "C" {
     UTILS_API double yDir (double y);
     UTILS_API char *ps_string(char *s, int);
     UTILS_API char *strdup_and_subst_obj(char *str, void *obj);
-    UTILS_API char *xml_url_string(char *s);
     UTILS_API void epsf_emit_body(GVJ_t *job, usershape_t *us);
     UTILS_API void epsf_define(GVJ_t * job);
     UTILS_API void undoClusterEdges(graph_t * g);
index ac13af781ac657c2126e5e9dfe297f849f8b6da0..9a246447e9236327a8f4ed763595f964d5b382fd 100644 (file)
@@ -1,12 +1,7 @@
-#include <assert.h>
-#include <common/memory.h>
 #include <common/types.h>
 #include <common/utils.h>
 #include <ctype.h>
-#include <limits.h>
 #include <stdbool.h>
-#include <stddef.h>
-#include <string.h>
 
 // variant of `isalpha` that assumes a C locale
 static bool isalpha_no_locale(char c) {
@@ -115,69 +110,3 @@ int xml_escape(const char *s, xml_flags_t flags,
   }
   return rc;
 }
-
-// a dynamically resizable string
-typedef struct {
-  char *base;
-  size_t length;
-  size_t capacity;
-} buffer_t;
-
-/** Write string data to a buffer
- *
- * \param dst A `buffer_t` to write to, but `void*` typed to align with the
- *   callback type `xml_core` expects.
- * \param src String to append.
- * \return Number of characters written.
- */
-static int buffer_put(void *dst, const char *src) {
-
-  buffer_t *buffer = dst;
-  size_t length = strlen(src);
-
-  // do we need to expand this buffer?
-  assert(buffer->base != NULL && "buffer not initialized in xml_url_string?");
-  while (length > buffer->capacity ||
-         buffer->capacity - length <= buffer->length) {
-    size_t capacity = buffer->capacity == 0 ? 64 : (buffer->capacity * 2);
-    char *base = grealloc(buffer->base, capacity);
-    buffer->base = base;
-    buffer->capacity = capacity;
-  }
-
-  // write source data into the buffer
-  strcpy(buffer->base + buffer->length, src);
-  buffer->length += length;
-
-  // `xml_core` should only have given us short data
-  assert(length <= INT_MAX && "too large XML escape sequence");
-  return (int)length;
-}
-
-/* a variant of xml_string for urls in hrefs */
-char *xml_url_string(char *s) {
-  static char *buf = NULL;
-  static size_t bufsize = 0;
-
-  const xml_flags_t flags = {0};
-
-  if (!buf) {
-    bufsize = 64;
-    buf = gmalloc(bufsize);
-  }
-
-  // generate n escaped version of this string into `buf`
-  buffer_t buffer = {.base = buf, .capacity = bufsize};
-  while (s && *s) {
-    (void)xml_core('\0', s, flags, buffer_put, &buffer);
-    s++;
-  }
-  assert(buffer.length < buffer.capacity && "no room for NUL");
-  buffer.base[buffer.length] = '\0';
-
-  // save the static buffer (it may have been realloced) for reuse next time
-  buf = buffer.base;
-  bufsize = buffer.capacity;
-
-  return buf;
-}
index 5cb297214444e090f17773ea494b4fe52d92ecea..0dc35a06be895e23582e3b057bc66927e1bc2c8d 100644 (file)
@@ -294,7 +294,6 @@ Verbose
 Version    
 write_plain    
 xml_escape
-xml_url_string    
 Y_invert    
 zmalloc    
 zrealloc