<commit_before><?php

require_once 'Template.php';

class Yokaze_Parser extends Yokaze_Template
{
    private $tagOpened = false;
    private $attrOpend = false;
    private $behaviors = array('b' => 'nl2br',
                               'n' => 'number_format',
                               'u' => 'urlencode');
    private $plains = array('h', 'a');
    private $tagStack = array();
    public function __construct($templateDir = null, $cacheDir = null)
    {
        parent::__construct($templateDir, $cacheDir);
    }

    public function addBehavior($char, $callback, $isPlain = false)
    {
        $this->behaviors[$char] = $callback;
        if ($isPlain)
            $this->plains[] = $char;
    }
    private function parse($buf)
    {
        $length = strlen($buf);
        $ret = '';
        for ($i = 0; $i < $length;){
            $char = $buf[$i];

            if ($char === '<'){
                list($parsed, $len) = $this->parseTag(substr($buf, $i));
            }else if ($char === '{'){
                list($parsed, $len) = $this->parseVal(substr($buf, $i));
            }else{
                $parsed = $char;
                $len = 1;
            }
            $ret .= $parsed;
            $i += $len;
        }
        return $ret;
    }

    private function parseAttr($tagName, $close, $buf)
    {
        if (!preg_match("/^$close([^$close]*)$close/", $buf, $matches))
            return array($buf[0], 1);

        $val = $matches[1];
        $length = strlen($val);

        $ret = '';
        $append = null;
        $loop = '/^loop:([[:alnum:].]+):([[:alnum:]_]+)(:[[:alnum:]]+)?/';
        $if = '/^if(el)?:([[:alnum:].<>=\(\)$_-]+)/';
        for ($i = 0; $i < $length;){
            $char = $val[$i];

            $sub = substr($val, $i);
            if (!$append && preg_match($loop, $sub, $m)){

                $ite = str_replace('.', '->', $m[1]);
                if (isset($m[3])){
                    $v = ltrim($m[3], ':');
                    $append = "<?php foreach(\$$ite as \$$m[2]=>\$$v): ?> ";
                }else{
                    $append = "<?php foreach(\$$ite as \$$m[2]): ?> ";
                }<commit_msg>add exclamation character to if feature.<commit_after><?php

require_once 'Template.php';

class Yokaze_Parser extends Yokaze_Template
{
    private $tagOpened = false;
    private $attrOpend = false;
    private $behaviors = array('b' => 'nl2br',
                               'n' => 'number_format',
                               'u' => 'urlencode');
    private $plains = array('h', 'a');
    private $tagStack = array();
    public function __construct($templateDir = null, $cacheDir = null)
    {
        parent::__construct($templateDir, $cacheDir);
    }

    public function addBehavior($char, $callback, $isPlain = false)
    {
        $this->behaviors[$char] = $callback;
        if ($isPlain)
            $this->plains[] = $char;
    }
    private function parse($buf)
    {
        $length = strlen($buf);
        $ret = '';
        for ($i = 0; $i < $length;){
            $char = $buf[$i];

            if ($char === '<'){
                list($parsed, $len) = $this->parseTag(substr($buf, $i));
            }else if ($char === '{'){
                list($parsed, $len) = $this->parseVal(substr($buf, $i));
            }else{
                $parsed = $char;
                $len = 1;
            }
            $ret .= $parsed;
            $i += $len;
        }
        return $ret;
    }

    private function parseAttr($tagName, $close, $buf)
    {
        if (!preg_match("/^$close([^$close]*)$close/", $buf, $matches))
            return array($buf[0], 1);

        $val = $matches[1];
        $length = strlen($val);

        $ret = '';
        $append = null;
        $loop = '/^loop:([[:alnum:].]+):([[:alnum:]_]+)(:[[:alnum:]]+)?/';
        $if = '/^if(el)?:([[:alnum:].<>=\(\)$_!-]+)/';
        for ($i = 0; $i < $length;){
            $char = $val[$i];

            $sub = substr($val, $i);
            if (!$append && preg_match($loop, $sub, $m)){

                $ite = str_replace('.', '->', $m[1]);
                if (isset($m[3])){
                    $v = ltrim($m[3], ':');
                    $append = "<?php foreach(\$$ite as \$$m[2]=>\$$v): ?> ";
                }else{
                    $append = "<?php foreach(\$$ite as \$$m[2]): ?> ";
                }
{'fraction_non_alphanumeric': 0.21438387540082454, 'fraction_numerical': 0.005497022446174988, 'mean_word_length': 1.648271679805943, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '553944', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1395, 'n_words': 287}