<commit_before><?php

use Chigi\Sublime\Exception\ScriptNotFoundException;
use Chigi\Sublime\Settings\Environment;

function __autoload($class) {
    $baseDir = dirname(dirname(__FILE__));
    $parts = explode('\\', $class);
    if ($parts[0] == 'Chigi' && $parts[1] == 'Sublime') {
        // Chigi core classes --> /Core
        array_shift($parts);
        array_shift($parts);
        require_once($baseDir . '/Core/' . implode('/', $parts) . '.php' );
    } else {
        // Other namespaces --> map file
        $tmpParts = array();
        // 常用快捷路径替换映射
        $quickPath = array(
            '${entryDir}' => $baseDir
        );
        //$map = require_once('autoload_namespaces.php');
        $map = Environment::getInstance()->getNamespacesMap();
        for ($i = count($parts) - 1; $i >= -1; $i--) {
            $tmpNamespace = implode('\\', $parts);
            if (isset($map[$tmpNamespace])) {
                // 例如'Chigi' namespace
                $scriptFile = str_replace(
                                array_keys($quickPath), array_values($quickPath), $map[$tmpNamespace]
                        )
                        . '/' . implode('/', $tmpParts) . '.php';
                if (!@include_once(iconv('utf-8', Environment::getInstance()->getFileSystemEncoding(), $scriptFile))) {
                    throw new ScriptNotFoundException($scriptFile);
                }
                return;
            } elseif (isset($map[$tmpNamespace . '\\'])) {
                // 例如'Chigi\' namespace
                $scriptFile = str_replace(
                                array_keys($quickPath), array_values($quickPath), $map[$tmpNamespace . '\\']
                        )
                        . '/' . implode('/', $tmpParts) . '.php';
                if (!@include_once(iconv('utf-8', Environment::getInstance()->getFileSystemEncoding(), $scriptFile))) // @ - to suppress warnings, 
                    throw new ScriptNotFoundException($scriptFile);
                return;
            }
            // 都不符合，则去掉末节namespace，重新检索
            try {
                array_unshift($tmpParts, $parts[$i]);
                unset($parts[$i]);
            } catch (Exception $e) {
                return;
            }
        }
    }
}

?><commit_msg>ADD autoload support for different fileSystemEncoding<commit_after><?php

use Chigi\Sublime\Exception\ScriptNotFoundException;
use Chigi\Sublime\Settings\Environment;

function __autoload($class) {
    $baseDir = dirname(dirname(__FILE__));
    $parts = explode('\\', $class);
    if ($parts[0] == 'Chigi' && $parts[1] == 'Sublime') {
        // Chigi core classes --> /Core
        array_shift($parts);
        array_shift($parts);
        require_once($baseDir . '/Core/' . implode('/', $parts) . '.php' );
    } else {
        // Other namespaces --> map file
        $tmpParts = array();
        // 常用快捷路径替换映射
        $quickPath = array(
            '${entryDir}' => $baseDir
        );
        $map = Environment::getInstance()->getNamespacesMap();
        for ($i = count($parts) - 1; $i >= -1; $i--) {
            $tmpNamespace = implode('\\', $parts);
            if (isset($map[$tmpNamespace])) {
                // 例如'Chigi' namespace
                $scriptFile = str_replace(
                                array_keys($quickPath), array_values($quickPath), $map[$tmpNamespace]
                        )
                        . '/' . implode('/', $tmpParts) . '.php';
                if (@include_once(iconv('utf-8', Environment::getInstance()->getFileSystemEncoding(), $scriptFile))){ // @ - to suppress warnings, 
                    ;
                } else if(@include_once($scriptFile)){
                    ;
                } else{
                    throw new ScriptNotFoundException($scriptFile);
                }
                return;
            } elseif (isset($map[$tmpNamespace . '\\'])) {
                // 例如'Chigi\' namespace
                $scriptFile = str_replace(
                                array_keys($quickPath), array_values($quickPath), $map[$tmpNamespace . '\\']
                        )
                        . '/' . implode('/', $tmpParts) . '.php';
                if (@include_once(iconv('utf-8', Environment::getInstance()->getFileSystemEncoding(), $scriptFile))){ // @ - to suppress warnings, 
                    ;
                } else if(@include_once($scriptFile)){
                    ;
                } else{
                    throw new ScriptNotFoundException($scriptFile);
                }
                return;
            }else{
                // 都不符合，则将末节 namespace 移至 $tmpParts 前缀拼接，重新检索
                try {
                    array_unshift($tmpParts, $parts[$i]);
                    unset($parts[$i]);
                } catch (\Chigi\Sublime\Exception\ArrayIndexOutOfBoundsException $e) {
                    $callStack = debug_backtrace();
                    $lastStack = $callStack[0];
                    $exToThrow = new \Chigi\Sublime\Exception\ClassNotFoundException($class,0,null);
                    $exToThrow->setFile($lastStack['file'])->setLine($lastStack['line']);
                    throw $exToThrow;
                    return;
                } catch (Exception $e) {
                    throw $e;
                    return;
                }
            }
        }
    }
}

?>
{'fraction_non_alphanumeric': 0.15113020736035868, 'fraction_numerical': 0.0026153558752101624, 'mean_word_length': 1.5018691588785047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '4136768', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1454, 'n_words': 245}