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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 for (int i = startIndex; i >= 0; i--) { | 44 for (int i = startIndex; i >= 0; i--) { |
45 if (a[i] == element) { | 45 if (a[i] == element) { |
46 return i; | 46 return i; |
47 } | 47 } |
48 } | 48 } |
49 return -1; | 49 return -1; |
50 } | 50 } |
51 | 51 |
52 /** | 52 /** |
53 * Returns a sub list copy of this list, from [start] to | 53 * Returns a sub list copy of this list, from [start] to |
54 * [:start + length:]. | 54 * [end] ([end] not inclusive). |
55 * Returns an empty list if [length] is 0. | 55 * Returns an empty list if [length] is 0. |
56 * Throws an [ArgumentError] if [length] is negative. | 56 * It is an error if indices are not valid for the list, or |
57 * Throws a [RangeError] if [start] or [:start + length:] are out of range. | 57 * if [end] is before [start]. |
58 */ | 58 */ |
59 static List getRange(List a, int start, int length, List accumulator) { | 59 static List getRange(List a, int start, int end, List accumulator) { |
60 if (length < 0) throw new ArgumentError('length'); | |
61 if (start < 0) throw new RangeError.value(start); | 60 if (start < 0) throw new RangeError.value(start); |
62 int end = start + length; | 61 if (end < start) throw new RangeError.value(end); |
63 if (end > a.length) throw new RangeError.value(end); | 62 if (end > a.length) throw new RangeError.value(end); |
64 for (int i = start; i < end; i++) { | 63 for (int i = start; i < end; i++) { |
65 accumulator.add(a[i]); | 64 accumulator.add(a[i]); |
66 } | 65 } |
67 return accumulator; | 66 return accumulator; |
68 } | 67 } |
69 } | 68 } |
OLD | NEW |