OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// The line used in the string representation of stack chains to represent | 5 /// The line used in the string representation of stack chains to represent |
6 /// the gap between traces. | 6 /// the gap between traces. |
7 const chainGap = '===== asynchronous gap ===========================\n'; | 7 const chainGap = '===== asynchronous gap ===========================\n'; |
8 | 8 |
9 /// Returns [string] with enough spaces added to the end to make it [length] | 9 /// Returns [string] with enough spaces added to the end to make it [length] |
10 /// characters long. | 10 /// characters long. |
11 String padRight(String string, int length) { | 11 String padRight(String string, int length) { |
12 if (string.length >= length) return string; | 12 if (string.length >= length) return string; |
13 | 13 |
14 var result = new StringBuffer(); | 14 var result = new StringBuffer(); |
15 result.write(string); | 15 result.write(string); |
16 for (var i = 0; i < length - string.length; i++) { | 16 for (var i = 0; i < length - string.length; i++) { |
17 result.write(' '); | 17 result.write(' '); |
18 } | 18 } |
19 | 19 |
20 return result.toString(); | 20 return result.toString(); |
21 } | 21 } |
22 | |
23 /// Flattens nested lists inside an iterable into a single list containing only | |
24 /// non-list elements. | |
25 List flatten(Iterable nested) { | |
26 var result = []; | |
27 helper(list) { | |
28 for (var element in list) { | |
29 if (element is List) { | |
30 helper(element); | |
31 } else { | |
32 result.add(element); | |
33 } | |
34 } | |
35 } | |
36 helper(nested); | |
37 return result; | |
38 } | |
OLD | NEW |