From 7f425243aefccc91bf603441c087da6e4be35d3d Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 3 Oct 2021 17:19:44 -0700 Subject: [PATCH] common: remove 'xml_url_string' 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 | 1 - lib/common/xml.c | 71 ---------------------------------------------- lib/gvc/gvc.def | 1 - 3 files changed, 73 deletions(-) diff --git a/lib/common/utils.h b/lib/common/utils.h index 37cd02397..bbb78c7aa 100644 --- a/lib/common/utils.h +++ b/lib/common/utils.h @@ -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); diff --git a/lib/common/xml.c b/lib/common/xml.c index ac13af781..9a246447e 100644 --- a/lib/common/xml.c +++ b/lib/common/xml.c @@ -1,12 +1,7 @@ -#include -#include #include #include #include -#include #include -#include -#include // 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; -} diff --git a/lib/gvc/gvc.def b/lib/gvc/gvc.def index 5cb297214..0dc35a06b 100644 --- a/lib/gvc/gvc.def +++ b/lib/gvc/gvc.def @@ -294,7 +294,6 @@ Verbose Version write_plain xml_escape -xml_url_string Y_invert zmalloc zrealloc -- 2.40.0