Index: utils/dartdoc/utils.dart |
diff --git a/utils/dartdoc/utils.dart b/utils/dartdoc/utils.dart |
index a77d5fcfeb6616681b2047964896368c8292c41c..b827772f84236076da2ae360a093b396d0cb679e 100644 |
--- a/utils/dartdoc/utils.dart |
+++ b/utils/dartdoc/utils.dart |
@@ -65,4 +65,15 @@ List orderByName(Map<String, Dynamic> map) { |
values.add(map[k]); |
} |
return values; |
-} |
+} |
+ |
+/** |
+ * Joins [items] into a single, comma-separated string using [conjunction]. |
+ * E.g. `['A', 'B', 'C']` becomes `"A, B, and C"`. |
+ */ |
+String joinWithCommas(List<String> items, [String conjunction = 'and']) { |
+ if (items.length == 1) return items[0]; |
+ if (items.length == 2) return "${items[0]} $conjunction ${items[1]}"; |
+ return Strings.join(items.getRange(0, items.length - 1), ', ') + |
+ ', $conjunction ' + items[items.length - 1]; |
+} |