Tweak comments added by `write` function on packages_file.dart.
Now adds "# " in front, not just "#", and doesn't treat the empty
string after a final "\n" as an extra line.
R=sgjesse@google.com
Review URL: https://codereview.chromium.org//1167223004.
diff --git a/lib/packages_file.dart b/lib/packages_file.dart
index 2228cb3..a736ca0 100644
--- a/lib/packages_file.dart
+++ b/lib/packages_file.dart
@@ -74,7 +74,9 @@
/// Writes the mapping to a [StringSink].
///
/// If [comment] is provided, the output will contain this comment
-/// with `#` in front of each line.
+/// with `# ` in front of each line.
+/// Lines are defined as ending in line feed (`'\n'`). If the final
+/// line of the comment doesn't end in a line feed, one will be added.
///
/// If [baseUri] is provided, package locations will be made relative
/// to the base URI, if possible, before writing.
@@ -85,8 +87,10 @@
}
if (comment != null) {
- for (var commentLine in comment.split('\n')) {
- output.write('#');
+ var lines = comment.split('\n');
+ if (lines.last.isEmpty) lines.removeLast();
+ for (var commentLine in lines) {
+ output.write('# ');
output.writeln(commentLine);
}
} else {
@@ -172,4 +176,4 @@
}
// TODO: inline to uri.normalizePath() when we move to 1.11
-Uri _normalizePath(Uri uri) => new Uri().resolveUri(uri);
+Uri _normalizePath(Uri uri) => new Uri().resolveUri(uri);