| OLD | NEW |
| 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 Loading... |
| 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 } |
| OLD | NEW |