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 /** | 5 /** |
6 * Converters for JSON and UTF-8, as well as support for creating additional | 6 * |
7 * converters. | 7 * Encoders and decoders for converting between different data representations, |
| 8 * including JSON and UTF-8. |
| 9 * |
| 10 * In addition to converters for common data representations, this library |
| 11 * provides support for implementing converters in a way which makes them easy t
o |
| 12 * chain and to use with streams. |
| 13 * |
| 14 * The `dart:convert` library works in both web apps and command-line apps. |
| 15 * To use it: |
| 16 * |
| 17 * import 'dart:convert'; |
| 18 * |
| 19 * Two commonly used converters are the top-level instances of |
| 20 * [JsonCodec] and [Utf8Codec], named JSON and UTF8, respectively. |
| 21 * |
| 22 * JSON is a simple text format for representing |
| 23 * structured objects and collections. |
| 24 * The JSON encoder/decoder transforms between strings and |
| 25 * object structures, such as lists and maps, using the JSON format. |
| 26 * |
| 27 * UTF-8 is a common variable-width encoding that can represent |
| 28 * every character in the Unicode character set. |
| 29 * The UTF-8 encoder/decoder transforms between Strings and bytes. |
| 30 * |
| 31 * Converters are often used with streams |
| 32 * to transform the data that comes through the stream |
| 33 * as it becomes available. |
| 34 * The following code uses two converters. |
| 35 * The first is a UTF-8 decoder, which converts the data from bytes to UTF-8 |
| 36 * as it's read from a file, |
| 37 * The second is an instance of [LineSplitter], |
| 38 * which splits the data on newline boundaries. |
| 39 * |
| 40 * int lineNumber = 1; |
| 41 * Stream<List<int>> stream = new File('quotes.txt').openRead(); |
| 42 * |
| 43 * stream.transform(UTF8.decoder) |
| 44 * .transform(const LineSplitter()) |
| 45 * .listen((line) { |
| 46 * if (showLineNumbers) { |
| 47 * stdout.write('${lineNumber++} '); |
| 48 * } |
| 49 * stdout.writeln(line); |
| 50 * }); |
| 51 * |
| 52 * See the documentation for the [Codec] and [Converter] classes |
| 53 * for information about creating your own converters. |
8 */ | 54 */ |
9 library dart.convert; | 55 library dart.convert; |
10 | 56 |
11 import 'dart:async'; | 57 import 'dart:async'; |
12 import "dart:collection" show HashSet; | 58 import "dart:collection" show HashSet; |
13 | 59 |
14 part 'ascii.dart'; | 60 part 'ascii.dart'; |
15 part 'byte_conversion.dart'; | 61 part 'byte_conversion.dart'; |
16 part 'chunked_conversion.dart'; | 62 part 'chunked_conversion.dart'; |
17 part 'codec.dart'; | 63 part 'codec.dart'; |
18 part 'converter.dart'; | 64 part 'converter.dart'; |
19 part 'encoding.dart'; | 65 part 'encoding.dart'; |
20 part 'html_escape.dart'; | 66 part 'html_escape.dart'; |
21 part 'json.dart'; | 67 part 'json.dart'; |
22 part 'latin1.dart'; | 68 part 'latin1.dart'; |
23 part 'line_splitter.dart'; | 69 part 'line_splitter.dart'; |
24 part 'string_conversion.dart'; | 70 part 'string_conversion.dart'; |
25 part 'utf.dart'; | 71 part 'utf.dart'; |
OLD | NEW |