PHP Class Neos\Flow\I18n\Parser\NumberParser

This parser does not support full syntax of number formats as defined in CLDR. It uses parsed formats from NumbersReader class.
See also: NumbersReader
Exibir arquivo Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$numbersReader Neos\Flow\I18n\Cldr\Reader\NumbersReader

Public Methods

Method Description
injectNumbersReader ( NumbersReader $numbersReader ) : void
parseDecimalNumber ( string $numberToParse, Locale $locale, string $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT, boolean $strictMode = true ) : mixed Parses decimal number using proper format from CLDR.
parseNumberWithCustomPattern ( string $numberToParse, string $format, Locale $locale, boolean $strictMode = true ) : mixed Parses number given as a string using provided format.
parsePercentNumber ( string $numberToParse, Locale $locale, string $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT, boolean $strictMode = true ) : mixed Parses percent number using proper format from CLDR.

Protected Methods

Method Description
doParsingInLenientMode ( string $numberToParse, array $parsedFormat, array $localizedSymbols ) : mixed Parses number in lenient mode.
doParsingInStrictMode ( string $numberToParse, array $parsedFormat, array $localizedSymbols ) : mixed Parses number in strict mode.
doParsingWithParsedFormat ( string $numberToParse, array $parsedFormat, array $localizedSymbols, boolean $strictMode ) : mixed Parses number using parsed format, in strict or lenient mode.

Method Details

doParsingInLenientMode() protected method

Lenient parsing ignores everything that can be ignored, and tries to extract number from the string, even if it's not well formed. Implementation is simple but should work more often than strict parsing. Algorithm: 1. Find first digit 2. Find last digit 3. Find decimal separator between first and last digit (if any) 4. Remove non-digits from integer part 5. Remove non-digits from decimal part (optional) 6. Try to match negative prefix before first digit 7. Try to match negative suffix after last digit
protected doParsingInLenientMode ( string $numberToParse, array $parsedFormat, array $localizedSymbols ) : mixed
$numberToParse string Number to be parsed
$parsedFormat array Parsed format (from NumbersReader)
$localizedSymbols array An array with symbols to use
return mixed Parsed float number or FALSE on failure

doParsingInStrictMode() protected method

In strict mode parser checks all constraints of provided parsed format, and if any of them is not fullfiled, parsing fails (FALSE is returned).
protected doParsingInStrictMode ( string $numberToParse, array $parsedFormat, array $localizedSymbols ) : mixed
$numberToParse string Number to be parsed
$parsedFormat array Parsed format (from NumbersReader)
$localizedSymbols array An array with symbols to use
return mixed Parsed float number or FALSE on failure

doParsingWithParsedFormat() protected method

Parses number using parsed format, in strict or lenient mode.
protected doParsingWithParsedFormat ( string $numberToParse, array $parsedFormat, array $localizedSymbols, boolean $strictMode ) : mixed
$numberToParse string Number to be parsed
$parsedFormat array Parsed format (from NumbersReader)
$localizedSymbols array An array with symbols to use
$strictMode boolean Work mode (strict when TRUE, lenient when FALSE)
return mixed Parsed float number or FALSE on failure

injectNumbersReader() public method

public injectNumbersReader ( NumbersReader $numbersReader ) : void
$numbersReader Neos\Flow\I18n\Cldr\Reader\NumbersReader
return void

parseDecimalNumber() public method

Parses decimal number using proper format from CLDR.
public parseDecimalNumber ( string $numberToParse, Locale $locale, string $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT, boolean $strictMode = true ) : mixed
$numberToParse string Number to be parsed
$locale Neos\Flow\I18n\Locale Locale to use
$formatLength string One of NumbersReader FORMAT_LENGTH constants
$strictMode boolean Work mode (strict when TRUE, lenient when FALSE)
return mixed Parsed float number or FALSE on failure

parseNumberWithCustomPattern() public method

Parses number given as a string using provided format.
public parseNumberWithCustomPattern ( string $numberToParse, string $format, Locale $locale, boolean $strictMode = true ) : mixed
$numberToParse string Number to be parsed
$format string Number format to use
$locale Neos\Flow\I18n\Locale Locale to use
$strictMode boolean Work mode (strict when TRUE, lenient when FALSE)
return mixed Parsed float number or FALSE on failure

parsePercentNumber() public method

Parses percent number using proper format from CLDR.
public parsePercentNumber ( string $numberToParse, Locale $locale, string $formatLength = NumbersReader::FORMAT_LENGTH_DEFAULT, boolean $strictMode = true ) : mixed
$numberToParse string Number to be parsed
$locale Neos\Flow\I18n\Locale Locale to use
$formatLength string One of NumbersReader FORMAT_LENGTH constants
$strictMode boolean Work mode (strict when TRUE, lenient when FALSE)
return mixed Parsed float number or FALSE on failure

Property Details

$numbersReader protected_oe property

protected NumbersReader,Neos\Flow\I18n\Cldr\Reader $numbersReader
return Neos\Flow\I18n\Cldr\Reader\NumbersReader