OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 patch class _WindowsCodePageDecoder { | 5 patch class _WindowsCodePageDecoder { |
6 /* patch */ static String _decodeBytes(List<int> bytes) | 6 /* patch */ static String _decodeBytes(List<int> bytes) |
7 native "SystemEncodingToString"; | 7 native "SystemEncodingToString"; |
8 } | 8 } |
9 | 9 |
10 | 10 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 var sb = new StringBuffer(); | 111 var sb = new StringBuffer(); |
112 var nextPos = 0; | 112 var nextPos = 0; |
113 var quotePos = argument.indexOf('"', nextPos); | 113 var quotePos = argument.indexOf('"', nextPos); |
114 while (quotePos != -1) { | 114 while (quotePos != -1) { |
115 var numBackslash = 0; | 115 var numBackslash = 0; |
116 var pos = quotePos - 1; | 116 var pos = quotePos - 1; |
117 while (pos >= 0 && argument.codeUnitAt(pos) == backslash) { | 117 while (pos >= 0 && argument.codeUnitAt(pos) == backslash) { |
118 numBackslash++; | 118 numBackslash++; |
119 pos--; | 119 pos--; |
120 } | 120 } |
121 sb.add(argument.substring(nextPos, quotePos - numBackslash)); | 121 sb.write(argument.substring(nextPos, quotePos - numBackslash)); |
122 for (var i = 0; i < numBackslash; i++) { | 122 for (var i = 0; i < numBackslash; i++) { |
123 sb.add(r'\\'); | 123 sb.write(r'\\'); |
124 } | 124 } |
125 sb.add(r'\"'); | 125 sb.write(r'\"'); |
126 nextPos = quotePos + 1; | 126 nextPos = quotePos + 1; |
127 quotePos = argument.indexOf('"', nextPos); | 127 quotePos = argument.indexOf('"', nextPos); |
128 } | 128 } |
129 sb.add(argument.substring(nextPos, argument.length)); | 129 sb.write(argument.substring(nextPos, argument.length)); |
130 result = sb.toString(); | 130 result = sb.toString(); |
131 | 131 |
132 // Add '"' at the beginning and end and replace all '\' at | 132 // Add '"' at the beginning and end and replace all '\' at |
133 // the end with two '\'. | 133 // the end with two '\'. |
134 sb = new StringBuffer('"'); | 134 sb = new StringBuffer('"'); |
135 sb.add(result); | 135 sb.write(result); |
136 nextPos = argument.length - 1; | 136 nextPos = argument.length - 1; |
137 while (argument.codeUnitAt(nextPos) == backslash) { | 137 while (argument.codeUnitAt(nextPos) == backslash) { |
138 sb.add('\\'); | 138 sb.write('\\'); |
139 nextPos--; | 139 nextPos--; |
140 } | 140 } |
141 sb.add('"'); | 141 sb.write('"'); |
142 result = sb.toString(); | 142 result = sb.toString(); |
143 } | 143 } |
144 | 144 |
145 return result; | 145 return result; |
146 } | 146 } |
147 | 147 |
148 int _intFromBytes(List<int> bytes, int offset) { | 148 int _intFromBytes(List<int> bytes, int offset) { |
149 return (bytes[offset] + | 149 return (bytes[offset] + |
150 (bytes[offset + 1] << 8) + | 150 (bytes[offset + 1] << 8) + |
151 (bytes[offset + 2] << 16) + | 151 (bytes[offset + 2] << 16) + |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 return Process.start(path, arguments, options).then((Process p) { | 295 return Process.start(path, arguments, options).then((Process p) { |
296 // Make sure the process stdin is closed. | 296 // Make sure the process stdin is closed. |
297 p.stdin.close(); | 297 p.stdin.close(); |
298 | 298 |
299 // Setup stdout handling. | 299 // Setup stdout handling. |
300 Future<StringBuffer> stdout = p.stdout | 300 Future<StringBuffer> stdout = p.stdout |
301 .transform(new StringDecoder(stdoutEncoding)) | 301 .transform(new StringDecoder(stdoutEncoding)) |
302 .reduce( | 302 .reduce( |
303 new StringBuffer(), | 303 new StringBuffer(), |
304 (buf, data) { | 304 (buf, data) { |
305 buf.add(data); | 305 buf.write(data); |
306 return buf; | 306 return buf; |
307 }); | 307 }); |
308 | 308 |
309 Future<StringBuffer> stderr = p.stderr | 309 Future<StringBuffer> stderr = p.stderr |
310 .transform(new StringDecoder(stderrEncoding)) | 310 .transform(new StringDecoder(stderrEncoding)) |
311 .reduce( | 311 .reduce( |
312 new StringBuffer(), | 312 new StringBuffer(), |
313 (buf, data) { | 313 (buf, data) { |
314 buf.add(data); | 314 buf.write(data); |
315 return buf; | 315 return buf; |
316 }); | 316 }); |
317 | 317 |
318 return Future.wait([p.exitCode, stdout, stderr]).then((result) { | 318 return Future.wait([p.exitCode, stdout, stderr]).then((result) { |
319 return new _ProcessResult(result[0], | 319 return new _ProcessResult(result[0], |
320 result[1].toString(), | 320 result[1].toString(), |
321 result[2].toString()); | 321 result[2].toString()); |
322 }); | 322 }); |
323 }); | 323 }); |
324 } | 324 } |
325 | 325 |
326 | 326 |
327 class _ProcessResult implements ProcessResult { | 327 class _ProcessResult implements ProcessResult { |
328 const _ProcessResult(int this.exitCode, | 328 const _ProcessResult(int this.exitCode, |
329 String this.stdout, | 329 String this.stdout, |
330 String this.stderr); | 330 String this.stderr); |
331 | 331 |
332 final int exitCode; | 332 final int exitCode; |
333 final String stdout; | 333 final String stdout; |
334 final String stderr; | 334 final String stderr; |
335 } | 335 } |
OLD | NEW |