Skip to content

Commit

Permalink
Fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed May 20, 2024
1 parent 23329e7 commit 0b3cd5c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import java.util.regex.Pattern;

/**
* Implementation of XMLWriter which emits nicely formatted documents.
*
* <p>Implementation of XMLWriter which emits nicely formatted documents.</p>
*
* <p>C0 controls chars are omitted from output</p>
*/
public class PrettyPrintXMLWriter implements XMLWriter {
/** Line separator ("\n" on UNIX) */
Expand Down Expand Up @@ -226,9 +226,9 @@ private static String escapeXml(String text) {

private static final Pattern crlf = Pattern.compile(crlf_str);

private static final Pattern lowers = Pattern.compile("([\000-\037])");
private static final Pattern lowers = Pattern.compile("([\\x00-\\x1F])");

private static final Pattern lowersText = Pattern.compile("([\000-\010\013-\014\016-\037])");
private static final Pattern illegalC0Characters = Pattern.compile("([\\x00-\\x08\\x0B-\\x0C\\x0E-\\x1F])");

private static String escapeXmlAttribute(String text) {
text = escapeXmlText(text);
Expand All @@ -252,12 +252,12 @@ private static String escapeXmlAttribute(String text) {
private static String escapeXmlText(String text) {
text = escapeXml(text);

Matcher m = lowersText.matcher(text);
Matcher matcher = illegalC0Characters.matcher(text);
StringBuffer b = new StringBuffer();
while (m.find()) {
m = m.appendReplacement(b, "");
while (matcher.find()) {
matcher = matcher.appendReplacement(b, "");
}
m.appendTail(b);
matcher.appendTail(b);

return b.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* <li>PROPERTY_SERIALIZER_INDENTATION
* <li>PROPERTY_SERIALIZER_LINE_SEPARATOR
* </ul>
* <p>C0 controls chars are omitted from output</p>
*/
public class MXSerializer implements XmlSerializer {
protected static final String XML_URI = "http://www.w3.org/XML/1998/namespace";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ private String expectedOutput() {
out.append("<?xml version=\"1.0\" standalone=\"yes\"?>");
out.append("<root>");
out.append("<char>BACKSPACE: </char>");
out.append("<char>CHARACTER TABULATION: \t");
out.append("</char><char>LINE FEED (LF): \n");
out.append("</char><char>LINE TABULATION: </char>");
out.append("<char>CARRIAGE RETURN (CR): \r");
out.append("</char><char>SHIFT IN: </char>");
out.append("<char>CHARACTER TABULATION: \t</char>");
out.append("<char>LINE FEED (LF): \n</char>");
out.append("<char>LINE TABULATION: </char>");
out.append("<char>CARRIAGE RETURN (CR): \r</char>");
out.append("<char>SHIFT IN: </char>");
out.append("</root>");
return out.toString();
}
Expand Down

0 comments on commit 0b3cd5c

Please sign in to comment.