return 0;
}
-
char *xml_string(char *s)
{
static char *buf = NULL;
buf = grealloc(buf, bufsize);
p = buf + pos;
}
- /* these are safe even if string is already UTF-8 coded
+ /* escape '&' only if not part of a legal entity sequence */
+ if (*s == '&' && !(xml_isentity(s))) {
+ sub = "&";
+ len = 5;
+ }
+ /* '<' '>' are safe to substitute even if string is already UTF-8 coded
* since UTF-8 strings won't contain '<' or '>' */
- if (*s == '<') {
+ else if (*s == '<') {
sub = "<";
len = 4;
- } else if (*s == '>') {
+ }
+ else if (*s == '>') {
sub = ">";
len = 4;
- } else if (*s == '"') {
- sub = """;
- len = 6;
- } else if (*s == '-') { /* can't be used in xml comment strings */
+ }
+ else if (*s == '-') { /* can't be used in xml comment strings */
sub = "-";
len = 5;
- } else if (*s == '\'') {
- sub = "'";
- len = 5;
- } else if (*s == ' ' && prev && *prev == ' ') {
+ }
+ else if (*s == ' ' && prev && *prev == ' ') {
/* substitute 2nd and subsequent spaces with required_spaces */
sub = " "; /* inkscape doesn't recognise */
len = 6;
}
+ else if (*s == '"') {
+ sub = """;
+ len = 6;
+ }
+ else if (*s == '\'') {
+ sub = "'";
+ len = 5;
+ }
+ else {
+ sub = s;
+ len = 1;
+ }
+ while (len--) {
+ *p++ = *sub++;
+ pos++;
+ }
+ prev = s;
+ s++;
+ }
+ *p = '\0';
+ return buf;
+}
+
+/* a variant of xml_string for urls in hrefs */
+char *xml_url_string(char *s)
+{
+ static char *buf = NULL;
+ static int bufsize = 0;
+ char *p, *sub, *prev = NULL;
+ int len, pos = 0;
+
+ if (!buf) {
+ bufsize = 64;
+ buf = gmalloc(bufsize);
+ }
+
+ p = buf;
+ while (s && *s) {
+ if (pos > (bufsize - 8)) {
+ bufsize *= 2;
+ buf = grealloc(buf, bufsize);
+ p = buf + pos;
+ }
/* escape '&' only if not part of a legal entity sequence */
- else if (*s == '&' && !(xml_isentity(s))) {
+ if (*s == '&' && !(xml_isentity(s))) {
sub = "&";
len = 5;
- } else {
+ }
+#if 0
+ /* '<' '>' are safe to substitute even if string is already UTF-8 coded
+ * since UTF-8 strings won't contain '<' or '>' */
+ else if (*s == '<') {
+ sub = "<";
+ len = 4;
+ }
+ else if (*s == '>') {
+ sub = ">";
+ len = 4;
+ }
+ else if (*s == '-') { /* can't be used in xml comment strings */
+ sub = "-";
+ len = 5;
+ }
+ else if (*s == ' ' && prev && *prev == ' ') {
+ /* substitute 2nd and subsequent spaces with required_spaces */
+ sub = " "; /* inkscape doesn't recognise */
+ len = 6;
+ }
+#endif
+ else if (*s == '"') {
+ sub = """;
+ len = 6;
+ }
+ else if (*s == '\'') {
+ sub = "'";
+ len = 5;
+ }
+ else {
sub = s;
len = 1;
}
extern boolean isPolygon(node_t *);
extern char *strdup_and_subst_obj(char *str, void *obj);
extern char *xml_string(char *s);
+ extern char *xml_url_string(char *s);
extern void makeSelfEdge(path *, edge_t **, int, int, int, int,
splineInfo *);
extern textlabel_t *make_label(graph_t *g, int html, char *str,