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

Unified Diff: third_party/pkg/angular/lib/filter/limit_to.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/lib/filter/limit_to.dart
diff --git a/third_party/pkg/angular/lib/filter/limit_to.dart b/third_party/pkg/angular/lib/filter/limit_to.dart
new file mode 100644
index 0000000000000000000000000000000000000000..17d6c35ceebeb1d5e47339ec660731eeb8e583ec
--- /dev/null
+++ b/third_party/pkg/angular/lib/filter/limit_to.dart
@@ -0,0 +1,69 @@
+part of angular.filter;
+
+/**
+ * Creates a new List or String containing only a prefix/suffix of the
+ * elements as specified by the `limit` parameter.
+ *
+ * When operating on a List, the returned list is always a copy even when all
+ * the elements are being returned.
+ *
+ * When the `limit` expression evaluates to a positive integer, `limit` items
+ * from the beginning of the List/String are returned. When `limit` evaluates
+ * to a negative integer, `|limit|` items from the end of the List/String are
+ * returned. If `|limit|` is larger than the size of the List/String, then the
+ * entire List/String is returned. In the case of a List, a copy of the list is
+ * returned.
+ *
+ * If the `limit` expression evaluates to a null or non-integer, then an empty
+ * list is returned. If the input is a null List/String, a null is returned.
+ *
+ * Example:
+ *
+ * - `{{ 'abcdefghij' | limitTo: 4 }}` → `'abcd'`
+ * - `{{ 'abcdefghij' | limitTo: -4 }}` → `'ghij'`
+ * - `{{ 'abcdefghij' | limitTo: -100 }}` → `'abcdefghij'`
+ *
+ * <br>
+ *
+ * This [ng-repeat] directive:
+ *
+ * <li ng-repeat="i in 'abcdefghij' | limitTo:-2">{{i}}</li>
+ *
+ * results in
+ *
+ * <li>i</li>
+ * <li>j</li>
+ */
+@NgFilter(name:'limitTo')
+class LimitToFilter {
+ Injector _injector;
+ Parser _parser;
+
+ LimitToFilter(this._injector, this._parser);
+
+ dynamic call(dynamic items, [int limit]) {
+ if (items == null) {
+ return null;
+ }
+ if (limit == null) {
+ return const[];
+ }
+ if (items is! List && items is! String) {
+ return items;
+ }
+ int i = 0, j = items.length;
+ if (limit > -1) {
+ j = (limit > j) ? j : limit;
+ } else {
+ i = j + limit;
+ if (i < 0) {
+ i = 0;
+ }
+ }
+ if (items is String) {
+ return (items as String).substring(i, j);
+ } else {
+ return (items as List).getRange(i, j).toList(growable: false);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698