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

Side by Side Diff: dart/tests/try/poi/source_update.dart

Issue 799403005: Avoid repeating common parts of ProgramResults. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r42384. Created 6 years 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 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 library trydart.source_update;
6
7 /// Returns [updates] expanded to full compilation units/source files.
8 ///
9 /// [updates] is a convenient way to write updates/patches to a single source
10 /// file without repeating common parts.
11 ///
12 /// For example:
13 /// ["head ", ["v1", "v2"], " tail"]
14 /// expands to:
15 /// ["head v1 tail", "head v2 tail"]
16 List<String> expandUpdates(List updates) {
17 int outputCount = updates.firstWhere((e) => e is Iterable).length;
18 List<StringBuffer> result = new List<StringBuffer>(outputCount);
19 for (int i = 0; i < outputCount; i++) {
20 result[i] = new StringBuffer();
21 }
22 for (var chunk in updates) {
23 if (chunk is Iterable) {
24 int segmentCount = 0;
25 for (var segment in chunk) {
26 result[segmentCount++].write(segment);
27 }
28 if (segmentCount != outputCount) {
29 throw new ArgumentError(
30 "Expected ${outputCount} segments, "
31 "but found ${segmentCount} in $chunk");
32 }
33 } else {
34 for (StringBuffer buffer in result) {
35 buffer.write(chunk);
36 }
37 }
38 }
39
40 return result.map((e) => '$e').toList();
41 }
OLDNEW
« no previous file with comments | « dart/tests/try/poi/library_updater_test.dart ('k') | dart/tests/try/poi/source_update_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698