I’m thinking of a function for localization purposes where I know exactly what it is supposed to do, and how to do it, but i can’t for the life of me figure out a good name for it. I’m pretty sure there is a decent standard expression in the english language that could apply brilliantly to this thing here, I just can’t find it.
The question itself is totally language agnostic but the code here is in PHP because that’s what I’m writing at the moment.
So please, name my function!
/**
* Expand a number into a format string based on its value, giving
* different format strings for 0, 1 and greater than one.
*
* example:
* myFun(count($apples), 'No apples', 'one apple', '%d apples.');
*
* @param integer $aNumber
* @param string $ifZero
* @param string $ifOne
* @param string $ifGreaterThanOne
* @return string
*/
function myFunc($aNumber, $ifZero, $ifOne, $ifGreaterThanOne)
{
assert('is_integer($aNumber) && $aNumber > -1;');
assert('is_string($ifZero);');
assert('is_string($ifOne);');
assert('is_string($ifGreaterThanOne);');
$result = null;
if ($aNumber == 0)
{
$result = strpos($ifZero, '%d') > -1
? sprintf($ifZero, $aNumber)
: $ifZero;
}
else if ($aNumber == 1)
{
$result = strpos($ifOne, '%d') > -1
? sprintf($ifOne, $aNumber)
: $ifOne;
}
else
{
$result = strpos($ifGreaterThanOne, '%d') > -1
? sprintf($ifGreaterThanOne, $aNumber)
: $ifGreaterThanOne;
}
return $result;
}
The most technical name I’ve seen is “CardinalityLabel,” but I usually call it CountLabel.