24
24
import java .util .regex .Pattern ;
25
25
26
26
/**
27
- * Implementation of XMLWriter which emits nicely formatted documents.
28
- *
27
+ * <p>Implementation of XMLWriter which emits nicely formatted documents.</p>
29
28
*
29
+ * <p>C0 controls chars are omitted from output</p>
30
30
*/
31
31
public class PrettyPrintXMLWriter implements XMLWriter {
32
32
/** Line separator ("\n" on UNIX) */
@@ -226,9 +226,9 @@ private static String escapeXml(String text) {
226
226
227
227
private static final Pattern crlf = Pattern .compile (crlf_str );
228
228
229
- private static final Pattern lowers = Pattern .compile ("([\000 - \037 ])" );
229
+ private static final Pattern lowers = Pattern .compile ("([\\ x00- \\ x1F ])" );
230
230
231
- private static final Pattern lowersText = Pattern .compile ("([\000 - \010 \013 - \014 \016 - \037 ])" );
231
+ private static final Pattern illegalC0Characters = Pattern .compile ("([\\ x00- \\ x08 \\ x0B- \\ x0C \\ x0E- \\ x1F ])" );
232
232
233
233
private static String escapeXmlAttribute (String text ) {
234
234
text = escapeXmlText (text );
@@ -252,12 +252,12 @@ private static String escapeXmlAttribute(String text) {
252
252
private static String escapeXmlText (String text ) {
253
253
text = escapeXml (text );
254
254
255
- Matcher m = lowersText .matcher (text );
255
+ Matcher matcher = illegalC0Characters .matcher (text );
256
256
StringBuffer b = new StringBuffer ();
257
- while (m .find ()) {
258
- m = m .appendReplacement (b , "" );
257
+ while (matcher .find ()) {
258
+ matcher = matcher .appendReplacement (b , "" );
259
259
}
260
- m .appendTail (b );
260
+ matcher .appendTail (b );
261
261
262
262
return b .toString ();
263
263
}
0 commit comments