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

Side by Side Diff: third_party/pkg/angular/lib/formatter/limit_to.dart

Issue 256553002: Revert "Update all Angular libs (run update_all.sh)." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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
OLDNEW
(Empty)
1 part of angular.formatter_internal;
2
3 /**
4 * Creates a new List or String containing only a prefix/suffix of the
5 * elements as specified by the `limit` parameter.
6 *
7 * When operating on a List, the returned list is always a copy even when all
8 * the elements are being returned.
9 *
10 * When the `limit` expression evaluates to a positive integer, `limit` items
11 * from the beginning of the List/String are returned. When `limit` evaluates
12 * to a negative integer, `|limit|` items from the end of the List/String are
13 * returned. If `|limit|` is larger than the size of the List/String, then the
14 * entire List/String is returned. In the case of a List, a copy of the list is
15 * returned.
16 *
17 * If the `limit` expression evaluates to a null or non-integer, then an empty
18 * list is returned. If the input is a null List/String, a null is returned.
19 *
20 * Example:
21 *
22 * - `{{ 'abcdefghij' | limitTo: 4 }}` → `'abcd'`
23 * - `{{ 'abcdefghij' | limitTo: -4 }}` → `'ghij'`
24 * - `{{ 'abcdefghij' | limitTo: -100 }}` → `'abcdefghij'`
25 *
26 * <br>
27 *
28 * This [ng-repeat] directive:
29 *
30 * <li ng-repeat="i in 'abcdefghij' | limitTo:-2">{{i}}</li>
31 *
32 * results in
33 *
34 * <li>i</li>
35 * <li>j</li>
36 */
37 @Formatter(name:'limitTo')
38 class LimitTo implements Function {
39 Injector _injector;
40
41 LimitTo(this._injector);
42
43 dynamic call(dynamic items, [int limit]) {
44 if (items == null) return null;
45 if (limit == null) return const[];
46 if (items is! List && items is! String) return items;
47 int i = 0, j = items.length;
48 if (limit > -1) {
49 j = (limit > j) ? j : limit;
50 } else {
51 i = j + limit;
52 if (i < 0) i = 0;
53 }
54 return items is String ?
55 (items as String).substring(i, j) :
56 (items as List).getRange(i, j).toList(growable: false);
57 }
58 }
OLDNEW
« no previous file with comments | « third_party/pkg/angular/lib/formatter/json.dart ('k') | third_party/pkg/angular/lib/formatter/lowercase.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698