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

Side by Side Diff: sdk/lib/_internal/dartdoc/lib/src/dartdoc/utils.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 part of dartdoc; 5 part of dartdoc;
6 6
7 // Generic utility functions. 7 // Generic utility functions.
8 8
9 /** Turns [name] into something that's safe to use as a file name. */ 9 /** Turns [name] into something that's safe to use as a file name. */
10 String sanitize(String name) => name.replaceAll(':', '_').replaceAll('/', '_'); 10 String sanitize(String name) => name.replaceAll(':', '_').replaceAll('/', '_');
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 var start; 42 var start;
43 for (start = 0; start < min(indentation, text.length); start++) { 43 for (start = 0; start < min(indentation, text.length); start++) {
44 // Stop if we hit a non-whitespace character. 44 // Stop if we hit a non-whitespace character.
45 if (text[start] != ' ') break; 45 if (text[start] != ' ') break;
46 } 46 }
47 47
48 return text.substring(start); 48 return text.substring(start);
49 } 49 }
50 50
51 /** Sorts the map by the key, doing a case-insensitive comparison. */ 51 /** Sorts the map by the key, doing a case-insensitive comparison. */
52 List<Mirror> orderByName(Collection<Mirror> list) { 52 List<Mirror> orderByName(Iterable<Mirror> list) {
53 final elements = new List<Mirror>.from(list); 53 final elements = new List<Mirror>.from(list);
54 elements.sort((a,b) { 54 elements.sort((a,b) {
55 String aName = a.simpleName.toLowerCase(); 55 String aName = a.simpleName.toLowerCase();
56 String bName = b.simpleName.toLowerCase(); 56 String bName = b.simpleName.toLowerCase();
57 bool doma = aName.startsWith(r"$dom"); 57 bool doma = aName.startsWith(r"$dom");
58 bool domb = bName.startsWith(r"$dom"); 58 bool domb = bName.startsWith(r"$dom");
59 return doma == domb ? aName.compareTo(bName) : doma ? 1 : -1; 59 return doma == domb ? aName.compareTo(bName) : doma ? 1 : -1;
60 }); 60 });
61 return elements; 61 return elements;
62 } 62 }
63 63
64 /** 64 /**
65 * Joins [items] into a single, comma-separated string using [conjunction]. 65 * Joins [items] into a single, comma-separated string using [conjunction].
66 * E.g. `['A', 'B', 'C']` becomes `"A, B, and C"`. 66 * E.g. `['A', 'B', 'C']` becomes `"A, B, and C"`.
67 */ 67 */
68 String joinWithCommas(List<String> items, [String conjunction = 'and']) { 68 String joinWithCommas(List<String> items, [String conjunction = 'and']) {
69 if (items.length == 1) return items[0]; 69 if (items.length == 1) return items[0];
70 if (items.length == 2) return "${items[0]} $conjunction ${items[1]}"; 70 if (items.length == 2) return "${items[0]} $conjunction ${items[1]}";
71 return '${Strings.join(items.getRange(0, items.length - 1), ', ')}' 71 return '${Strings.join(items.getRange(0, items.length - 1), ', ')}'
72 ', $conjunction ${items[items.length - 1]}'; 72 ', $conjunction ${items[items.length - 1]}';
73 } 73 }
74 74
75 void writeString(File file, String text) { 75 void writeString(File file, String text) {
76 var randomAccessFile = file.openSync(FileMode.WRITE); 76 var randomAccessFile = file.openSync(FileMode.WRITE);
77 randomAccessFile.writeStringSync(text); 77 randomAccessFile.writeStringSync(text);
78 randomAccessFile.closeSync(); 78 randomAccessFile.closeSync();
79 } 79 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/dartdoc/lib/src/client/client-live-nav.dart ('k') | sdk/lib/_internal/dartdoc/lib/src/json_serializer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698