What's missing from Phobos for Orbit (package manager)

FG home at fgda.pl
Tue Feb 12 08:39:43 PST 2013


On 2013-02-12 15:21, Steven Schveighoffer wrote:
> string pluralize(string x, int count)
> {
>     return count > 1 ? x ~ "s" : x;
> }

You mean: return count != 1 ? x ~ "s" : x;
For special cases there could be a third optional argument:

     string pluralize(int count, string sng, string pl="") {
         return count == 1 ? sng : pl.length ? pl : sng ~ "s";
     }
     writeln(pluralize(2, "cat"));
     writeln(pluralize(2, "radius", "radii"));


That's for simple English-only pluralization, before we jump into translations.


More information about the Digitalmars-d mailing list