Commit 39a6b8fb authored by Albert Gräf's avatar Albert Gräf
Browse files

Escape a literal # in the iemguis so that it can be used inside labels.

This fixes #427.

We do this by tacking on a tilde if # is followed by a digit, to prevent it
from being mistaken for a $ substitution (which happens because $ becomes # in
FUDI, which is required behavior by non-iem gui objects and thus we don't want
to break this). The tilde gets removed automatically when the label is sent to
the gui.

All this is implemented using the existing symbol mungers in the
iemgui_dollar2raute and iemgui_raute2dollar functions in g_all_guis.c and
iemgui_escape and iemgui_unescape in dialog_iemgui.html.
parent 84cbd6b5
Pipeline #1244 passed with stage
in 310 minutes and 32 seconds
......@@ -379,8 +379,14 @@ function iemgui_escape(s) {
if (arr[i] === "$" && i+1 < arr.length &&
arr[i+1] >= "0" && arr[i+1] <= "9") {
arr[i] = "#";
// AG: handle literal '#' followed by digit, tack a tilde onto it to
// prevent it from being interpreted as a '$' substitution
} else if (arr[i] === "#" && i+1 < arr.length &&
arr[i+1] >= "0" && arr[i+1] <= "9") {
arr[i] = "#~";
}
}
//if (s != arr.join("")) pdgui.post("iemgui_escape: '" + s + "' -> '" + arr.join("") + "'");
s = arr.join("");
s = substitute_space(s);
s = strip_problem_chars(s);
......@@ -390,11 +396,15 @@ function iemgui_escape(s) {
function iemgui_unescape(s) {
var arr = s.split("");
for (var i = 0; i < arr.length; i++) {
if (arr[i] === "#" && i+1 < arr.length &&
// AG: handle escaped '#'
if (arr[i] === "#" && i > 0 && i+1 < arr.length && arr[i+1] == "~") {
arr[i] = "#"; arr[++i] = "";
} else if (arr[i] === "#" && i+1 < arr.length &&
arr[i+1] >= "0" && arr[i+1] <= "9") {
arr[i] = "$";
}
}
//if (s != arr.join("")) pdgui.post("iemgui_unescape: '" + s + "' -> '" + arr.join("") + "'");
s = arr.join("");
return s;
}
......@@ -412,9 +422,16 @@ function send_params(attrs, create_undo_point) {
var send_symbol = attrs.send_symbol,
receive_symbol = attrs.receive_symbol,
label = attrs["label"];
send_symbol = iemgui_escape(send_symbol);
receive_symbol = iemgui_escape(receive_symbol);
label = iemgui_escape(label);
// AG: We only escape these values again if they actually changed. This
// check is necessary because iemgui_escape isn't idempotent and will thus
// wreak havoc if it's applied to a value which didn't change and is still
// in the original escaped format.
if (send_symbol != old_attrs.send_symbol)
send_symbol = iemgui_escape(send_symbol);
if (receive_symbol != old_attrs.receive_symbol)
receive_symbol = iemgui_escape(receive_symbol);
if (label != old_attrs["label"])
label = iemgui_escape(label);
var label_x_offset = attrs.x_offset;
var label_y_offset = attrs.y_offset;
......
......@@ -53,11 +53,19 @@ t_symbol *iemgui_dollar2raute(t_symbol *s)
return (s);
for (s1 = s->s_name, s2 = buf; ; s1++, s2++)
{
if (*s1 == '$' && *s1 && isdigit(s1[1]))
if (*s1 == '$' && isdigit(s1[1]))
*s2 = '#';
else if (!(*s2 = *s1))
// AG: handle literal '#' followed by digit, tack a tilde onto it to
// prevent it from being interpreted as a '$' substitution
else if (*s1 == '#' && isdigit(s1[1])) {
// make sure that we don't overflow the buffer
if (s2-buf+2 >= MAXPDSTRING)
return (s);
*s2++ = '#'; *s2 = '~';
} else if (!(*s2 = *s1))
break;
}
//if (strcmp(s->s_name, buf) != 0) fprintf(stderr, "+++ iemgui_dollar2raute: '%s' -> '%s'\n", s->s_name, buf);
return(gensym(buf));
}
......@@ -68,11 +76,15 @@ t_symbol *iemgui_raute2dollar(t_symbol *s)
return (s);
for (s1 = s->s_name, s2 = buf; ; s1++, s2++)
{
if (*s1 == '#' && *s1 && isdigit(s1[1]))
// AG: handle escaped '#'
if (*s1 == '#' && s1[1] == '~') {
*s2 = '#'; s1++;
} else if (*s1 == '#' && isdigit(s1[1]))
*s2 = '$';
else if (!(*s2 = *s1))
break;
}
//if (strcmp(s->s_name, buf) != 0) fprintf(stderr, "+++ iemgui_raute2dollar: '%s' -> '%s'\n", s->s_name, buf);
return(gensym(buf));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment