OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 part of html_common; | 5 part of html_common; |
6 | 6 |
7 class Lists { | 7 class Lists { |
8 | 8 |
9 /** | 9 /** |
10 * Returns the index in the array [a] of the given [element], starting | 10 * Returns the index in the array [a] of the given [element], starting |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 static List getRange(List a, int start, int length, List accumulator) { | 59 static List getRange(List a, int start, int length, List accumulator) { |
60 if (length < 0) throw new ArgumentError('length'); | 60 if (length < 0) throw new ArgumentError('length'); |
61 if (start < 0) throw new RangeError.value(start); | 61 if (start < 0) throw new RangeError.value(start); |
62 int end = start + length; | 62 int end = start + length; |
63 if (end > a.length) throw new RangeError.value(end); | 63 if (end > a.length) throw new RangeError.value(end); |
64 for (int i = start; i < end; i++) { | 64 for (int i = start; i < end; i++) { |
65 accumulator.add(a[i]); | 65 accumulator.add(a[i]); |
66 } | 66 } |
67 return accumulator; | 67 return accumulator; |
68 } | 68 } |
| 69 |
| 70 static String join(List<Object> list, [String separator]) { |
| 71 if (list.isEmpty) return ""; |
| 72 if (list.length == 1) return "${list[0]}"; |
| 73 StringBuffer buffer = new StringBuffer(); |
| 74 if (separator == null || separator == "") { |
| 75 for (int i = 0; i < list.length; i++) { |
| 76 buffer.add("${list[i]}"); |
| 77 } |
| 78 } else { |
| 79 buffer.add("${list[0]}"); |
| 80 for (int i = 1; i < list.length; i++) { |
| 81 buffer.add(separator); |
| 82 buffer.add("${list[i]}"); |
| 83 } |
| 84 } |
| 85 return buffer.toString(); |
| 86 } |
69 } | 87 } |
OLD | NEW |