2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 06:15:47 +00:00

util: New function for forming English lists.

This follows the rules I learned in school.  Some locales may prefer to
omit the comma before "and" in a list of three or more items.
This commit is contained in:
Ben Pfaff
2011-06-02 10:47:18 -07:00
parent 29d7226e8b
commit 44b4d050d4
2 changed files with 13 additions and 0 deletions

View File

@@ -596,3 +596,14 @@ abs_file_name(const char *dir, const char *file_name)
* its return value. (Note that every scalar type can be implicitly
* converted to bool.) */
void ignore(bool x OVS_UNUSED) { }
/* Returns an appropriate delimiter for inserting just before the 0-based item
* 'index' in a list that has 'total' items in it. */
const char *
english_list_delimiter(size_t index, size_t total)
{
return (index == 0 ? ""
: index < total - 1 ? ", "
: total > 2 ? ", and "
: " and ");
}