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

Side by Side Diff: tools/gardening/lib/src/util.dart

Issue 2751543006: structure gardening tool (Closed)
Patch Set: oops Created 3 years, 9 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
« no previous file with comments | « tools/gardening/lib/current_summary.dart ('k') | tools/gardening/lib/status_summary.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'dart:async';
6 import 'dart:convert';
7 import 'dart:io';
8
5 /// Split [text] using [infixes] as infix markers. 9 /// Split [text] using [infixes] as infix markers.
6 List<String> split(String text, List<String> infixes) { 10 List<String> split(String text, List<String> infixes) {
7 List<String> result = <String>[]; 11 List<String> result = <String>[];
8 int start = 0; 12 int start = 0;
9 for (String infix in infixes) { 13 for (String infix in infixes) {
10 int index = text.indexOf(infix, start); 14 int index = text.indexOf(infix, start);
11 if (index == -1) 15 if (index == -1)
12 throw "'$infix' not found in '$text' from offset ${start}."; 16 throw "'$infix' not found in '$text' from offset ${start}.";
13 result.add(text.substring(start, index)); 17 result.add(text.substring(start, index));
14 start = index + infix.length; 18 start = index + infix.length;
15 } 19 }
16 result.add(text.substring(start)); 20 result.add(text.substring(start));
17 return result; 21 return result;
18 } 22 }
19 23
20 /// Pad [text] with spaces to the right to fit [length]. 24 /// Pad [text] with spaces to the right to fit [length].
21 String padRight(String text, int length) { 25 String padRight(String text, int length) {
22 if (text.length < length) return '${text}${' ' * (length - text.length)}'; 26 if (text.length < length) return '${text}${' ' * (length - text.length)}';
23 return text; 27 return text;
24 } 28 }
25 29
26 const bool LOG = const bool.fromEnvironment('LOG', defaultValue: false); 30 const bool LOG = const bool.fromEnvironment('LOG', defaultValue: false);
27 31
28 void log(String text) { 32 void log(String text) {
29 if (LOG) print(text); 33 if (LOG) print(text);
30 } 34 }
35
36 /// Reads the content of [uri] as text.
37 Future<String> readUriAsText(HttpClient client, Uri uri) async {
38 HttpClientRequest request = await client.getUrl(uri);
39 HttpClientResponse response = await request.close();
40 return await response.transform(UTF8.decoder).join();
41 }
OLDNEW
« no previous file with comments | « tools/gardening/lib/current_summary.dart ('k') | tools/gardening/lib/status_summary.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698