OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library stub_core_libraries.utils; |
| 6 |
| 7 /// Returns a sentence fragment listing the elements of [iter]. |
| 8 /// |
| 9 /// This converts each element of [iter] to a string and separates them with |
| 10 /// commas and/or "and" where appropriate. |
| 11 String toSentence(Iterable iter) { |
| 12 if (iter.length == 1) return iter.first.toString(); |
| 13 return iter.take(iter.length - 1).join(", ") + " and ${iter.last}"; |
| 14 } |
| 15 |
| 16 /// Returns [name] if [number] is 1, or the plural of [name] otherwise. |
| 17 /// |
| 18 /// By default, this just adds "s" to the end of [name] to get the plural. If |
| 19 /// [plural] is passed, that's used instead. |
| 20 String pluralize(String name, int number, {String plural}) { |
| 21 if (number == 1) return name; |
| 22 if (plural != null) return plural; |
| 23 return '${name}s'; |
| 24 } |
OLD | NEW |