X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Futil.c;h=1a42376e21216fc0c3a07ea928dd172719f1515e;hb=c002dde70329b5553b79f3f1ad6d60771f4179c0;hp=c05c582fed6fe2e0b4481aa01cfeb1a05e1f23a4;hpb=fcaddd4dd1e8feefc09ea2664ad51fb669d136f8;p=openvswitch diff --git a/lib/util.c b/lib/util.c index c05c582f..1a42376e 100644 --- a/lib/util.c +++ b/lib/util.c @@ -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 "); +}