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

Side by Side Diff: lib/dartdoc/utils.dart

Issue 10701091: Dartdoc and Apidoc updated to use dart2js through the mirror system. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed cf. rnystrom's comments. Created 8 years, 5 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 // Generic utility functions. 5 // Generic utility functions.
6 6
7 /** Turns [name] into something that's safe to use as a file name. */ 7 /** Turns [name] into something that's safe to use as a file name. */
8 String sanitize(String name) => name.replaceAll(':', '_').replaceAll('/', '_'); 8 String sanitize(String name) => name.replaceAll(':', '_').replaceAll('/', '_');
9 9
10 /** Returns the number of times [search] occurs in [text]. */ 10 /** Returns the number of times [search] occurs in [text]. */
(...skipping 29 matching lines...) Expand all
40 var start; 40 var start;
41 for (start = 0; start < Math.min(indentation, text.length); start++) { 41 for (start = 0; start < Math.min(indentation, text.length); start++) {
42 // Stop if we hit a non-whitespace character. 42 // Stop if we hit a non-whitespace character.
43 if (text[start] != ' ') break; 43 if (text[start] != ' ') break;
44 } 44 }
45 45
46 return text.substring(start); 46 return text.substring(start);
47 } 47 }
48 48
49 /** Sorts the map by the key, doing a case-insensitive comparison. */ 49 /** Sorts the map by the key, doing a case-insensitive comparison. */
50 List orderByName(Map<String, Dynamic> map) { 50 List<Mirror> orderByName(List<Mirror> list) {
51 List keys = map.getKeys(); 51 final elements = new List<Mirror>.from(list);
52 keys.sort((a, b) { 52 elements.sort((a,b) {
53 // Hack: make sure $dom methods show up last in the list not first. 53 String aName = a.simpleName();
54 String transformName(String name) => 54 String bName = b.simpleName();
55 name.toUpperCase().replaceFirst(const RegExp('\\\$DOM_'), 'zzzz'); 55 bool doma = aName.startsWith(@"$dom");
56 56 bool domb = bName.startsWith(@"$dom");
57 return transformName(a).compareTo(transformName(b)); 57 return doma == domb ? aName.compareTo(bName) : doma ? 1 : -1;
58 }); 58 });
59 final values = []; 59 return elements;
60 for (var k in keys) {
61 values.add(map[k]);
62 }
63 return values;
64 } 60 }
65 61
66 /** 62 /**
67 * Joins [items] into a single, comma-separated string using [conjunction]. 63 * Joins [items] into a single, comma-separated string using [conjunction].
68 * E.g. `['A', 'B', 'C']` becomes `"A, B, and C"`. 64 * E.g. `['A', 'B', 'C']` becomes `"A, B, and C"`.
69 */ 65 */
70 String joinWithCommas(List<String> items, [String conjunction = 'and']) { 66 String joinWithCommas(List<String> items, [String conjunction = 'and']) {
71 if (items.length == 1) return items[0]; 67 if (items.length == 1) return items[0];
72 if (items.length == 2) return "${items[0]} $conjunction ${items[1]}"; 68 if (items.length == 2) return "${items[0]} $conjunction ${items[1]}";
73 return Strings.join(items.getRange(0, items.length - 1), ', ') + 69 return '${Strings.join(items.getRange(0, items.length - 1), ', ')}'
74 ', $conjunction ' + items[items.length - 1]; 70 ', $conjunction ${items[items.length - 1]}';
75 } 71 }
72
73 void writeString(File file, String text) {
74 var randomAccessFile = file.openSync(FileMode.WRITE);
75 randomAccessFile.writeStringSync(text);
76 randomAccessFile.closeSync();
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698