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 // TODO(floitsch) - Document - Issue 13097 | 7 // TODO(floitsch) - Document - Issue 13097 |
8 const HtmlEscape HTML_ESCAPE = const HtmlEscape(); | 8 const HtmlEscape HTML_ESCAPE = const HtmlEscape(); |
9 | 9 |
10 class HtmlEscapeMode { | 10 class HtmlEscapeMode { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 if (result == null) result = new StringBuffer(text.substring(start, i)); | 65 if (result == null) result = new StringBuffer(text.substring(start, i)); |
66 result.write(replace); | 66 result.write(replace); |
67 } else if (result != null) { | 67 } else if (result != null) { |
68 result.write(ch); | 68 result.write(ch); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 return result != null ? result.toString() : null; | 72 return result != null ? result.toString() : null; |
73 } | 73 } |
74 | 74 |
75 StringConversionSink startChunkedConversion( | 75 StringConversionSink startChunkedConversion(Sink<String> sink) { |
76 ChunkedConversionSink<String> sink) { | |
77 | |
78 if (sink is! StringConversionSink) { | 76 if (sink is! StringConversionSink) { |
79 sink = new StringConversionSink.from(sink); | 77 sink = new StringConversionSink.from(sink); |
80 } | 78 } |
81 return new _HtmlEscapeSink(this, sink); | 79 return new _HtmlEscapeSink(this, sink); |
82 } | 80 } |
83 } | 81 } |
84 | 82 |
85 class _HtmlEscapeSink extends StringConversionSinkBase { | 83 class _HtmlEscapeSink extends StringConversionSinkBase { |
86 final HtmlEscape _escape; | 84 final HtmlEscape _escape; |
87 final StringConversionSink _sink; | 85 final StringConversionSink _sink; |
88 | 86 |
89 _HtmlEscapeSink(this._escape, this._sink); | 87 _HtmlEscapeSink(this._escape, this._sink); |
90 | 88 |
91 void addSlice(String chunk, int start, int end, bool isLast) { | 89 void addSlice(String chunk, int start, int end, bool isLast) { |
92 var val = _escape._convert(chunk, start, end); | 90 var val = _escape._convert(chunk, start, end); |
93 if(val == null) { | 91 if(val == null) { |
94 _sink.addSlice(chunk, start, end, isLast); | 92 _sink.addSlice(chunk, start, end, isLast); |
95 } else { | 93 } else { |
96 _sink.add(val); | 94 _sink.add(val); |
97 if (isLast) _sink.close(); | 95 if (isLast) _sink.close(); |
98 } | 96 } |
99 } | 97 } |
100 | 98 |
101 void close() => _sink.close(); | 99 void close() => _sink.close(); |
102 } | 100 } |
OLD | NEW |