Files
sdk/tests/standalone/io/process_std_io_script2.dart
T
sgjesse@google.com b6096848b1 Make IOSink implement StringSink
Besides adding the StringSink methods I also added writeBytes and
deprecated both add and addString.

To handle the encoding of strings the IOSike has an encoding
property. This property is mutable in situation when it makes sense to
change encoding of what is written. The exception here is for HTTP
where the encoding is determined from the header and the encoding
cannot be changed.

R=ajohnsen@google.com, ager@google.com, nweiz@google.com

BUG=

Review URL: https://codereview.chromium.org//12504006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@19676 260f80e4-7a28-3924-810f-c04153c831b5
2013-03-08 10:06:28 +00:00

36 lines
1.1 KiB
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
// Utility script to echo strings in various formats to stdout or
// stderr.
import "dart:io";
writeData(data, encoding, stream) {
if (stream == "stdout") {
stdout.encoding = encoding;
stdout.write(data);
} else if (stream == "stderr") {
stderr.encoding = encoding;
stderr.write(data);
}
}
main() {
var asciiString = 'abc';
var latin1String = 'æøå';
var utf8String = new String.fromCharCodes([955]);
var options = new Options();
if (options.arguments.length > 1) {
var stream = options.arguments[1];
if (options.arguments[0] == "ascii") {
writeData(asciiString, Encoding.ASCII, stream);
} else if (options.arguments[0] == "latin1") {
writeData(latin1String, Encoding.ISO_8859_1, stream);
} else if (options.arguments[0] == "utf8") {
writeData(utf8String, Encoding.UTF_8, stream);
}
}
}