Neos\Flow\I18n\Cldr\Reader\NumbersReader::parseFormat PHP Method

parseFormat() protected method

Not all features from CLDR specification are implemented. Please see the documentation for this class for details what is missing.
See also: NumbersReader::$parsedFormats
protected parseFormat ( string $format ) : array
$format string
return array Parsed format
    protected function parseFormat($format)
    {
        foreach (['E', '@', '*', '\''] as $unsupportedFeature) {
            if (strpos($format, $unsupportedFeature) !== false) {
                throw new Exception\UnsupportedNumberFormatException('Encountered unsupported format characters in format string.', 1280219449);
            }
        }
        $parsedFormat = ['positivePrefix' => '', 'positiveSuffix' => '', 'negativePrefix' => '-', 'negativeSuffix' => '', 'multiplier' => 1, 'minDecimalDigits' => 0, 'maxDecimalDigits' => 0, 'minIntegerDigits' => 1, 'primaryGroupingSize' => 0, 'secondaryGroupingSize' => 0, 'rounding' => 0.0];
        if (strpos($format, ';') !== false) {
            list($positiveFormat, $negativeFormat) = explode(';', $format);
            $format = $positiveFormat;
        } else {
            $positiveFormat = $format;
            $negativeFormat = null;
        }
        if (preg_match(self::PATTERN_MATCH_SUBFORMAT, $positiveFormat, $matches) === 1) {
            $parsedFormat['positivePrefix'] = $matches[1];
            $parsedFormat['positiveSuffix'] = $matches[2];
        }
        if ($negativeFormat !== null && preg_match(self::PATTERN_MATCH_SUBFORMAT, $negativeFormat, $matches) === 1) {
            $parsedFormat['negativePrefix'] = $matches[1];
            $parsedFormat['negativeSuffix'] = $matches[2];
        } else {
            $parsedFormat['negativePrefix'] = '-' . $parsedFormat['positivePrefix'];
            $parsedFormat['negativeSuffix'] = $parsedFormat['positiveSuffix'];
        }
        if (strpos($format, '%') !== false) {
            $parsedFormat['multiplier'] = 100;
        } elseif (strpos($format, '‰') !== false) {
            $parsedFormat['multiplier'] = 1000;
        }
        if (preg_match(self::PATTERN_MATCH_ROUNDING, $format, $matches) === 1) {
            $parsedFormat['rounding'] = (double) $matches[1];
            $format = preg_replace('/[1-9]/', '0', $format);
        }
        if (($positionOfDecimalSeparator = strpos($format, '.')) !== false) {
            if (($positionOfLastZero = strrpos($format, '0')) > $positionOfDecimalSeparator) {
                $parsedFormat['minDecimalDigits'] = $positionOfLastZero - $positionOfDecimalSeparator;
            }
            if (($positionOfLastHash = strrpos($format, '#')) >= $positionOfLastZero) {
                $parsedFormat['maxDecimalDigits'] = $positionOfLastHash - $positionOfDecimalSeparator;
            } else {
                $parsedFormat['maxDecimalDigits'] = $parsedFormat['minDecimalDigits'];
            }
            $format = substr($format, 0, $positionOfDecimalSeparator);
        }
        $formatWithoutGroupSeparators = str_replace(',', '', $format);
        if (($positionOfFirstZero = strpos($formatWithoutGroupSeparators, '0')) !== false) {
            $parsedFormat['minIntegerDigits'] = strrpos($formatWithoutGroupSeparators, '0') - $positionOfFirstZero + 1;
        }
        $formatWithoutHashes = str_replace('#', '0', $format);
        if (($positionOfPrimaryGroupSeparator = strrpos($format, ',')) !== false) {
            $parsedFormat['primaryGroupingSize'] = strrpos($formatWithoutHashes, '0') - $positionOfPrimaryGroupSeparator;
            if (($positionOfSecondaryGroupSeparator = strrpos(substr($formatWithoutHashes, 0, $positionOfPrimaryGroupSeparator), ',')) !== false) {
                $parsedFormat['secondaryGroupingSize'] = $positionOfPrimaryGroupSeparator - $positionOfSecondaryGroupSeparator - 1;
            } else {
                $parsedFormat['secondaryGroupingSize'] = $parsedFormat['primaryGroupingSize'];
            }
        }
        return $parsedFormat;
    }