<commit_before><?php
/**
 * Twig::API
 * ~~~~~~~~~
 *
 * The High-Level API
 *
 * :copyright: 2008 by <NAME>.
 * :license: BSD.
 */


/**
 * Load the compiler system.
 * Call this before you access the compiler!
 */
function twig_load_compiler()
{
    if (!defined('TWIG_COMPILER_INCLUDED'))
        require TWIG_BASE . DIRECTORY_SEPARATOR . 'compiler.php';
}


/**
 * A helper function that can be used by filters to get the
 * current active template.  This use useful to access variables
 * on the template like the charset.
 */
function twig_get_current_template()
{
    return $GLOBALS['twig_current_template'];
}


/* the current template that is rendered.  This used used internally
   and is an implementation detail.  Don't tamper with that. */
$twig_current_template = NULL;


/**
 * This class wraps a template instance as returned by the compiler and
 * is usually constructed from the `Twig_Loader`.
 */
class Twig_Template
{
    private $instance;
    public $charset;
    public $loader;

    public function __construct($instance, $charset=NULL, $loader)
    {
        $this->instance = $instance;
        $this->charset = $charset;
        $this->loader = $loader;
    }

    /**
     * Render the template with the given context and return it
     * as string.
     */
    public function render($context=NULL)
    {
        ob_start();
        $this->display($context);
        return ob_get_clean();
    }

    /**
     * Works like `render()` but prints the output.
     */
    public function display($context=NULL)
    {
        global $twig_current_template;
        $old = $twig_current_template;
        $twig_current_template = $this;
        if (is_null($context))
            $context = array();
        $this->instance->render($context);
        $twig_current_template = $old;
    }
}

/**
 * Baseclass for custom loaders.
 * Subclasses have to provide a getFilename method.
 */
class Twig_BaseLoader
{
    public $cache;
    public $charset;

    public function __construct($cache=NULL, $charset=NULL)
    {
        $this->cache = $cache;
        $this->charset = $charset;
    }

    public function getTemplate($name)
    {
        $cls = $this->requireTemplate($name);
        return new Twig_Template(new $cls, $this->charset, $this);
    }

    public function getCacheFilename($name)
    {
        return $this->cache . DIRECTORY_SEPARATOR . 'twig_' . md5($name) . '.cache';
    }

    public function requireTemplate($name)
    {
        $cls = '__TwigTemplate_' . md5($name);
        if (!class_exists($cls)) {
            if (is_null($this->cache)) {
                $this->evalTemplate($name);
                return $cls;
            }
            $fn = $this->getFilename($name);
            $cache_fn = $this->getCacheFilename($name);
            if (!file_exists($cache_fn) ||
                filemtime($cache_fn) < filemtime($fn)) {
                twig_load_compiler();
                $fp = @fopen($cache_fn, 'wb');
                if (!$fp) {
                    $this->evalTemplate($name, $fn);
                    return $cls;
                }
                $compiler = new Twig_FileCompiler($fp);
                $this->compileTemplate($name, $compiler, $fn);
                fclose($fp);
            }
            include $cache_fn;
        }
        return $cls;
    }

    public function compileTemplate($name, $compiler=NULL, $fn=NULL)
    {
        twig_load_compiler();
        if (is_null($compiler)) {
            $compiler = new Twig_StringCompiler();
            $returnCode = true;
        }
        else
            $returnCode = false;
        if (is_null($fn))
            $fn = $this->getFilename($name);

        $node = twig_parse(file_get_contents($fn, $name), $name);
        $node->compile($compiler);
        if ($returnCode)
            return $compiler->getCode();
    }

    private function evalTemplate($name, $fn=NULL)
    {
        $code = $this->compileTemplate($name, NULL, $fn);
        $code = preg_replace('/echo (?!twig_get_attribute.+)"(\\\\r|\\\\n)+(\\\\t| )*";/', "", $code); # Remove blank lines
        eval('?>' . $code);
    }
}


/**
 * Helper class that loads templates.
 */
class Twig_Loader extends Twig_BaseLoader
{
    public $folder;

    public function __construct($folder, $cache=NULL, $charset=NULL)
    {
        parent::__construct($cache, $charset);<commit_msg>Adjusted Twig line-trimming regex to catch all whitespace chars<commit_after><?php
/**
 * Twig::API
 * ~~~~~~~~~
 *
 * The High-Level API
 *
 * :copyright: 2008 by <NAME>.
 * :license: BSD.
 */


/**
 * Load the compiler system.
 * Call this before you access the compiler!
 */
function twig_load_compiler()
{
    if (!defined('TWIG_COMPILER_INCLUDED'))
        require TWIG_BASE . DIRECTORY_SEPARATOR . 'compiler.php';
}


/**
 * A helper function that can be used by filters to get the
 * current active template.  This use useful to access variables
 * on the template like the charset.
 */
function twig_get_current_template()
{
    return $GLOBALS['twig_current_template'];
}


/* the current template that is rendered.  This used used internally
   and is an implementation detail.  Don't tamper with that. */
$twig_current_template = NULL;


/**
 * This class wraps a template instance as returned by the compiler and
 * is usually constructed from the `Twig_Loader`.
 */
class Twig_Template
{
    private $instance;
    public $charset;
    public $loader;

    public function __construct($instance, $charset=NULL, $loader)
    {
        $this->instance = $instance;
        $this->charset = $charset;
        $this->loader = $loader;
    }

    /**
     * Render the template with the given context and return it
     * as string.
     */
    public function render($context=NULL)
    {
        ob_start();
        $this->display($context);
        return ob_get_clean();
    }

    /**
     * Works like `render()` but prints the output.
     */
    public function display($context=NULL)
    {
        global $twig_current_template;
        $old = $twig_current_template;
        $twig_current_template = $this;
        if (is_null($context))
            $context = array();
        $this->instance->render($context);
        $twig_current_template = $old;
    }
}

/**
 * Baseclass for custom loaders.
 * Subclasses have to provide a getFilename method.
 */
class Twig_BaseLoader
{
    public $cache;
    public $charset;

    public function __construct($cache=NULL, $charset=NULL)
    {
        $this->cache = $cache;
        $this->charset = $charset;
    }

    public function getTemplate($name)
    {
        $cls = $this->requireTemplate($name);
        return new Twig_Template(new $cls, $this->charset, $this);
    }

    public function getCacheFilename($name)
    {
        return $this->cache . DIRECTORY_SEPARATOR . 'twig_' . md5($name) . '.cache';
    }

    public function requireTemplate($name)
    {
        $cls = '__TwigTemplate_' . md5($name);
        if (!class_exists($cls)) {
            if (is_null($this->cache)) {
                $this->evalTemplate($name);
                return $cls;
            }
            $fn = $this->getFilename($name);
            $cache_fn = $this->getCacheFilename($name);
            if (!file_exists($cache_fn) ||
                filemtime($cache_fn) < filemtime($fn)) {
                twig_load_compiler();
                $fp = @fopen($cache_fn, 'wb');
                if (!$fp) {
                    $this->evalTemplate($name, $fn);
                    return $cls;
                }
                $compiler = new Twig_FileCompiler($fp);
                $this->compileTemplate($name, $compiler, $fn);
                fclose($fp);
            }
            include $cache_fn;
        }
        return $cls;
    }

    public function compileTemplate($name, $compiler=NULL, $fn=NULL)
    {
        twig_load_compiler();
        if (is_null($compiler)) {
            $compiler = new Twig_StringCompiler();
            $returnCode = true;
        }
        else
            $returnCode = false;
        if (is_null($fn))
            $fn = $this->getFilename($name);

        $node = twig_parse(file_get_contents($fn, $name), $name);
        $node->compile($compiler);
        if ($returnCode)
            return $compiler->getCode();
    }

    private function evalTemplate($name, $fn=NULL)
    {
        $code = $this->compileTemplate($name, NULL, $fn);
        $code = preg_replace('/echo (?!twig_get_attribute.+)"(\\\\r|\\\\n)+(\\\\t|\\s)*";/', "", $code); # Remove blank lines
        eval('?>' . $code);
    }
}


/**
 * Helper class that loads templates.
 */
class Twig_Loader extends Twig_BaseLoader
{
    public $folder;

    public function __construct($folder, $cache=NULL, $charset=NULL)
    {
        parent::__construct($cache, $charset);
{'fraction_non_alphanumeric': 0.13741759490793362, 'fraction_numerical': 0.00136394635144351, 'mean_word_length': 2.214833759590793, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 49, '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': '3682912', 'n_tokens_mistral': 2673, 'n_tokens_neox': 2567, 'n_words': 631}