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 // Utility script to echo strings in various formats to stdout or | 5 // Utility script to echo strings in various formats to stdout or |
6 // stderr. | 6 // stderr. |
7 | 7 |
8 import "dart:convert"; | 8 import "dart:convert"; |
9 import "dart:io"; | 9 import "dart:io"; |
10 | 10 |
11 writeData(data, encoding, stream) { | 11 writeData(data, encoding, stream) { |
12 if (stream == "stdout") { | 12 if (stream == "stdout") { |
13 if (encoding == null) { | 13 if (encoding == null) { |
14 stdout.add(data); | 14 stdout.add(data); |
15 } else { | 15 } else { |
16 stdout.encoding = encoding; | 16 stdout.encoding = encoding; |
17 stdout.write(data); | 17 stdout.write(data); |
18 } | 18 } |
19 } else if (stream == "stderr") { | 19 } else if (stream == "stderr") { |
20 if (encoding == null) { | 20 if (encoding == null) { |
21 stderr.add(data); | 21 stderr.add(data); |
22 } else { | 22 } else { |
23 stderr.encoding = encoding; | 23 stderr.encoding = encoding; |
24 stderr.write(data); | 24 stderr.write(data); |
25 } | 25 } |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 main() { | 29 main(List<String> arguments) { |
30 var asciiString = 'abc'; | 30 var asciiString = 'abc'; |
31 var latin1String = 'æøå'; | 31 var latin1String = 'æøå'; |
32 var utf8String = new String.fromCharCodes([955]); | 32 var utf8String = new String.fromCharCodes([955]); |
33 var binary = [0, 1, 2]; | 33 var binary = [0, 1, 2]; |
34 var options = new Options(); | 34 if (arguments.length > 1) { |
35 if (options.arguments.length > 1) { | 35 var stream = arguments[1]; |
36 var stream = options.arguments[1]; | 36 if (arguments[0] == "ascii") { |
37 if (options.arguments[0] == "ascii") { | |
38 writeData(asciiString, ASCII, stream); | 37 writeData(asciiString, ASCII, stream); |
39 } else if (options.arguments[0] == "latin1") { | 38 } else if (arguments[0] == "latin1") { |
40 writeData(latin1String, LATIN1, stream); | 39 writeData(latin1String, LATIN1, stream); |
41 } else if (options.arguments[0] == "utf8") { | 40 } else if (arguments[0] == "utf8") { |
42 writeData(utf8String, UTF8, stream); | 41 writeData(utf8String, UTF8, stream); |
43 } else if (options.arguments[0] == "binary") { | 42 } else if (arguments[0] == "binary") { |
44 writeData(binary, null, stream); | 43 writeData(binary, null, stream); |
45 } | 44 } |
46 } | 45 } |
47 } | 46 } |
OLD | NEW |