OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, 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 import 'dart:convert'; | |
6 | |
7 /// A sink that provides synchronous access to the concatenated strings passed | |
Lasse Reichstein Nielsen
2016/04/22 09:15:14
Again, no need for "synchronous".
nweiz
2016/04/22 21:19:56
Done.
| |
8 /// to it. | |
9 class StringAccumulatorSink extends StringConversionSinkBase { | |
10 /// The string accumulated so far. | |
11 String get string => _buffer.toString(); | |
12 final _buffer = new StringBuffer(); | |
13 | |
14 /// Whether [close] has been called. | |
15 bool get isClosed => _isClosed; | |
16 var _isClosed = false; | |
17 | |
18 void add(String chunk) { | |
19 if (_isClosed) { | |
20 throw new StateError("Can't add to a closed sink."); | |
21 } | |
22 | |
23 _buffer.write(chunk); | |
24 } | |
25 | |
26 void addSlice(String chunk, int start, int end, bool isLast) { | |
27 if (_isClosed) { | |
28 throw new StateError("Can't add to a closed sink."); | |
29 } | |
30 | |
31 _buffer.write(chunk.substring(start, end)); | |
32 if (isLast) _isClosed = true; | |
33 } | |
34 | |
35 void close() { | |
36 _isClosed = true; | |
37 } | |
38 } | |
OLD | NEW |