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

Side by Side Diff: sdk/lib/collection/collections.dart

Issue 13008021: Add optional writeAll separator argument. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 9 months 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
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/code_buffer.dart ('k') | sdk/lib/core/iterable.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 part of dart.collection; 5 part of dart.collection;
6 6
7 /** 7 /**
8 * This class provides default implementations for Iterables (including Lists). 8 * This class provides default implementations for Iterables (including Lists).
9 * 9 *
10 * Once Dart receives Mixins it will be replaced with mixin classes. 10 * Once Dart receives Mixins it will be replaced with mixin classes.
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 if (index is! int || index < 0) throw new RangeError.value(index); 267 if (index is! int || index < 0) throw new RangeError.value(index);
268 int remaining = index; 268 int remaining = index;
269 for (dynamic element in iterable) { 269 for (dynamic element in iterable) {
270 if (remaining == 0) return element; 270 if (remaining == 0) return element;
271 remaining--; 271 remaining--;
272 } 272 }
273 throw new RangeError.value(index); 273 throw new RangeError.value(index);
274 } 274 }
275 275
276 static String join(Iterable iterable, [String separator]) { 276 static String join(Iterable iterable, [String separator]) {
277 Iterator iterator = iterable.iterator;
278 if (!iterator.moveNext()) return "";
279 StringBuffer buffer = new StringBuffer(); 277 StringBuffer buffer = new StringBuffer();
280 if (separator == null || separator == "") { 278 buffer.writeAll(iterable, separator == null ? "" : separator);
281 do {
282 buffer.write("${iterator.current}");
283 } while (iterator.moveNext());
284 } else {
285 buffer.write("${iterator.current}");
286 while (iterator.moveNext()) {
287 buffer.write(separator);
288 buffer.write("${iterator.current}");
289 }
290 }
291 return buffer.toString(); 279 return buffer.toString();
292 } 280 }
293 281
294 static String joinList(List list, [String separator]) { 282 static String joinList(List list, [String separator]) {
295 if (list.isEmpty) return ""; 283 if (list.isEmpty) return "";
296 if (list.length == 1) return "${list[0]}"; 284 if (list.length == 1) return "${list[0]}";
297 StringBuffer buffer = new StringBuffer(); 285 StringBuffer buffer = new StringBuffer();
298 if (separator == null || separator == "") { 286 if (separator == null || separator == "") {
299 for (int i = 0; i < list.length; i++) { 287 for (int i = 0; i < list.length; i++) {
300 buffer.write("${list[i]}"); 288 buffer.write("${list[i]}");
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 * The source of the elements may be a [List] or any [Iterable] with 422 * The source of the elements may be a [List] or any [Iterable] with
435 * efficient [Iterable.length] and [Iterable.elementAt]. 423 * efficient [Iterable.length] and [Iterable.elementAt].
436 */ 424 */
437 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { 425 class UnmodifiableListView<E> extends UnmodifiableListBase<E> {
438 Iterable<E> _source; 426 Iterable<E> _source;
439 /** Create an unmodifiable list backed by [source]. */ 427 /** Create an unmodifiable list backed by [source]. */
440 UnmodifiableListView(Iterable<E> source) : _source = source; 428 UnmodifiableListView(Iterable<E> source) : _source = source;
441 int get length => _source.length; 429 int get length => _source.length;
442 E operator[](int index) => _source.elementAt(index); 430 E operator[](int index) => _source.elementAt(index);
443 } 431 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/code_buffer.dart ('k') | sdk/lib/core/iterable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698