## Class ChoiceFormat

Description

ChoiceFormat class.

ChoiceFormat converts between ranges of numeric values and string names for those ranges.

A ChoiceFormat splits the real number line -Inf to +Inf into two or more contiguous ranges. Each range is mapped to a string. ChoiceFormat is generally used in a MessageFormat for displaying grammatically correct plurals such as "There are 2 files."

        $string = '[0] are no files |[1] is one file |(1,Inf] are {number} files';

      $formatter = new MessageFormat(...); //init for a source
            $translated = $formatter->format($string);

      $choice = new ChoiceFormat();
         echo $choice->format($translated, 0); //shows "are no files"

The message/string choices are separated by the pipe "|" followed by a set notation of the form

- <t>[1,2]</t> -- accepts values between 1 and 2, inclusive.
- <t>(1,2)</t> -- accepts values between 1 and 2, excluding 1 and 2.
- <t>{1,2,3,4}</t> -- only values defined in the set are accepted.
- <t>[-Inf,0)</t> -- accepts value greater or equal to negative infinity and strictly less than 0

Any non-empty combinations of the delimiters of square and round brackets are acceptable.

- version: v1.0, last update on Fri Dec 24 20:46:16 EST 2004
- author: Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>

Located in /I18N/core/ChoiceFormat.php (line 56)

Variable Summary
float $inf
string $parse
string $validate
Method Summary
ChoiceFormat __construct ()
string format (string $string, float $number)
boolean isValid (float $number, string $set)
array parse (string $string)
Variables
float $inf (line 74)

The value for positive infinity.

- access: protected

string $parse = '/\s?\|?([\(\[\{]([-Inf\d]+,?[\+Inf\d]*)+[\)\]\}])\s?/' (line 68)

The pattern to parse the formatting string.

- access: protected

string $validate = '/[\(\[\{]|[-Inf\d]+|,|[\+Inf\d]+|[\)\]\}]/ms' (line 62)

The pattern to validate a set notation

- access: protected

Methods
Constructor __construct (line 80)

Constructor.

ChoiceFormat __construct ()
format (line 173)

For the choice string, and a number, find and return the string that satisfied the set within the choices.

- return: the choosen string.
- access: public

string format (string $string, float $number)

- string $string: the choices string.
- float $number: the number to test.

isValid (line 92)

Determine if the given number belongs to a given set

- return: true if number is in the set, false otherwise.

boolean isValid (float $number, string $set)

- float $number: the number to test.
- string $set: the set, in set notation.

parse (line 148)

Parse a choice string and get a list of sets and a list of strings corresponding to the sets.

- return: array($sets, $strings)

array parse (string $string)

- string $string: the string containing the choices

Documentation generated on Sun, 04 Jun 2006 18:58:23 -0400 by phpDocumentor 1.3.0RC4