| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 '${items.getRange(0, items.length - 1).join(', ')}' |
| 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 |