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 #library("dart:coreimpl"); | 5 #library("dart:coreimpl"); |
6 | 6 |
7 #source("../../corelib/src/implementation/dual_pivot_quicksort.dart"); | 7 #source("../../corelib/src/implementation/dual_pivot_quicksort.dart"); |
8 #source("../../corelib/src/implementation/duration_implementation.dart"); | 8 #source("../../corelib/src/implementation/duration_implementation.dart"); |
9 #source("../../corelib/src/implementation/exceptions.dart"); | 9 #source("../../corelib/src/implementation/exceptions.dart"); |
10 #source("../../corelib/src/implementation/collections.dart"); | 10 #source("../../corelib/src/implementation/collections.dart"); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 void sort(int compare(E a, E b)) native; | 59 void sort(int compare(E a, E b)) native; |
60 void copyFrom(List<Object> src, int srcStart, int dstStart, int count) native; | 60 void copyFrom(List<Object> src, int srcStart, int dstStart, int count) native; |
61 int indexOf(E element, [int start]) native; | 61 int indexOf(E element, [int start]) native; |
62 int lastIndexOf(E element, [int start]) native; | 62 int lastIndexOf(E element, [int start]) native; |
63 void clear() { length = 0; } | 63 void clear() { length = 0; } |
64 | 64 |
65 E removeLast() native "return this.pop();"; | 65 E removeLast() native "return this.pop();"; |
66 | 66 |
67 E last() => this[this.length-1]; | 67 E last() => this[this.length-1]; |
68 | 68 |
69 List<E> getRange(int start, int length) native """ | 69 List<E> getRange(int start, int rangeLength) native """ |
70 if (length == 0) return []; | 70 if (rangeLength == 0) return []; |
71 if (length < 0) throw new IllegalArgumentException('length'); | 71 if (rangeLength < 0) throw new IllegalArgumentException('length'); |
72 if (start < 0 || start + length > this.length) | 72 if (start < 0 || start + rangeLength > this.length) |
73 throw new IndexOutOfRangeException(start); | 73 throw new IndexOutOfRangeException(start); |
74 return this.slice(start, start + length); | 74 return this.slice(start, start + rangeLength); |
75 """ { throw new IllegalArgumentException(''); | 75 """ { throw new IllegalArgumentException(''); |
76 throw new IndexOutOfRangeException(0); } | 76 throw new IndexOutOfRangeException(0); } |
77 | 77 |
78 void setRange(int start, int length, List<E> from, [int startFrom = 0]) { | 78 void setRange(int start, int rangeLength, List<E> from, [int startFrom = 0]) { |
79 // length of 0 prevails and should not throw exceptions. | 79 // length of 0 prevails and should not throw exceptions. |
80 if (length == 0) return; | 80 if (rangeLength == 0) return; |
81 if (length < 0) throw new IllegalArgumentException('length is negative'); | 81 if (rangeLength < 0) { |
| 82 throw new IllegalArgumentException('length is negative'); |
| 83 } |
82 | 84 |
83 if (start < 0) throw new IndexOutOfRangeException(start); | 85 if (start < 0) throw new IndexOutOfRangeException(start); |
84 | 86 |
85 int end = start + length; | 87 int end = start + rangeLength; |
86 if (end > this.length) throw new IndexOutOfRangeException(end); | 88 if (end > this.length) throw new IndexOutOfRangeException(end); |
87 | 89 |
88 if (startFrom < 0) throw new IndexOutOfRangeException(startFrom); | 90 if (startFrom < 0) throw new IndexOutOfRangeException(startFrom); |
89 | 91 |
90 int endFrom = startFrom + length; | 92 int endFrom = startFrom + rangeLength; |
91 if (endFrom > from.length) throw new IndexOutOfRangeException(endFrom); | 93 if (endFrom > from.length) throw new IndexOutOfRangeException(endFrom); |
92 | 94 |
93 for (var i = 0; i < length; ++i) | 95 for (var i = 0; i < rangeLength; ++i) |
94 this[start + i] = from[startFrom + i]; | 96 this[start + i] = from[startFrom + i]; |
95 } | 97 } |
96 | 98 |
97 void removeRange(int start, int length) native """ | 99 void removeRange(int start, int rangeLength) native """ |
98 if (length == 0) return; | 100 if (rangeLength == 0) return; |
99 if (length < 0) throw new IllegalArgumentException('length'); | 101 if (rangeLength < 0) throw new IllegalArgumentException('length'); |
100 if (start < 0 || start + length > this.length) | 102 if (start < 0 || start + rangeLength > this.length) |
101 throw new IndexOutOfRangeException(start); | 103 throw new IndexOutOfRangeException(start); |
102 this.splice(start, length); | 104 this.splice(start, rangeLength); |
103 """ { throw new IllegalArgumentException(''); | 105 """ { throw new IllegalArgumentException(''); |
104 throw new IndexOutOfRangeException(0); } | 106 throw new IndexOutOfRangeException(0); } |
105 | 107 |
106 void insertRange(int start, int length, [E initialValue]) native """ | 108 void insertRange(int start, int rangeLength, [E initialValue]) native """ |
107 if (length == 0) return; | 109 if (rangeLength == 0) return; |
108 if (length < 0) throw new IllegalArgumentException('length'); | 110 if (rangeLength < 0) throw new IllegalArgumentException('length'); |
109 if (start < 0 || start > this.length) | 111 if (start < 0 || start > this.length) |
110 throw new IndexOutOfRangeException(start); | 112 throw new IndexOutOfRangeException(start); |
111 | 113 |
112 // Splice in the values with a minimum of array allocations. | 114 // Splice in the values with a minimum of array allocations. |
113 var args = new Array(length + 2); | 115 var args = new Array(rangeLength + 2); |
114 args[0] = start; | 116 args[0] = start; |
115 args[1] = 0; | 117 args[1] = 0; |
116 for (var i = 0; i < length; i++) { | 118 for (var i = 0; i < rangeLength; i++) { |
117 args[i + 2] = initialValue; | 119 args[i + 2] = initialValue; |
118 } | 120 } |
119 this.splice.apply(this, args); | 121 this.splice.apply(this, args); |
120 """ { throw new IllegalArgumentException(''); | 122 """ { throw new IllegalArgumentException(''); |
121 throw new IndexOutOfRangeException(0); } | 123 throw new IndexOutOfRangeException(0); } |
122 | 124 |
123 // Collection<E> members: | 125 // Collection<E> members: |
124 void forEach(void f(E element)) native; | 126 void forEach(void f(E element)) native; |
125 Collection<E> filter(bool f(E element)) native; | 127 Collection<E> filter(bool f(E element)) native; |
126 Collection map(f(E element)) native; | 128 Collection map(f(E element)) native; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 List<String> this._groups); | 353 List<String> this._groups); |
352 | 354 |
353 final String pattern; | 355 final String pattern; |
354 final String str; | 356 final String str; |
355 final int _start; | 357 final int _start; |
356 final int _end; | 358 final int _end; |
357 final List<String> _groups; | 359 final List<String> _groups; |
358 | 360 |
359 int start() => _start; | 361 int start() => _start; |
360 int end() => _end; | 362 int end() => _end; |
361 String group(int group) => _groups[group]; | 363 String group(int groupIndex) => _groups[groupIndex]; |
362 String operator [](int group) => _groups[group]; | 364 String operator [](int groupIndex) => _groups[groupIndex]; |
363 int groupCount() => _groups.length; | 365 int groupCount() => _groups.length; |
364 | 366 |
365 List<String> groups(List<int> groups) { | 367 List<String> groups(List<int> groupIndices) { |
366 List<String> out = []; | 368 List<String> out = []; |
367 groups.forEach((int group) => out.add(_groups[group])); | 369 groupIndices.forEach((int groupIndex) => out.add(_groups[groupIndex])); |
368 return out; | 370 return out; |
369 } | 371 } |
370 } | 372 } |
371 | 373 |
372 class _AllMatchesIterable implements Iterable<Match> { | 374 class _AllMatchesIterable implements Iterable<Match> { |
373 final JSSyntaxRegExp _re; | 375 final JSSyntaxRegExp _re; |
374 final String _str; | 376 final String _str; |
375 | 377 |
376 const _AllMatchesIterable(this._re, this._str); | 378 const _AllMatchesIterable(this._re, this._str); |
377 | 379 |
378 Iterator<Match> iterator() => new _AllMatchesIterator(_re, _str); | 380 Iterator<Match> iterator() => new _AllMatchesIterator(_re, _str); |
379 } | 381 } |
380 | 382 |
381 class _AllMatchesIterator implements Iterator<Match> { | 383 class _AllMatchesIterator implements Iterator<Match> { |
382 final RegExp _re; | 384 final RegExp _re; |
383 final String _str; | 385 final String _str; |
384 Match _next; | 386 Match _next; |
385 bool _done; | 387 bool _done; |
386 | 388 |
387 _AllMatchesIterator(JSSyntaxRegExp re, String this._str) | 389 _AllMatchesIterator(JSSyntaxRegExp re, String this._str) |
388 : _done = false, _re = re._global; | 390 : _done = false, _re = re._global; |
389 | 391 |
390 Match next() { | 392 Match next() { |
391 if (!hasNext()) { | 393 if (!hasNext()) { |
392 throw const NoMoreElementsException(); | 394 throw const NoMoreElementsException(); |
393 } | 395 } |
394 | 396 |
395 // _next is set by #hasNext | 397 // _next is set by #hasNext |
396 var next = _next; | 398 var result = _next; |
397 _next = null; | 399 _next = null; |
398 return next; | 400 return result; |
399 } | 401 } |
400 | 402 |
401 bool hasNext() { | 403 bool hasNext() { |
402 if (_done) { | 404 if (_done) { |
403 return false; | 405 return false; |
404 } else if (_next != null) { | 406 } else if (_next != null) { |
405 return true; | 407 return true; |
406 } | 408 } |
407 | 409 |
408 _next = _re.firstMatch(_str); | 410 _next = _re.firstMatch(_str); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 } else if (isNaN()) { | 518 } else if (isNaN()) { |
517 if (other.isNaN()) { | 519 if (other.isNaN()) { |
518 return 0; | 520 return 0; |
519 } | 521 } |
520 return 1; | 522 return 1; |
521 } else { | 523 } else { |
522 return -1; | 524 return -1; |
523 } | 525 } |
524 } | 526 } |
525 } | 527 } |
OLD | NEW |