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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/util/command_line.dart

Issue 694353007: Move dart2js from sdk/lib/_internal/compiler to pkg/compiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library dart2js.util.command_line;
6
7 /// The accepted escapes in the input of the --batch processor.
8 ///
9 /// Contrary to Dart strings it does not contain hex escapes (\u or \x).
10 Map<String, String> ESCAPE_MAPPING =
11 const {
12 "n": "\n",
13 "r": "\r",
14 "t": "\t",
15 "b": "\b",
16 "f": "\f",
17 "v": "\v",
18 "\\": "\\",
19 };
20
21 /// Splits the line similar to how a shell would split arguments. If [windows]
22 /// is `true` escapes will be handled like on the Windows command-line.
23 ///
24 /// Example:
25 ///
26 /// splitline("""--args "ab"c 'with " \'spaces'""").forEach(print);
27 /// // --args
28 /// // abc
29 /// // with " 'spaces
30 List<String> splitLine(String line, {bool windows: false}) {
31 List<String> result = <String>[];
32 bool inQuotes = false;
33 String openingQuote;
34 StringBuffer buffer = new StringBuffer();
35 for (int i = 0; i < line.length; i++) {
36 String c = line[i];
37 if (inQuotes && c == openingQuote) {
38 inQuotes = false;
39 continue;
40 }
41 if (!inQuotes && (c == '"' || (c == "'" && !windows))) {
42 inQuotes = true;
43 openingQuote = c;
44 continue;
45 }
46 if (c == '\\') {
47 if (i == line.length - 1) {
48 throw new FormatException("Unfinished escape: $line");
49 }
50 if (windows) {
51 String next = line[i+1];
52 if (next == '"' || next == r'\') {
53 buffer.write(next);
54 i++;
55 continue;
56 }
57 } else {
58 i++;
59
60 c = line[i];
61 String mapped = ESCAPE_MAPPING[c];
62 if (mapped == null) mapped = c;
63 buffer.write(mapped);
64 continue;
65 }
66 }
67 if (!inQuotes && c == " ") {
68 if (buffer.isNotEmpty) result.add(buffer.toString());
69 buffer.clear();
70 continue;
71 }
72 buffer.write(c);
73 }
74 if (inQuotes) throw new FormatException("Unclosed quotes: $line");
75 if (buffer.isNotEmpty) result.add(buffer.toString());
76 return result;
77 }
78
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698