<commit_before><?php

/**
 * 9 April 2008. version 1.1
 *
 * This is the php version of the Dean Edwards JavaScript's Packer,
 * Based on :
 *
 * ParseMaster, version 1.0.2 (2005-08-19) Copyright 2005, Dean Edwards
 * a multi-pattern parser.
 * KNOWN BUG: erroneous behavior when using escapeChar with a replacement
 * value that is a function
 *
 * packer, version 2.0.2 (2005-08-19) Copyright 2004-2005, Dean Edwards
 *
 * License: http://creativecommons.org/licenses/LGPL/2.1/
 *
 * Ported to PHP by Nicolas Martin.
 *
 * ----------------------------------------------------------------------
 * changelog:
 * 1.1 : correct a bug, '\0' packed then unpacked becomes '\'.
 * ----------------------------------------------------------------------
 *
 * Changes:
 * 2014-08-28: grkalik: change class for composer support. no functionality change.
 *
 */

namespace GK;

/**
 * Class JavascriptPacker
 *
 * @package GK
 * @author  <NAME>
 * @author  <NAME> <<EMAIL>>
 */
class JavascriptPacker
{
    // constants
    const IGNORE = '$1';

    // validate parameters
    private $_script = '';
    private $_encoding = 62;
    private $_fastDecode = true;
    private $_specialChars = false;

    private $LITERAL_ENCODING = array(
        'None'       => 0,
        'Numeric'    => 10,
        'Normal'     => 62,
        'High ASCII' => 95
    );

    public function __construct($_script, $_encoding = 62, $_fastDecode = true, $_specialChars = false)
    {
        $this->_script = $_script . "\n";
        if (array_key_exists($_encoding, $this->LITERAL_ENCODING)) {
            $_encoding = $this->LITERAL_ENCODING[$_encoding];
        }
        $this->_encoding = min((int) $_encoding, 95);
        $this->_fastDecode = $_fastDecode;
        $this->_specialChars = $_specialChars;
    }

    public function pack()
    {
        $this->_addParser('_basicCompression');
        if ($this->_specialChars) {
            $this->_addParser('_encodeSpecialChars');
        }
        if ($this->_encoding) {
            $this->_addParser('_encodeKeywords');
        }

        // go!
        return $this->_pack($this->_script);
    }

    // apply all parsing routines
    private function _pack($script)
    {
        for ($i = 0; isset($this->_parsers[$i]); $i++) {
            $script = call_user_func(array(&$this, $this->_parsers[$i]), $script);<commit_msg>fix logic<commit_after><?php

/**
 * 9 April 2008. version 1.1
 *
 * This is the php version of the Dean Edwards JavaScript's Packer,
 * Based on :
 *
 * ParseMaster, version 1.0.2 (2005-08-19) Copyright 2005, Dean Edwards
 * a multi-pattern parser.
 * KNOWN BUG: erroneous behavior when using escapeChar with a replacement
 * value that is a function
 *
 * packer, version 2.0.2 (2005-08-19) Copyright 2004-2005, Dean Edwards
 *
 * License: http://creativecommons.org/licenses/LGPL/2.1/
 *
 * Ported to PHP by <NAME>.
 *
 * ----------------------------------------------------------------------
 * changelog:
 * 1.1 : correct a bug, '\0' packed then unpacked becomes '\'.
 * ----------------------------------------------------------------------
 *
 * Changes:
 * 2014-08-28: grkalik: change class for composer support. no functionality change.
 *
 */

namespace GK;

/**
 * Class JavascriptPacker
 *
 * @package GK
 * @author  <NAME>
 * @author  <NAME> <<EMAIL>>
 */
class JavascriptPacker
{
    // constants
    const IGNORE = '$1';

    // validate parameters
    private $_script = '';
    private $_encoding = 62;
    private $_fastDecode = true;
    private $_specialChars = false;

    private $LITERAL_ENCODING = array(
        'None'       => 0,
        'Numeric'    => 10,
        'Normal'     => 62,
        'High ASCII' => 95
    );

    public function __construct($_script, $_encoding = 'Normal', $_fastDecode = true, $_specialChars = false)
    {
        $this->_script = $_script . "\n";
        if (array_key_exists($_encoding, $this->LITERAL_ENCODING)) {
            $_encoding = $this->LITERAL_ENCODING[$_encoding];
        }
        $this->_encoding = min((int) $_encoding, 95);
        $this->_fastDecode = $_fastDecode;
        $this->_specialChars = $_specialChars;
    }

    public function pack()
    {
        if ($this->_encoding > 0) {
            $this->_addParser('_basicCompression');
        }

        if ($this->_specialChars) {
            $this->_addParser('_encodeSpecialChars');
        }

        if ($this->_encoding) {
            $this->_addParser('_encodeKeywords');
        }

        return $this->_pack($this->_script).';';
    }

    // apply all parsing routines
    private function _pack($script)
    {
        for ($i = 0; isset($this->_parsers[$i]); $i++) {
            $script = call_user_func(array(&$this, $this->_parsers[$i]), $script);
{'fraction_non_alphanumeric': 0.19671786240269304, 'fraction_numerical': 0.028823900694298337, 'mean_word_length': 2.037699680511182, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 52, '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': '779309', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1369, 'n_words': 357}