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