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 * An instance of the default implementation of the [AsciiCodec]. | 8 * An instance of the default implementation of the [AsciiCodec]. |
9 * | 9 * |
10 * This instance provides a convenient access to the most common ASCII | 10 * This instance provides a convenient access to the most common ASCII |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 Sink _sink; | 283 Sink _sink; |
284 _SimpleAsciiDecoderSink(this._sink); | 284 _SimpleAsciiDecoderSink(this._sink); |
285 | 285 |
286 void close() { | 286 void close() { |
287 _sink.close(); | 287 _sink.close(); |
288 } | 288 } |
289 | 289 |
290 void add(List<int> source) { | 290 void add(List<int> source) { |
291 for (int i = 0; i < source.length; i++) { | 291 for (int i = 0; i < source.length; i++) { |
292 if ((source[i] & ~_ASCII_MASK) != 0) { | 292 if ((source[i] & ~_ASCII_MASK) != 0) { |
293 throw new FormatException("Source contains non-ASCII bytes."); | 293 throw new FormatException("Source contains non-ASCII bytes.", |
| 294 source, i); |
294 } | 295 } |
295 } | 296 } |
296 _sink.add(new String.fromCharCodes(source)); | 297 _sink.add(new String.fromCharCodes(source)); |
297 } | 298 } |
298 | 299 |
299 void addSlice(List<int> source, int start, int end, bool isLast) { | 300 void addSlice(List<int> source, int start, int end, bool isLast) { |
300 final int length = source.length; | 301 final int length = source.length; |
301 RangeError.checkValidRange(start, end, length); | 302 RangeError.checkValidRange(start, end, length); |
302 if (start < end) { | 303 if (start < end) { |
303 if (start != 0 || end != length) { | 304 if (start != 0 || end != length) { |
304 source = source.sublist(start, end); | 305 source = source.sublist(start, end); |
305 } | 306 } |
306 add(source); | 307 add(source); |
307 } | 308 } |
308 if (isLast) close(); | 309 if (isLast) close(); |
309 } | 310 } |
310 } | 311 } |
OLD | NEW |