Skip to content

Commit

Permalink
- Fix XmlDump; escape comments (bug #1101)
Browse files Browse the repository at this point in the history
- Fixed the rtest script, so that it is possible to have output that starts with "xmlNameSpace:..." or similar


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5903 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Aug 10, 2010
1 parent c90ce8d commit c6f0127
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 61 deletions.
8 changes: 8 additions & 0 deletions Compiler/Util.mo
Expand Up @@ -5889,5 +5889,13 @@ algorithm
end matchcontinue;
end makeValueOrDefault;

public function xmlEscape "Escapes a String so that it can be used in xml"
input String s1;
output String s2;
algorithm
s2 := stringReplaceChar(s1,"<","&lt;");
s2 := stringReplaceChar(s2,">","&gt;");
end xmlEscape;

end Util;

94 changes: 33 additions & 61 deletions Compiler/XMLDump.mo
Expand Up @@ -609,10 +609,8 @@ algorithm
equation
s1 = Exp.printExpStr(e1);
s2 = Exp.printExpStr(e2);
s1 = Util.stringReplaceChar(s1,"<","&lt;");
s1 = Util.stringReplaceChar(s1,">","&gt;");
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s1 = Util.xmlEscape(s1);
s2 = Util.xmlEscape(s2);
s = Util.stringAppendList({s1," = ",s2,"\n"});
dumpStrOpenTagAttr(ARRAY_EQUATION, EXP_STRING, s);
dumpStrOpenTag(MathML);
Expand All @@ -631,10 +629,8 @@ algorithm
equation
s1 = Exp.printExpStr(e1);
s2 = Exp.printExpStr(e2);
s1 = Util.stringReplaceChar(s1,"<","&lt;");
s1 = Util.stringReplaceChar(s1,">","&gt;");
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s1 = Util.xmlEscape(s1);
s2 = Util.xmlEscape(s2);
s = Util.stringAppendList({s1," = ",s2,"\n"});
dumpStrOpenTagAttr(ARRAY_EQUATION, EXP_STRING, s);
dumpStrCloseTag(ARRAY_EQUATION);
Expand All @@ -644,10 +640,8 @@ algorithm
equation
s1 = Exp.printExpStr(e1);
s2 = Exp.printExpStr(e2);
s1 = Util.stringReplaceChar(s1,"<","&lt;");
s1 = Util.stringReplaceChar(s1,">","&gt;");
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s1 = Util.xmlEscape(s1);
s2 = Util.xmlEscape(s2);
s = Util.stringAppendList({s1," - (",s2,") = 0\n"});
dumpStrOpenTagAttr(ARRAY_EQUATION, EXP_STRING, s);
dumpStrOpenTag(MathML);
Expand All @@ -670,10 +664,8 @@ algorithm
equation
s1 = Exp.printExpStr(e1);
s2 = Exp.printExpStr(e2);
s1 = Util.stringReplaceChar(s1,"<","&lt;");
s1 = Util.stringReplaceChar(s1,">","&gt;");
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s1 = Util.xmlEscape(s1);
s2 = Util.xmlEscape(s2);
s = Util.stringAppendList({s1," - (",s2,") = 0\n"});
dumpStrOpenTagAttr(ARRAY_EQUATION, EXP_STRING, s);
dumpStrCloseTag(ARRAY_EQUATION);
Expand Down Expand Up @@ -756,7 +748,9 @@ Function for adding comments using the XML tag.
"
input String inComment;
algorithm
Print.printBuf("<!--");Print.printBuf(inComment);Print.printBuf("-->");
Print.printBuf("<!--");
Print.printBuf(Util.xmlEscape(inComment));
Print.printBuf("-->");
end dumpComment;


Expand Down Expand Up @@ -1356,10 +1350,8 @@ algorithm
equation
s1 = Exp.printExpStr(e1);
s2 = Exp.printExpStr(e2);
s1 = Util.stringReplaceChar(s1,"<","&lt;");
s1 = Util.stringReplaceChar(s1,">","&gt;");
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s1 = Util.xmlEscape(s1);
s2 = Util.xmlEscape(s2);
res = Util.stringAppendList({s1," = ",s2});
dumpStrOpenTagAttr(EQUATION,ID,indexS);
Print.printBuf(res);
Expand All @@ -1378,10 +1370,8 @@ algorithm
equation
s1 = Exp.printExpStr(e1);
s2 = Exp.printExpStr(e2);
s1 = Util.stringReplaceChar(s1,"<","&lt;");
s1 = Util.stringReplaceChar(s1,">","&gt;");
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s1 = Util.xmlEscape(s1);
s2 = Util.xmlEscape(s2);
res = Util.stringAppendList({s1," = ",s2});
dumpStrOpenTagAttr(EQUATION,ID,indexS);
Print.printBuf(res);
Expand All @@ -1404,8 +1394,7 @@ algorithm
equation
s1 = Exp.printComponentRefStr(cr);
s2 = Exp.printExpStr(e2);
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s2 = Util.xmlEscape(s2);
res = Util.stringAppendList({s1," := ",s2});
dumpStrOpenTagAttr(stringAppend(SOLVED,EQUATION_),ID,indexS);
Print.printBuf(res);
Expand Down Expand Up @@ -1434,8 +1423,7 @@ algorithm
equation
s1 = Exp.printComponentRefStr(cr);
s2 = Exp.printExpStr(e2);
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s2 = Util.xmlEscape(s2);
is = intString(i);
res = Util.stringAppendList({s1," := ",s2});
dumpStrOpenTagAttr(stringAppend(WHEN,EQUATION_),ID,indexS);
Expand All @@ -1456,8 +1444,7 @@ algorithm
equation
s1 = Exp.printComponentRefStr(cr);
s2 = Exp.printExpStr(e2);
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s2 = Util.xmlEscape(s2);
is = intString(i);
res = Util.stringAppendList({s1," := ",s2});
dumpStrOpenTagAttr(stringAppend(WHEN,EQUATION_),ID,indexS);
Expand All @@ -1468,8 +1455,7 @@ algorithm
case (DAELow.RESIDUAL_EQUATION(exp = e),indexS,DAE.BCONST(bool=true))
equation
s1 = Exp.printExpStr(e);
s1 = Util.stringReplaceChar(s1,"<","&lt;");
s1 = Util.stringReplaceChar(s1,">","&gt;");
s1 = Util.xmlEscape(s1);
res = Util.stringAppendList({s1," = 0"});
dumpStrOpenTagAttr(stringAppend(RESIDUAL,EQUATION_),ID,indexS);
Print.printBuf(res);
Expand All @@ -1487,8 +1473,7 @@ algorithm
case (DAELow.RESIDUAL_EQUATION(exp = e),indexS,DAE.BCONST(bool=false))
equation
s1 = Exp.printExpStr(e);
s1 = Util.stringReplaceChar(s1,"<","&lt;");
s1 = Util.stringReplaceChar(s1,">","&gt;");
s1 = Util.xmlEscape(s1);
res = Util.stringAppendList({s1," = 0"});
dumpStrOpenTagAttr(stringAppend(RESIDUAL,EQUATION_),ID,indexS);
Print.printBuf(res);
Expand Down Expand Up @@ -2404,8 +2389,7 @@ algorithm
case ((e :: es),inContent,addMathMLCode)
equation
s = Exp.printExpStr(e);
s = Util.stringReplaceChar(s,"<","&lt;");
s = Util.stringReplaceChar(s,">","&gt;");
s = Util.xmlEscape(s);
dumpStrOpenTagAttr(inContent, EXP_STRING, s);
dumpExp(e,addMathMLCode);
dumpStrCloseTag(inContent);
Expand Down Expand Up @@ -3199,7 +3183,7 @@ algorithm
Print.printBuf("\" ");Print.printBuf(VAR_FIXED);Print.printBuf("=\"");Print.printBuf(varFixed);
Print.printBuf("\" ");Print.printBuf(VAR_FLOW);Print.printBuf("=\"");Print.printBuf(flowPrefix);
Print.printBuf("\" ");Print.printBuf(VAR_STREAM);Print.printBuf("=\"");Print.printBuf(streamPrefix);
Print.printBuf("\" ");Print.printBuf(VAR_COMMENT);Print.printBuf("=\"");Print.printBuf(comment);
Print.printBuf("\" ");Print.printBuf(VAR_COMMENT);Print.printBuf("=\"");Print.printBuf(Util.xmlEscape(comment));
Print.printBuf("\">");
then ();
/*
Expand Down Expand Up @@ -3657,9 +3641,7 @@ algorithm
case ((e as DAE.RELATION(e1,op,e2)))
equation
sym = Exp.relopSymbol(op);
// replace < and > with W3C standart &lt; and &gt;
sym = Util.stringReplaceChar(sym,"<","&lt;");
sym = Util.stringReplaceChar(sym,">","&gt;");
sym = Util.xmlEscape(sym);
s1 = printExpStr(e1);
s2 = printExpStr(e2);
p = Exp.expPriority(e);
Expand Down Expand Up @@ -3904,10 +3886,8 @@ algorithm
equation
s1 = Exp.printExpStr(e1);
s2 = Exp.printExpStr(e2);
s1 = Util.stringReplaceChar(s1,"<","&lt;");
s1 = Util.stringReplaceChar(s1,">","&gt;");
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s1 = Util.xmlEscape(s1);
s2 = Util.xmlEscape(s2);
res = Util.stringAppendList({s1," ( ",s2,") = 0"});
dumpStrOpenTagAttr(EQUATION,ID,indexS);
Print.printBuf(res);
Expand All @@ -3930,10 +3910,8 @@ algorithm
equation
s1 = Exp.printExpStr(e1);
s2 = Exp.printExpStr(e2);
s1 = Util.stringReplaceChar(s1,"<","&lt;");
s1 = Util.stringReplaceChar(s1,">","&gt;");
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s1 = Util.xmlEscape(s1);
s2 = Util.xmlEscape(s2);
res = Util.stringAppendList({s1," - ( ",s2, " ) = 0"});
dumpStrOpenTagAttr(EQUATION,ID,indexS);
Print.printBuf(res);
Expand All @@ -3956,8 +3934,7 @@ algorithm
equation
s1 = Exp.printComponentRefStr(cr);
s2 = Exp.printExpStr(e2);
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s2 = Util.xmlEscape(s2);
res = Util.stringAppendList({s1," - ( ",s2," ) := 0"});
dumpStrOpenTagAttr(stringAppend(SOLVED,EQUATION_),ID,indexS);
Print.printBuf(res);
Expand All @@ -3980,8 +3957,7 @@ algorithm
equation
s1 = Exp.printComponentRefStr(cr);
s2 = Exp.printExpStr(e2);
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s2 = Util.xmlEscape(s2);
res = Util.stringAppendList({s1," - (",s2,") := 0"});
dumpStrOpenTagAttr(stringAppend(SOLVED,EQUATION_),ID,indexS);
Print.printBuf(res);
Expand All @@ -3991,8 +3967,7 @@ algorithm
equation
s1 = Exp.printComponentRefStr(cr);
s2 = Exp.printExpStr(e2);
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s2 = Util.xmlEscape(s2);
is = intString(i);
res = Util.stringAppendList({s1," - (",s2,") := 0"});
dumpStrOpenTagAttr(stringAppend(WHEN,EQUATION_),ID,indexS);
Expand All @@ -4017,8 +3992,7 @@ algorithm
equation
s1 = Exp.printComponentRefStr(cr);
s2 = Exp.printExpStr(e2);
s2 = Util.stringReplaceChar(s2,"<","&lt;");
s2 = Util.stringReplaceChar(s2,">","&gt;");
s2 = Util.xmlEscape(s2);
is = intString(i);
res = Util.stringAppendList({s1," - (",s2,") := 0"});
dumpStrOpenTagAttr(stringAppend(WHEN,EQUATION_),ID,indexS);
Expand All @@ -4029,8 +4003,7 @@ algorithm
case (DAELow.RESIDUAL_EQUATION(exp = e),indexS,DAE.BCONST(bool=true))
equation
s1 = Exp.printExpStr(e);
s1 = Util.stringReplaceChar(s1,"<","&lt;");
s1 = Util.stringReplaceChar(s1,">","&gt;");
s1 = Util.xmlEscape(s1);
res = Util.stringAppendList({s1," = 0"});
dumpStrOpenTagAttr(stringAppend(RESIDUAL,EQUATION_),ID,indexS);
Print.printBuf(res);
Expand All @@ -4048,8 +4021,7 @@ algorithm
case (DAELow.RESIDUAL_EQUATION(exp = e),indexS,DAE.BCONST(bool=false))
equation
s1 = Exp.printExpStr(e);
s1 = Util.stringReplaceChar(s1,"<","&lt;");
s1 = Util.stringReplaceChar(s1,">","&gt;");
s1 = Util.xmlEscape(s1);
res = Util.stringAppendList({s1," = 0"});
dumpStrOpenTagAttr(stringAppend(RESIDUAL,EQUATION_),ID,indexS);
Print.printBuf(res);
Expand Down

0 comments on commit c6f0127

Please sign in to comment.