Work around issue 9360.

BUG=8687

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20406 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
nweiz@google.com 2013-03-22 18:49:14 +00:00
parent 8783e780e9
commit 5f052a9796
3 changed files with 13 additions and 8 deletions

View file

@ -20,8 +20,6 @@ import 'utils.dart';
export '../../pkg/http/lib/http.dart' show ByteStream;
final NEWLINE_PATTERN = new RegExp("\r\n?|\n\r?");
/// Returns whether or not [entry] is nested somewhere within [dir]. This just
/// performs a path comparison; it doesn't look at the actual filesystem.
bool isBeneath(String entry, String dir) {
@ -409,7 +407,7 @@ Future<PubProcessResult> runProcess(String executable, List<String> args,
.then((result) {
// TODO(rnystrom): Remove this and change to returning one string.
List<String> toLines(String output) {
var lines = output.split(NEWLINE_PATTERN);
var lines = splitLines(output);
if (!lines.isEmpty && lines.last == "") lines.removeLast();
return lines;
}

View file

@ -6,7 +6,9 @@
library log;
import 'dart:async';
import 'io.dart';
import 'utils.dart';
typedef LogFn(Entry entry);
final Map<Level, LogFn> _loggers = new Map<Level, LogFn>();
@ -73,7 +75,7 @@ void fine(message) => write(Level.FINE, message);
void write(Level level, message) {
if (_loggers.isEmpty) showNormal();
var lines = message.toString().split(NEWLINE_PATTERN);
var lines = splitLines(message.toString());
var entry = new Entry(level, lines);
var logFn = _loggers[level];

View file

@ -218,9 +218,14 @@ Pair<Stream, Stream> tee(Stream stream) {
return new Pair<Stream, Stream>(controller1.stream, controller2.stream);
}
/// A regular expression matching a line termination character or character
/// sequence.
final RegExp _lineRegexp = new RegExp(r"\r\n|\r|\n");
/// A regular expression matching a trailing CR character.
final _trailingCR = new RegExp(r"\r$");
// TODO(nweiz): Use `text.split(new RegExp("\r\n?|\n\r?"))` when issue 9360 is
// fixed.
/// Splits [text] on its line breaks in a Windows-line-break-friendly way.
List<String> splitLines(String text) =>
text.split("\n").map((line) => line.replaceFirst(_trailingCR, "")).toList();
/// Converts a stream of arbitrarily chunked strings into a line-by-line stream.
/// The lines don't include line termination characters. A single trailing
@ -229,7 +234,7 @@ Stream<String> streamToLines(Stream<String> stream) {
var buffer = new StringBuffer();
return stream.transform(new StreamTransformer(
handleData: (chunk, sink) {
var lines = chunk.split(_lineRegexp);
var lines = splitLines(chunk);
var leftover = lines.removeLast();
for (var line in lines) {
if (!buffer.isEmpty) {