Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1036)

Unified Diff: utils/pub/utils.dart

Issue 12995008: Work around issue 9360. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Be compatible with Windows. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/log.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/utils.dart
diff --git a/utils/pub/utils.dart b/utils/pub/utils.dart
index e713e860b4f2a880cf49236ff5ee385abc101b5a..d354e683891365d3261fc782c506c2c0e70bb6c3 100644
--- a/utils/pub/utils.dart
+++ b/utils/pub/utils.dart
@@ -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) {
« no previous file with comments | « utils/pub/log.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698