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

Side by Side Diff: utils/pub/utils.dart

Issue 10867070: Support removing dead packages with `pub install`. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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
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 /** 5 /**
6 * Generic utility functions. Stuff that should possibly be in core. 6 * Generic utility functions. Stuff that should possibly be in core.
7 */ 7 */
8 #library('utils'); 8 #library('utils');
9 9
10 #import('dart:crypto'); 10 #import('dart:crypto');
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 */ 74 */
75 only(Iterable iter) { 75 only(Iterable iter) {
76 var iterator = iter.iterator(); 76 var iterator = iter.iterator();
77 assert(iterator.hasNext()); 77 assert(iterator.hasNext());
78 var obj = iterator.next(); 78 var obj = iterator.next();
79 assert(!iterator.hasNext()); 79 assert(!iterator.hasNext());
80 return obj; 80 return obj;
81 } 81 }
82 82
83 /** 83 /**
84 * Returns a set containing all elements in [minuend] that are not in
85 * [subtrahend].
86 */
87 Set setMinus(Collection minuend, Collection subtrahend) {
88 var minuendSet = new Set.from(minuend);
89 minuendSet.removeAll(subtrahend);
90 return minuendSet;
91 }
92
93 /**
84 * Replace each instance of [matcher] in [source] with the return value of [fn]. 94 * Replace each instance of [matcher] in [source] with the return value of [fn].
85 */ 95 */
86 String replace(String source, Pattern matcher, String fn(Match)) { 96 String replace(String source, Pattern matcher, String fn(Match)) {
87 var buffer = new StringBuffer(); 97 var buffer = new StringBuffer();
88 var start = 0; 98 var start = 0;
89 for (var match in matcher.allMatches(source)) { 99 for (var match in matcher.allMatches(source)) {
90 buffer.add(source.substring(start, match.start())); 100 buffer.add(source.substring(start, match.start()));
91 start = match.end(); 101 start = match.end();
92 buffer.add(fn(match)); 102 buffer.add(fn(match));
93 } 103 }
(...skipping 18 matching lines...) Expand all
112 CryptoUtils.bytesToHex(new SHA1().update(source.charCodes()).digest()); 122 CryptoUtils.bytesToHex(new SHA1().update(source.charCodes()).digest());
113 123
114 /** 124 /**
115 * Returns a [Future] that completes in [milliSeconds]. 125 * Returns a [Future] that completes in [milliSeconds].
116 */ 126 */
117 Future sleep(int milliSeconds) { 127 Future sleep(int milliSeconds) {
118 var completer = new Completer(); 128 var completer = new Completer();
119 new Timer(milliSeconds, completer.complete); 129 new Timer(milliSeconds, completer.complete);
120 return completer.future; 130 return completer.future;
121 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698