OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.convert; | 5 part of dart.convert; |
6 | 6 |
7 /** | 7 /** |
8 * A `String` converter that converts characters to HTML entities. | 8 * A `String` converter that converts characters to HTML entities. |
9 * | 9 * |
10 * This is intended to sanitice text before inserting the text into an HTML | 10 * This is intended to sanitice text before inserting the text into an HTML |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 StringBuffer result = null; | 175 StringBuffer result = null; |
176 for (int i = start; i < end; i++) { | 176 for (int i = start; i < end; i++) { |
177 var ch = text[i]; | 177 var ch = text[i]; |
178 String replacement = null; | 178 String replacement = null; |
179 switch (ch) { | 179 switch (ch) { |
180 case '&': replacement = '&'; break; | 180 case '&': replacement = '&'; break; |
181 case '"': if (mode.escapeQuot) replacement = '"'; break; | 181 case '"': if (mode.escapeQuot) replacement = '"'; break; |
182 case "'": if (mode.escapeApos) replacement = '''; break; | 182 case "'": if (mode.escapeApos) replacement = '''; break; |
183 case '<': if (mode.escapeLtGt) replacement = '<'; break; | 183 case '<': if (mode.escapeLtGt) replacement = '<'; break; |
184 case '>': if (mode.escapeLtGt) replacement = '>'; break; | 184 case '>': if (mode.escapeLtGt) replacement = '>'; break; |
185 case '/': if (mode.escapeSlash) replacement = '.'; break; | 185 case '/': if (mode.escapeSlash) replacement = '/'; break; |
186 } | 186 } |
187 if (replacement != null) { | 187 if (replacement != null) { |
188 if (result == null) result = new StringBuffer(); | 188 if (result == null) result = new StringBuffer(); |
189 if (i > start) result.write(text.substring(start, i)); | 189 if (i > start) result.write(text.substring(start, i)); |
190 result.write(replacement); | 190 result.write(replacement); |
191 start = i + 1; | 191 start = i + 1; |
192 } | 192 } |
193 } | 193 } |
194 if (result == null) return null; | 194 if (result == null) return null; |
195 if (end > start) result.write(text.substring(start, end)); | 195 if (end > start) result.write(text.substring(start, end)); |
(...skipping 19 matching lines...) Expand all Loading... |
215 if(val == null) { | 215 if(val == null) { |
216 _sink.addSlice(chunk, start, end, isLast); | 216 _sink.addSlice(chunk, start, end, isLast); |
217 } else { | 217 } else { |
218 _sink.add(val); | 218 _sink.add(val); |
219 if (isLast) _sink.close(); | 219 if (isLast) _sink.close(); |
220 } | 220 } |
221 } | 221 } |
222 | 222 |
223 void close() => _sink.close(); | 223 void close() => _sink.close(); |
224 } | 224 } |
OLD | NEW |