<commit_before><?php

/*
 * This file is part of the Symfony package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Locale\Stub;

use Symfony\Component\Locale\Locale;

/**
 * Provides a stub IntlDateFormatter for the 'en' locale.
 */
class StubIntlDateFormatter
{
    /* formats */
    const NONE = -1;
    const FULL = 0;
    const LONG = 1;
    const MEDIUM = 2;
    const SHORT = 3;

    /* formats */
    const TRADITIONAL = 0;
    const GREGORIAN = 1;

    private $defaultDateFormats = array(
        self::NONE      => '',
        self::FULL      => 'EEEE, LLLL d, y',
        self::LONG      => 'LLLL d, y',
        self::MEDIUM    => 'LLL d, y',
        self::SHORT     => 'M/d/yy',
    );

    private $defaultTimeFormats = array(
        self::FULL      => 'h:mm:ss a zzzz',
        self::LONG      => 'h:mm:ss a z',
        self::MEDIUM    => 'h:mm:ss a',
        self::SHORT     => 'h:mm a',
    );

    private $datetype;
    private $timetype;
    private $pattern;

    private $dateTimeZone;

    public function __construct($locale, $datetype, $timetype, $timezone = null, $calendar = null, $pattern = null)
    {
        if ('en' != $locale) {
            throw new \InvalidArgumentException('Unsupported $locale value. Only the \'en\' locale is supported. Install the intl extension for full localization capabilities.');
        }

        $this->datetype = $datetype;
        $this->timetype = $timetype;

        $this->setPattern($pattern);

        try {
            $this->dateTimeZone = new \DateTimeZone($timezone);
        } catch (\Exception $e) {
            $this->dateTimeZone = new \DateTimeZone('UTC');
        }
    }

    public function format($timestamp)
    {
        $dateTime = new \DateTime();
        $dateTime->setTimestamp($timestamp);
        $dateTime->setTimezone($this->dateTimeZone);

        // not implemented: YuwWFgecSAZvVW
        $specialChars = 'MLydGQqhDEaHkKmsz';
        $specialCharsArray = str_split($specialChars);
        $specialCharsMatch = implode('|', array_map(function($char) {
            return $char . '+';
        }, $specialCharsArray));
        $quoteMatch = "'(?>(?>[^']+|'{2}+)?)'|'{2}";
        $regExp = "/($quoteMatch|$specialCharsMatch)/";

        $callback = function($matches) use ($dateTime) {
            $pattern = $matches[0];
            $length = strlen($pattern);

            if ("'" === $pattern[0]) {
                return preg_replace("/'{2}/", "'", substr($pattern, 1, -1));
            }

            switch ($pattern[0]) {
                case 'M':
                case 'L':
                    $matchLengthMap = array(
                        1   => 'n',
                        2   => 'm',
                        3   => 'M',
                        4   => 'F',
                    );

                    if (isset($matchLengthMap[$length])) {
                       return $dateTime->format($matchLengthMap[$length]);
                    } else if (5 == $length) {
                        return substr($dateTime->format('M'), 0, 1);
                    } else {
                        return str_pad($dateTime->format('m'), $length, '0', STR_PAD_LEFT);
                    }
                    break;

                case 'y':<commit_msg>[Locale] Fixed implementation of quote parsing and replacement<commit_after><?php

/*
 * This file is part of the Symfony package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Locale\Stub;

use Symfony\Component\Locale\Locale;

/**
 * Provides a stub IntlDateFormatter for the 'en' locale.
 */
class StubIntlDateFormatter
{
    /* formats */
    const NONE = -1;
    const FULL = 0;
    const LONG = 1;
    const MEDIUM = 2;
    const SHORT = 3;

    /* formats */
    const TRADITIONAL = 0;
    const GREGORIAN = 1;

    private $defaultDateFormats = array(
        self::NONE      => '',
        self::FULL      => 'EEEE, LLLL d, y',
        self::LONG      => 'LLLL d, y',
        self::MEDIUM    => 'LLL d, y',
        self::SHORT     => 'M/d/yy',
    );

    private $defaultTimeFormats = array(
        self::FULL      => 'h:mm:ss a zzzz',
        self::LONG      => 'h:mm:ss a z',
        self::MEDIUM    => 'h:mm:ss a',
        self::SHORT     => 'h:mm a',
    );

    private $datetype;
    private $timetype;
    private $pattern;

    private $dateTimeZone;

    public function __construct($locale, $datetype, $timetype, $timezone = null, $calendar = null, $pattern = null)
    {
        if ('en' != $locale) {
            throw new \InvalidArgumentException('Unsupported $locale value. Only the \'en\' locale is supported. Install the intl extension for full localization capabilities.');
        }

        $this->datetype = $datetype;
        $this->timetype = $timetype;

        $this->setPattern($pattern);

        try {
            $this->dateTimeZone = new \DateTimeZone($timezone);
        } catch (\Exception $e) {
            $this->dateTimeZone = new \DateTimeZone('UTC');
        }
    }

    public function format($timestamp)
    {
        $dateTime = new \DateTime();
        $dateTime->setTimestamp($timestamp);
        $dateTime->setTimezone($this->dateTimeZone);

        // not implemented: YuwWFgecSAZvVW
        $specialChars = 'MLydGQqhDEaHkKmsz';
        $specialCharsArray = str_split($specialChars);
        $specialCharsMatch = implode('|', array_map(function($char) {
            return $char . '+';
        }, $specialCharsArray));
        $quoteMatch = "'(?:[^']+|'')*'";
        $regExp = "/($quoteMatch|$specialCharsMatch)/";

        $callback = function($matches) use ($dateTime) {
            $pattern = $matches[0];
            $length = strlen($pattern);

            if ("'" === $pattern[0]) {
                if (preg_match("/^'+$/", $matches[0])) {
                    return str_replace("''", "'", $matches[0]);
                }
                return str_replace("''", "'", substr($matches[0], 1, -1));
            }

            switch ($pattern[0]) {
                case 'M':
                case 'L':
                    $matchLengthMap = array(
                        1   => 'n',
                        2   => 'm',
                        3   => 'M',
                        4   => 'F',
                    );

                    if (isset($matchLengthMap[$length])) {
                       return $dateTime->format($matchLengthMap[$length]);
                    } else if (5 == $length) {
                        return substr($dateTime->format('M'), 0, 1);
                    } else {
                        return str_pad($dateTime->format('m'), $length, '0', STR_PAD_LEFT);
                    }
                    break;

                case 'y':
{'fraction_non_alphanumeric': 0.14922369177688327, 'fraction_numerical': 0.006612995974698103, 'mean_word_length': 1.729305610043154, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5561409', 'n_tokens_mistral': 2117, 'n_tokens_neox': 1980, 'n_words': 485}