From b6a7abf02652b74872b9c676fcfa545e18d9bde7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 25 Nov 2017 18:37:26 +0100 Subject: Encode invalid XML characters instead of skipping them. The element in has a new optional attribute `value`, which contains value of given invalid ASCII character. In case of space, the `value` attribute is omitted. Use cases for this: including snippets of *very esoteric* languages, markup that makes use of the advanced ASCII formatting characters or for example highlighting a console output containing ANSI color codes (which is my case, in fact). Regarding backwards compatibility -- as files with such ASCII characters are very rare, I don't expect this minor difference in the output to be a problem. Besides that, such ASCII characters are often replaced by a space in many applications anyway. A test snippet was extended to contain a special character so this difference in behavior could be verified. --- src/xmlgen.cpp | 4 +++- templates/xml/compound.xsd | 6 +++++- testing/025/example_test_8cpp-example.xml | 2 +- testing/032/indexpage.xml | 2 +- testing/example_test.cpp | 2 ++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/xmlgen.cpp b/src/xmlgen.cpp index 1b03c3b..56e107b 100644 --- a/src/xmlgen.cpp +++ b/src/xmlgen.cpp @@ -136,7 +136,9 @@ inline void writeXMLCodeString(FTextStream &t,const char *s, int &col) case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: - break; // skip invalid XML characters (see http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char) + // encode invalid XML characters (see http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char) + t << ""; + break; default: s=writeUtf8Char(t,s-1); col++; break; } } diff --git a/templates/xml/compound.xsd b/templates/xml/compound.xsd index 8affc20..efe1481 100644 --- a/templates/xml/compound.xsd +++ b/templates/xml/compound.xsd @@ -279,12 +279,16 @@ - + + + + + diff --git a/testing/025/example_test_8cpp-example.xml b/testing/025/example_test_8cpp-example.xml index 96a1cd7..1e01cba 100644 --- a/testing/025/example_test_8cpp-example.xml +++ b/testing/025/example_test_8cpp-example.xml @@ -4,7 +4,7 @@ example_test.cpp This is an example of how to use the Test class. - More details about this example. voidmain(){Testt;t.example();} + More details about this example. voidmain(){constchar*a="Somespecialcharacterhere:";Testt;t.example();} diff --git a/testing/032/indexpage.xml b/testing/032/indexpage.xml index 3a25272..1894ae4 100644 --- a/testing/032/indexpage.xml +++ b/testing/032/indexpage.xml @@ -4,7 +4,7 @@ index My Project - Some text. voidmain(){Testt;t.example();} More text. voidmain(){Testt;t.example();} End. + Some text. voidmain(){constchar*a="Somespecialcharacterhere:";Testt;t.example();} More text. voidmain(){constchar*a="Somespecialcharacterhere:";Testt;t.example();} End. diff --git a/testing/example_test.cpp b/testing/example_test.cpp index f589023..a117b63 100644 --- a/testing/example_test.cpp +++ b/testing/example_test.cpp @@ -1,5 +1,7 @@ void main() { + const char* a = "Some special character here:  "; + Test t; t.example(); } -- cgit v0.12