Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of dart.convert; | |
| 6 | |
| 7 const HTML_ESCAPE = const HtmlEscape(); | |
| 8 | |
| 9 class HtmlEscape extends Converter<String, String> { | |
|
Bob Nystrom
2013/08/27 18:03:57
Document all of this.
| |
| 10 | |
| 11 const HtmlEscape(); | |
| 12 | |
| 13 String convert(String data) => _convert(data); | |
| 14 | |
| 15 StringConversionSink startChunkedConversion( | |
| 16 ChunkedConversionSink<String> sink) { | |
| 17 | |
| 18 if (sink is! StringConversionSink) { | |
| 19 sink = new StringConversionSink.from(sink); | |
| 20 } | |
| 21 return new _HtmlEscapeSink(sink); | |
| 22 } | |
| 23 | |
| 24 static String _convert(String data) { | |
| 25 return data.replaceAll("&", "&") | |
| 26 .replaceAll("<", "<") | |
| 27 .replaceAll(">", ">") | |
| 28 .replaceAll('"', """) | |
| 29 .replaceAll("'", "'") | |
| 30 .replaceAll('\u00A0', ' '); | |
| 31 } | |
| 32 | |
| 33 } | |
| 34 | |
| 35 class _HtmlEscapeSink extends StringConversionSinkBase { | |
| 36 final StringConversionSink _sink; | |
| 37 | |
| 38 _HtmlEscapeSink(this._sink); | |
| 39 | |
| 40 void addSlice(String chunk, int start, int end, bool isLast) { | |
| 41 _sink.add(HtmlEscape._convert(chunk.substring(start, end))); | |
| 42 if (isLast) _sink.close(); | |
| 43 } | |
| 44 | |
| 45 void close() => _sink.close(); | |
| 46 } | |
| OLD | NEW |