comparison src/goodjava/xml/XmlElement.java @ 1469:21f5edab1fbf

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 14 Apr 2020 13:15:18 -0600
parents 35f3bfd4f51d
children a8c685a894b4
comparison
equal deleted inserted replaced
1468:35f3bfd4f51d 1469:21f5edab1fbf
78 for( int i=0; i<indented; i++ ) { 78 for( int i=0; i<indented; i++ ) {
79 sb.append('\t'); 79 sb.append('\t');
80 } 80 }
81 } 81 }
82 82
83 private static String encode(String s) { 83 public static String encode(String s) {
84 final char[] a = s.toCharArray(); 84 final char[] a = s.toCharArray();
85 StringBuilder buf = new StringBuilder(); 85 StringBuilder buf = new StringBuilder();
86 for( int i=0; i<a.length; i++ ) { 86 for( char c : a ) {
87 char c = a[i];
88 switch(c) { 87 switch(c) {
89 case '&': 88 case '&':
90 buf.append("&amp;"); 89 buf.append("&amp;");
91 break; 90 break;
92 case '<': 91 case '<':
96 buf.append("&gt;"); 95 buf.append("&gt;");
97 break; 96 break;
98 case '"': 97 case '"':
99 buf.append("&quot;"); 98 buf.append("&quot;");
100 break; 99 break;
100 case '\'':
101 buf.append("&apos;");
102 break;
101 default: 103 default:
102 buf.append(c); 104 buf.append(c);
103 } 105 }
104 } 106 }
105 return buf.toString(); 107 return buf.toString();