| OLD | NEW |
| 1 part of dart.convert; | 1 part of dart.convert; |
| 2 | 2 abstract class StringConversionSink extends ChunkedConversionSink<String> {Stri
ngConversionSink(); |
| 3 abstract class StringConversionSink extends ChunkedConversionSink<String> { | 3 factory StringConversionSink.withCallback(void callback(String accumulated)) =
_StringCallbackSink; |
| 4 StringConversionSink(); | 4 factory StringConversionSink.from(Sink<String> sink) = _StringAdapterSink; |
| 5 factory StringConversionSink.withCallback( | 5 factory StringConversionSink.fromStringSink(StringSink sink) = _StringSinkConve
rsionSink; |
| 6 void callback(String accumulated)) = _StringCallbackSink; | 6 void addSlice(String chunk, int start, int end, bool isLast); |
| 7 factory StringConversionSink.from(Sink<String> sink) = _StringAdapterSink; | 7 ByteConversionSink asUtf8Sink(bool allowMalformed); |
| 8 factory StringConversionSink.fromStringSink( | 8 ClosableStringSink asStringSink(); |
| 9 StringSink sink) = _StringSinkConversionSink; | |
| 10 void addSlice(String chunk, int start, int end, bool isLast); | |
| 11 ByteConversionSink asUtf8Sink(bool allowMalformed); | |
| 12 ClosableStringSink asStringSink(); | |
| 13 } | 9 } |
| 14 abstract class ClosableStringSink extends StringSink { | 10 abstract class ClosableStringSink extends StringSink {factory ClosableStringSin
k.fromStringSink(StringSink sink, void onClose()) = _ClosableStringSink; |
| 15 factory ClosableStringSink.fromStringSink( | 11 void close(); |
| 16 StringSink sink, void onClose()) = _ClosableStringSink; | |
| 17 void close(); | |
| 18 } | 12 } |
| 19 typedef void _StringSinkCloseCallback(); | 13 typedef void _StringSinkCloseCallback(); |
| 20 class _ClosableStringSink implements ClosableStringSink { | 14 class _ClosableStringSink implements ClosableStringSink {final _StringSinkClose
Callback _callback; |
| 21 final _StringSinkCloseCallback _callback; | 15 final StringSink _sink; |
| 22 final StringSink _sink; | 16 _ClosableStringSink(this._sink, this._callback); |
| 23 _ClosableStringSink(this._sink, this._callback); | 17 void close() => _callback(); |
| 24 void close() => _callback(); | 18 void writeCharCode(int charCode) => _sink.writeCharCode(charCode); |
| 25 void writeCharCode(int charCode) => _sink.writeCharCode(charCode); | 19 void write(Object o) => _sink.write(o); |
| 26 void write(Object o) => _sink.write(o); | 20 void writeln([Object o = ""]) => _sink.writeln(o); |
| 27 void writeln([Object o = ""]) => _sink.writeln(o); | 21 void writeAll(Iterable objects, [String separator = ""]) => _sink.writeAll(obje
cts, separator); |
| 28 void writeAll(Iterable objects, [String separator = ""]) => | |
| 29 _sink.writeAll(objects, separator); | |
| 30 } | 22 } |
| 31 class _StringConversionSinkAsStringSinkAdapter implements ClosableStringSink { | 23 class _StringConversionSinkAsStringSinkAdapter implements ClosableStringSink {s
tatic const _MIN_STRING_SIZE = 16; |
| 32 static const _MIN_STRING_SIZE = 16; | 24 StringBuffer _buffer; |
| 33 StringBuffer _buffer; | 25 StringConversionSink _chunkedSink; |
| 34 StringConversionSink _chunkedSink; | 26 _StringConversionSinkAsStringSinkAdapter(this._chunkedSink) : _buffer = new Str
ingBuffer(); |
| 35 _StringConversionSinkAsStringSinkAdapter(this._chunkedSink) | 27 void close() { |
| 36 : _buffer = new StringBuffer(); | 28 if (_buffer.isNotEmpty) _flush(); |
| 37 void close() { | 29 _chunkedSink.close(); |
| 38 if (_buffer.isNotEmpty) _flush(); | |
| 39 _chunkedSink.close(); | |
| 40 } | |
| 41 void writeCharCode(int charCode) { | |
| 42 _buffer.writeCharCode(charCode); | |
| 43 if (_buffer.length > _MIN_STRING_SIZE) _flush(); | |
| 44 } | |
| 45 void write(Object o) { | |
| 46 if (_buffer.isNotEmpty) _flush(); | |
| 47 String str = o.toString(); | |
| 48 _chunkedSink.add(o.toString()); | |
| 49 } | |
| 50 void writeln([Object o = ""]) { | |
| 51 _buffer.writeln(o); | |
| 52 if (_buffer.length > _MIN_STRING_SIZE) _flush(); | |
| 53 } | |
| 54 void writeAll(Iterable objects, [String separator = ""]) { | |
| 55 if (_buffer.isNotEmpty) _flush(); | |
| 56 Iterator iterator = objects.iterator; | |
| 57 if (!iterator.moveNext()) return; | |
| 58 if (separator.isEmpty) { | |
| 59 do { | |
| 60 _chunkedSink.add(((__x27) => DDC$RT.cast(__x27, dynamic, String, | |
| 61 "CastGeneral", | |
| 62 """line 147, column 26 of dart:convert/string_conversion.dart: """, | |
| 63 __x27 is String, true))(iterator.current.toString())); | |
| 64 } while (iterator.moveNext()); | |
| 65 } else { | |
| 66 _chunkedSink.add(((__x28) => DDC$RT.cast(__x28, dynamic, String, | |
| 67 "CastGeneral", | |
| 68 """line 150, column 24 of dart:convert/string_conversion.dart: """, | |
| 69 __x28 is String, true))(iterator.current.toString())); | |
| 70 while (iterator.moveNext()) { | |
| 71 write(separator); | |
| 72 _chunkedSink.add(((__x29) => DDC$RT.cast(__x29, dynamic, String, | |
| 73 "CastGeneral", | |
| 74 """line 153, column 26 of dart:convert/string_conversion.dart: """, | |
| 75 __x29 is String, true))(iterator.current.toString())); | |
| 76 } | |
| 77 } | |
| 78 } | |
| 79 void _flush() { | |
| 80 String accumulated = _buffer.toString(); | |
| 81 _buffer.clear(); | |
| 82 _chunkedSink.add(accumulated); | |
| 83 } | |
| 84 } | 30 } |
| 85 abstract class StringConversionSinkBase extends StringConversionSinkMixin {} | 31 void writeCharCode(int charCode) { |
| 86 abstract class StringConversionSinkMixin implements StringConversionSink { | 32 _buffer.writeCharCode(charCode); |
| 87 void addSlice(String str, int start, int end, bool isLast); | 33 if (_buffer.length > _MIN_STRING_SIZE) _flush(); |
| 88 void close(); | |
| 89 void add(String str) => addSlice(str, 0, str.length, false); | |
| 90 ByteConversionSink asUtf8Sink(bool allowMalformed) { | |
| 91 return new _Utf8ConversionSink(this, allowMalformed); | |
| 92 } | |
| 93 ClosableStringSink asStringSink() { | |
| 94 return new _StringConversionSinkAsStringSinkAdapter(this); | |
| 95 } | |
| 96 } | 34 } |
| 97 class _StringSinkConversionSink extends StringConversionSinkBase { | 35 void write(Object o) { |
| 98 StringSink _stringSink; | 36 if (_buffer.isNotEmpty) _flush(); |
| 99 _StringSinkConversionSink(StringSink this._stringSink); | 37 String str = o.toString(); |
| 100 void close() {} | 38 _chunkedSink.add(o.toString()); |
| 101 void addSlice(String str, int start, int end, bool isLast) { | |
| 102 if (start != 0 || end != str.length) { | |
| 103 for (int i = start; i < end; i++) { | |
| 104 _stringSink.writeCharCode(str.codeUnitAt(i)); | |
| 105 } | |
| 106 } else { | |
| 107 _stringSink.write(str); | |
| 108 } | |
| 109 if (isLast) close(); | |
| 110 } | |
| 111 void add(String str) => _stringSink.write(str); | |
| 112 ByteConversionSink asUtf8Sink(bool allowMalformed) { | |
| 113 return new _Utf8StringSinkAdapter(this, _stringSink, allowMalformed); | |
| 114 } | |
| 115 ClosableStringSink asStringSink() { | |
| 116 return new ClosableStringSink.fromStringSink(_stringSink, this.close); | |
| 117 } | |
| 118 } | 39 } |
| 119 class _StringCallbackSink extends _StringSinkConversionSink { | 40 void writeln([Object o = ""]) { |
| 120 final _ChunkedConversionCallback<String> _callback; | 41 _buffer.writeln(o); |
| 121 _StringCallbackSink(this._callback) : super(new StringBuffer()); | 42 if (_buffer.length > _MIN_STRING_SIZE) _flush(); |
| 122 void close() { | |
| 123 StringBuffer buffer = DDC$RT.cast(_stringSink, StringSink, StringBuffer, | |
| 124 "CastGeneral", | |
| 125 """line 233, column 27 of dart:convert/string_conversion.dart: """, | |
| 126 _stringSink is StringBuffer, true); | |
| 127 String accumulated = buffer.toString(); | |
| 128 buffer.clear(); | |
| 129 _callback(accumulated); | |
| 130 } | |
| 131 ByteConversionSink asUtf8Sink(bool allowMalformed) { | |
| 132 return new _Utf8StringSinkAdapter(this, _stringSink, allowMalformed); | |
| 133 } | |
| 134 } | 43 } |
| 135 class _StringAdapterSink extends StringConversionSinkBase { | 44 void writeAll(Iterable objects, [String separator = ""]) { |
| 136 final Sink<String> _sink; | 45 if (_buffer.isNotEmpty) _flush(); |
| 137 _StringAdapterSink(this._sink); | 46 Iterator iterator = objects.iterator; |
| 138 void add(String str) => _sink.add(str); | 47 if (!iterator.moveNext()) return; if (separator.isEmpty) { |
| 139 void addSlice(String str, int start, int end, bool isLast) { | 48 do { |
| 140 if (start == 0 && end == str.length) { | 49 _chunkedSink.add(((__x27) => DDC$RT.cast(__x27, dynamic, String, "CastGeneral",
"""line 147, column 26 of dart:convert/string_conversion.dart: """, __x27 is Str
ing, true))(iterator.current.toString())); |
| 141 add(str); | |
| 142 } else { | |
| 143 add(str.substring(start, end)); | |
| 144 } | |
| 145 if (isLast) close(); | |
| 146 } | |
| 147 void close() => _sink.close(); | |
| 148 } | 50 } |
| 149 class _Utf8StringSinkAdapter extends ByteConversionSink { | 51 while (iterator.moveNext());} |
| 150 final _Utf8Decoder _decoder; | 52 else { |
| 151 final Sink _sink; | 53 _chunkedSink.add(((__x28) => DDC$RT.cast(__x28, dynamic, String, "CastGeneral",
"""line 150, column 24 of dart:convert/string_conversion.dart: """, __x28 is Str
ing, true))(iterator.current.toString())); |
| 152 _Utf8StringSinkAdapter(this._sink, StringSink stringSink, bool allowMalformed) | 54 while (iterator.moveNext()) { |
| 153 : _decoder = new _Utf8Decoder(stringSink, allowMalformed); | 55 write(separator); |
| 154 void close() { | 56 _chunkedSink.add(((__x29) => DDC$RT.cast(__x29, dynamic, String, "CastGeneral",
"""line 153, column 26 of dart:convert/string_conversion.dart: """, __x29 is St
ring, true))(iterator.current.toString())); |
| 155 _decoder.close(); | |
| 156 if (_sink != null) _sink.close(); | |
| 157 } | |
| 158 void add(List<int> chunk) { | |
| 159 addSlice(chunk, 0, chunk.length, false); | |
| 160 } | |
| 161 void addSlice( | |
| 162 List<int> codeUnits, int startIndex, int endIndex, bool isLast) { | |
| 163 _decoder.convert(codeUnits, startIndex, endIndex); | |
| 164 if (isLast) close(); | |
| 165 } | |
| 166 } | 57 } |
| 167 class _Utf8ConversionSink extends ByteConversionSink { | |
| 168 final _Utf8Decoder _decoder; | |
| 169 final StringConversionSink _chunkedSink; | |
| 170 final StringBuffer _buffer; | |
| 171 _Utf8ConversionSink(StringConversionSink sink, bool allowMalformed) | |
| 172 : this._(sink, new StringBuffer(), allowMalformed); | |
| 173 _Utf8ConversionSink._( | |
| 174 this._chunkedSink, StringBuffer stringBuffer, bool allowMalformed) | |
| 175 : _decoder = new _Utf8Decoder(stringBuffer, allowMalformed), | |
| 176 _buffer = stringBuffer; | |
| 177 void close() { | |
| 178 _decoder.close(); | |
| 179 if (_buffer.isNotEmpty) { | |
| 180 String accumulated = _buffer.toString(); | |
| 181 _buffer.clear(); | |
| 182 _chunkedSink.addSlice(accumulated, 0, accumulated.length, true); | |
| 183 } else { | |
| 184 _chunkedSink.close(); | |
| 185 } | |
| 186 } | |
| 187 void add(List<int> chunk) { | |
| 188 addSlice(chunk, 0, chunk.length, false); | |
| 189 } | |
| 190 void addSlice(List<int> chunk, int startIndex, int endIndex, bool isLast) { | |
| 191 _decoder.convert(chunk, startIndex, endIndex); | |
| 192 if (_buffer.isNotEmpty) { | |
| 193 String accumulated = _buffer.toString(); | |
| 194 _chunkedSink.addSlice(accumulated, 0, accumulated.length, isLast); | |
| 195 _buffer.clear(); | |
| 196 return; | |
| 197 } | |
| 198 if (isLast) close(); | |
| 199 } | |
| 200 } | 58 } |
| 59 } |
| 60 void _flush() { |
| 61 String accumulated = _buffer.toString(); |
| 62 _buffer.clear(); |
| 63 _chunkedSink.add(accumulated); |
| 64 } |
| 65 } |
| 66 abstract class StringConversionSinkBase extends StringConversionSinkMixin {} |
| 67 abstract class StringConversionSinkMixin implements StringConversionSink {void
addSlice(String str, int start, int end, bool isLast); |
| 68 void close(); |
| 69 void add(String str) => addSlice(str, 0, str.length, false); |
| 70 ByteConversionSink asUtf8Sink(bool allowMalformed) { |
| 71 return new _Utf8ConversionSink(this, allowMalformed); |
| 72 } |
| 73 ClosableStringSink asStringSink() { |
| 74 return new _StringConversionSinkAsStringSinkAdapter(this); |
| 75 } |
| 76 } |
| 77 class _StringSinkConversionSink extends StringConversionSinkBase {StringSink _s
tringSink; |
| 78 _StringSinkConversionSink(StringSink this._stringSink); |
| 79 void close() { |
| 80 } |
| 81 void addSlice(String str, int start, int end, bool isLast) { |
| 82 if (start != 0 || end != str.length) { |
| 83 for (int i = start; |
| 84 i < end; |
| 85 i++) { |
| 86 _stringSink.writeCharCode(str.codeUnitAt(i)); |
| 87 } |
| 88 } |
| 89 else { |
| 90 _stringSink.write(str); |
| 91 } |
| 92 if (isLast) close(); |
| 93 } |
| 94 void add(String str) => _stringSink.write(str); |
| 95 ByteConversionSink asUtf8Sink(bool allowMalformed) { |
| 96 return new _Utf8StringSinkAdapter(this, _stringSink, allowMalformed); |
| 97 } |
| 98 ClosableStringSink asStringSink() { |
| 99 return new ClosableStringSink.fromStringSink(_stringSink, this.close); |
| 100 } |
| 101 } |
| 102 class _StringCallbackSink extends _StringSinkConversionSink {final _ChunkedConv
ersionCallback<String> _callback; |
| 103 _StringCallbackSink(this._callback) : super(new StringBuffer()); |
| 104 void close() { |
| 105 StringBuffer buffer = DDC$RT.cast(_stringSink, StringSink, StringBuffer, "CastGe
neral", """line 233, column 27 of dart:convert/string_conversion.dart: """, _str
ingSink is StringBuffer, true); |
| 106 String accumulated = buffer.toString(); |
| 107 buffer.clear(); |
| 108 _callback(accumulated); |
| 109 } |
| 110 ByteConversionSink asUtf8Sink(bool allowMalformed) { |
| 111 return new _Utf8StringSinkAdapter(this, _stringSink, allowMalformed); |
| 112 } |
| 113 } |
| 114 class _StringAdapterSink extends StringConversionSinkBase {final Sink<String> _
sink; |
| 115 _StringAdapterSink(this._sink); |
| 116 void add(String str) => _sink.add(str); |
| 117 void addSlice(String str, int start, int end, bool isLast) { |
| 118 if (start == 0 && end == str.length) { |
| 119 add(str); |
| 120 } |
| 121 else { |
| 122 add(str.substring(start, end)); |
| 123 } |
| 124 if (isLast) close(); |
| 125 } |
| 126 void close() => _sink.close(); |
| 127 } |
| 128 class _Utf8StringSinkAdapter extends ByteConversionSink {final _Utf8Decoder _de
coder; |
| 129 final Sink _sink; |
| 130 _Utf8StringSinkAdapter(this._sink, StringSink stringSink, bool allowMalformed)
: _decoder = new _Utf8Decoder(stringSink, allowMalformed); |
| 131 void close() { |
| 132 _decoder.close(); |
| 133 if (_sink != null) _sink.close(); |
| 134 } |
| 135 void add(List<int> chunk) { |
| 136 addSlice(chunk, 0, chunk.length, false); |
| 137 } |
| 138 void addSlice(List<int> codeUnits, int startIndex, int endIndex, bool isLast) { |
| 139 _decoder.convert(codeUnits, startIndex, endIndex); |
| 140 if (isLast) close(); |
| 141 } |
| 142 } |
| 143 class _Utf8ConversionSink extends ByteConversionSink {final _Utf8Decoder _decod
er; |
| 144 final StringConversionSink _chunkedSink; |
| 145 final StringBuffer _buffer; |
| 146 _Utf8ConversionSink(StringConversionSink sink, bool allowMalformed) : this._(si
nk, new StringBuffer(), allowMalformed); |
| 147 _Utf8ConversionSink._(this._chunkedSink, StringBuffer stringBuffer, bool allowM
alformed) : _decoder = new _Utf8Decoder(stringBuffer, allowMalformed), _buffer =
stringBuffer; |
| 148 void close() { |
| 149 _decoder.close(); |
| 150 if (_buffer.isNotEmpty) { |
| 151 String accumulated = _buffer.toString(); |
| 152 _buffer.clear(); |
| 153 _chunkedSink.addSlice(accumulated, 0, accumulated.length, true); |
| 154 } |
| 155 else { |
| 156 _chunkedSink.close(); |
| 157 } |
| 158 } |
| 159 void add(List<int> chunk) { |
| 160 addSlice(chunk, 0, chunk.length, false); |
| 161 } |
| 162 void addSlice(List<int> chunk, int startIndex, int endIndex, bool isLast) { |
| 163 _decoder.convert(chunk, startIndex, endIndex); |
| 164 if (_buffer.isNotEmpty) { |
| 165 String accumulated = _buffer.toString(); |
| 166 _chunkedSink.addSlice(accumulated, 0, accumulated.length, isLast); |
| 167 _buffer.clear(); |
| 168 return;} |
| 169 if (isLast) close(); |
| 170 } |
| 171 } |
| OLD | NEW |