public function format($string, $number)
{
list($sets, $strings) = $this->parse($string);
$total = count($sets);
for ($i = 0; $i < $total; $i++) {
if ($this->isValid($number, $sets[$i])) {
return $strings[$i];
}
}
return false;
}
function test_english() { $choice = new ChoiceFormat(); $string = '[0] none |{n: n % 10 == 1} 1st |{n: n % 10 == 2} 2nd |{n: n % 10 == 3} 3rd |{n:n} th'; $wants = array('none' => array(0), '1st' => array(1, 11, 21), '2nd' => array(2, 12, 22), '3rd' => array(3, 13, 23), 'th' => array(4, 5, 6, 7, 14, 15)); foreach ($wants as $want => $numbers) { foreach ($numbers as $n) { $this->assertEquals($want, $choice->format($string, $n)); } } }