Neos\Flow\I18n\Cldr\Reader\DatesReader::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: DatesReader::$parsedFormats
protected parseFormat ( string $format ) : array
$format string
return array Parsed format
    protected function parseFormat($format)
    {
        $parsedFormat = [];
        $formatLengthOfFormat = strlen($format);
        $duringCompletionOfLiteral = false;
        $literal = '';
        for ($i = 0; $i < $formatLengthOfFormat; ++$i) {
            $subformatSymbol = $format[$i];
            if ($subformatSymbol === '\'') {
                if ($i < $formatLengthOfFormat - 1 && $format[$i + 1] === '\'') {
                    // Two apostrophes means that one apostrophe is escaped
                    if ($duringCompletionOfLiteral) {
                        // We are already reading some literal, save it and continue
                        $parsedFormat[] = [$literal];
                        $literal = '';
                    }
                    $parsedFormat[] = ['\''];
                    ++$i;
                } elseif ($duringCompletionOfLiteral) {
                    $parsedFormat[] = [$literal];
                    $literal = '';
                    $duringCompletionOfLiteral = false;
                } else {
                    $duringCompletionOfLiteral = true;
                }
            } elseif ($duringCompletionOfLiteral) {
                $literal .= $subformatSymbol;
            } else {
                // Count the length of subformat
                for ($j = $i + 1; $j < $formatLengthOfFormat; ++$j) {
                    if ($format[$j] !== $subformatSymbol) {
                        break;
                    }
                }
                $subformat = str_repeat($subformatSymbol, $j - $i);
                if (isset(self::$maxLengthOfSubformats[$subformatSymbol])) {
                    if (self::$maxLengthOfSubformats[$subformatSymbol] === 0 || strlen($subformat) <= self::$maxLengthOfSubformats[$subformatSymbol]) {
                        $parsedFormat[] = $subformat;
                    } else {
                        throw new Exception\InvalidDateTimeFormatException('Date / time pattern is too long: ' . $subformat . ', specification allows up to ' . self::$maxLengthOfSubformats[$subformatSymbol] . ' chars.', 1276114248);
                    }
                } else {
                    $parsedFormat[] = [$subformat];
                }
                $i = $j - 1;
            }
        }
        if ($literal !== '') {
            $parsedFormat[] = [$literal];
        }
        return $parsedFormat;
    }