Skip to content

Commit 5cc7c6a

Browse files
committed
Merge pull request #2 from BRONSOLO/master
The episode of Who's the Boss where Tony "checks for needed escape characters."
2 parents e82d136 + cb77cef commit 5cc7c6a

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

plotly/plotly_aux/check_escape.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function [ escaped_val ] = check_escape(val)
2+
%adds '\' escape character if needed
3+
ec = '\';
4+
ind = find( (val == '"') | (val == '\' ));
5+
if(ind)
6+
if(ind(1) == 1)
7+
val = ['\' val];
8+
ind = ind + 1;
9+
ind(1) = [];
10+
end
11+
if (ind)
12+
val = [val ec(ones(1,length(ind)))]; %extend lengh of val to prep for char shifts.
13+
for i = 1:length(ind)
14+
val(ind(i):end) = [ec val(ind(i):end-1)];
15+
ind = ind+1;
16+
end
17+
end
18+
end
19+
20+
escaped_val = val;

plotly/plotly_aux/m2json.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
valstr = strrep(valstr, 'Inf', 'null');
2626
valstr = strrep(valstr, 'NaN', 'null');
2727
elseif ischar(val)
28+
val = check_escape(val); %add escape characters
2829
valstr = ['"' val '"'];
2930
elseif islogical(val)
3031
if val
Loading

0 commit comments

Comments
 (0)