Skip to content

Commit 47e4b4f

Browse files
parloughcommit-bot@chromium.org
authored andcommitted
[dart2js] Migrate command line util
Also makes the following minor improvements: - Standardizes the file on single quotes to make the file more uniform and match elsewhere. - Switches the ESCAPE_MAPPING declaration to const - Corrects method spelling in doc comment Change-Id: Ic271cd28d287f321b9b3719250b053df548ba194 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202061 Reviewed-by: Stephen Adams <[email protected]> Commit-Queue: Kevin Moore <[email protected]>
1 parent 51b7809 commit 47e4b4f

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

pkg/compiler/lib/src/util/command_line.dart

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,36 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// @dart=2.12
6+
57
library dart2js.util.command_line;
68

79
/// The accepted escapes in the input of the --batch processor.
810
///
911
/// Contrary to Dart strings it does not contain hex escapes (\u or \x).
10-
Map<String, String> ESCAPE_MAPPING = const {
11-
"n": "\n",
12-
"r": "\r",
13-
"t": "\t",
14-
"b": "\b",
15-
"f": "\f",
16-
"v": "\v",
17-
"\\": "\\",
12+
const Map<String, String> ESCAPE_MAPPING = {
13+
'n': '\n',
14+
'r': '\r',
15+
't': '\t',
16+
'b': '\b',
17+
'f': '\f',
18+
'v': '\v',
19+
'\\': '\\',
1820
};
1921

20-
/// Splits the line similar to how a shell would split arguments. If [windows]
22+
/// Splits the [line] similar to how a shell would split arguments. If [windows]
2123
/// is `true` escapes will be handled like on the Windows command-line.
2224
///
2325
/// Example:
2426
///
25-
/// splitline("""--args "ab"c 'with " \'spaces'""").forEach(print);
27+
/// splitLine("""--args "ab"c 'with " \'spaces'""").forEach(print);
2628
/// // --args
2729
/// // abc
2830
/// // with " 'spaces
29-
List<String> splitLine(String line, {bool windows: false}) {
31+
List<String> splitLine(String line, {bool windows = false}) {
3032
List<String> result = <String>[];
3133
bool inQuotes = false;
32-
String openingQuote;
34+
String? openingQuote;
3335
StringBuffer buffer = new StringBuffer();
3436
for (int i = 0; i < line.length; i++) {
3537
String c = line[i];
@@ -44,7 +46,7 @@ List<String> splitLine(String line, {bool windows: false}) {
4446
}
4547
if (c == '\\') {
4648
if (i == line.length - 1) {
47-
throw new FormatException("Unfinished escape: $line");
49+
throw new FormatException('Unfinished escape: $line');
4850
}
4951
if (windows) {
5052
String next = line[i + 1];
@@ -57,20 +59,21 @@ List<String> splitLine(String line, {bool windows: false}) {
5759
i++;
5860

5961
c = line[i];
60-
String mapped = ESCAPE_MAPPING[c];
61-
if (mapped == null) mapped = c;
62+
String mapped = ESCAPE_MAPPING[c] ?? c;
6263
buffer.write(mapped);
6364
continue;
6465
}
6566
}
66-
if (!inQuotes && c == " ") {
67-
if (buffer.isNotEmpty) result.add(buffer.toString());
68-
buffer.clear();
67+
if (!inQuotes && c == ' ') {
68+
if (buffer.isNotEmpty) {
69+
result.add(buffer.toString());
70+
buffer.clear();
71+
}
6972
continue;
7073
}
7174
buffer.write(c);
7275
}
73-
if (inQuotes) throw new FormatException("Unclosed quotes: $line");
76+
if (inQuotes) throw new FormatException('Unclosed quotes: $line');
7477
if (buffer.isNotEmpty) result.add(buffer.toString());
7578
return result;
7679
}

0 commit comments

Comments
 (0)