<commit_before><?php namespace Hpkns\FrontMatter;

use Symfony\Component\Yaml\Parser as Yaml;

class Parser {

    /**
     * A yaml parser instance
     *
     * @var \Symfony\Component\Yaml\Parser
     */
    protected $yaml;

    /**
     * Initialise the instance
     *
     * @param  \Symfony\Component\Yaml\Parser
     * @return void
     */
    public function __construct(Yaml $yaml = null)
    {
        $this->yaml = $yaml ?: new Yaml;
    }
    /**
     * Parse a front matter file and return an array with its content
     *
     * @param  string $fm
     * @param  array  $default
     * @return array
     */
    public function parse($fm, array $default = [], $castObject = false)
    {
        $pieces = [];
        $parsed = [];
        $regexp = '/^-{3}(?:\n|\r)(.+?)-{3}(.*)$/ms';

        if(preg_match($regexp, $fm, $pieces) && $yaml = $pieces[1])
        {
            $parsed = $this->yaml->parse($yaml, true);
            $parsed['content'] = trim($pieces[2]);
        }
        else
        {
            // If the regexp fails (i.e. if there is no front matter header present)
            // we just return an array with the content as the only key
            $parsed['content'] = $this->raw;
        }

        $parsed = $this->fillDefault($parsed, $default);

        if($castObject)<commit_msg>Bugfix<commit_after><?php namespace Hpkns\FrontMatter;

use Symfony\Component\Yaml\Parser as Yaml;

class Parser {

    /**
     * A yaml parser instance
     *
     * @var \Symfony\Component\Yaml\Parser
     */
    protected $yaml;

    /**
     * Initialise the instance
     *
     * @param  \Symfony\Component\Yaml\Parser
     * @return void
     */
    public function __construct(Yaml $yaml = null)
    {
        $this->yaml = $yaml ?: new Yaml;
    }
    /**
     * Parse a front matter file and return an array with its content
     *
     * @param  string $fm
     * @param  array  $default
     * @return array
     */
    public function parse($fm, array $default = [], $castObject = false)
    {
        $pieces = [];
        $parsed = [];
        $regexp = '/^-{3}(?:\n|\r)(.+?)-{3}(.*)$/ms';

        if(preg_match($regexp, $fm, $pieces) && $yaml = $pieces[1])
        {
            $parsed = $this->yaml->parse($yaml, true);
            $parsed['content'] = trim($pieces[2]);
        }
        else
        {
            // If the regexp fails (i.e. if there is no front matter header present)
            // we just return an array with the content as the only key
            $parsed['content'] = $fm;
        }

        $parsed = $this->fillDefault($parsed, $default);

        if($castObject)
{'fraction_non_alphanumeric': 0.15098634294385432, 'fraction_numerical': 0.0030349013657056147, 'mean_word_length': 1.835483870967742, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '6253214', 'n_tokens_mistral': 835, 'n_tokens_neox': 824, 'n_words': 211}