<commit_before>/*!
 * modify by yswang at:
 * 2014/12/31 -> 0.8.5 supported IE6,7
 * 2015/01/04 -> 0.8.6 upgrade route path parsor
 */
;(function(window) {
    var Path = {
        'version': "0.8.6",
        'map': function (path) {
            var str_path = Path._pathToString(path);
            if(Path.routes.defined.hasOwnProperty(str_path)) {
                return Path.routes.defined[str_path];
            } else {
                return new Path.core.route(path);
            }
        },
        'root': function (path) {
            Path.routes.root = path;
        },
        'rescue': function (fn) {
            Path.routes.rescue = fn;
        },
        'history': {
            'initial':{}, // Empty container for "Initial Popstate" checking variables.
            'pushState': function(state, title, path){
                if(Path.history.supported){
                    if(Path.dispatch(path)){
                        window.history.pushState(state, title, path);
                    }
                } else {
                    if(Path.history.fallback){
                        window.location.hash = "#" + path;
                    }
                }
            },
            'popState': function(event){
                var initialPop = !Path.history.initial.popped && window.location.href == Path.history.initial.URL;
                Path.history.initial.popped = true;
                if(initialPop) { 
                    return; 
                }
                
                Path.dispatch(document.location.pathname);
            },
            'listen': function(fallback){
                Path.history.supported = !!(window.history && window.history.pushState);
                Path.history.fallback  = fallback;

                if(Path.history.supported){
                    Path.history.initial.popped = ('state' in window.history);
                    Path.history.initial.URL = window.location.href;
                    window.onpopstate = Path.history.popState;
                } else {
                    if(Path.history.fallback){
                        for(route in Path.routes.defined){
                            if(route.charAt(0) != "#"){
                              Path.routes.defined["#"+route] = Path.routes.defined[route];
                              Path.routes.defined["#"+route].path = "#"+route;
                            }
                        }
                        Path.listen();
                    }
                }
            }
        },
        'match': function (path, parameterize) {
            var route = null;
            for (var _dpath in Path.routes.defined) {
                route = Path.routes.defined[_dpath];
                if(route && route.match(path, parameterize)) {
                    return route;
                } 
            }
            return null;
        },
        'dispatch': function (passed_route) {
            var previous_route, matched_route;
            if (Path.routes.current !== passed_route) {
                Path.routes.previous = Path.routes.current;
                Path.routes.current = passed_route;

                matched_route = Path.match(passed_route, true);

                if (Path.routes.previous) {
                    previous_route = Path.match(Path.routes.previous);
                    if (previous_route !== null && typeof previous_route.do_exit === 'function') {
                        previous_route.do_exit();
                    }
                }

                if (matched_route !== null) {
                    matched_route.run();
                    return true;
                } else {
                    if (Path.routes.rescue !== null) {
                        Path.routes.rescue();
                    }
                }
            }
        },
        'listen': function () {
            // yswang add to hack legacy IE(6,7)
            Path._hackLegacyIE();

            var fn = function() {Path.dispatch(window.location.hash);};

            if(window.location.hash === "") {
                if (Path.routes.root !== null) {
                    window.location.hash = Path.routes.root;
                }
            }

            // The 'document.documentMode' checks below ensure that PathJS fires the right events
            // even in IE "Quirks Mode".
            if ("onhashchange" in window && (!document.documentMode || document.documentMode >= 8)) {
                window.onhashchange = fn;
            } else {
                setInterval(fn, 50);
            }

            if(window.location.hash !== "") {
                Path.dispatch(window.location.hash);
            }
        },
        'core': {
            'route': function (path) {
                this.path = Path._pathToString(path);
                // yswang
                this.pathKeys = [];
                this.pathRegExp = Path._pathRegExp(path, this.pathKeys, false, false);

                this.action = null;
                this.do_enter = [];
                this.do_exit = null;
                this.params = {};

                Path.routes.defined[Path._pathToString(path)] = this;
            }
        },
        'routes': {
            'current': null,
            'root': null,
            'rescue': null,
            'previous': null,
            'defined': {}
        },

        // yswang add to support complex path route
        '_pathToString': function(path) {
            if(Object.prototype.toString.call(path) === '[object Array]') {
                return '[' + path.join(',') + ']';
            }
             
            return path.toString();
        },
        '_pathRegExp': function(path, keys, sensitive, strict) {
            if (Object.prototype.toString.call(path) === '[object RegExp]') {
                return path;
            } 

            if (Object.prototype.toString.call(path) === '[object Array]') {
                path = '(' + path.join('|') + ')';
            }
            
            var _keys = [];
            path = path
                .concat(strict ? '' : '/?')
                // -- comment this to support path eg: /user/(\\d+)
                //.replace(/\/\(/g, '(?:/')
                .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?(\*)?/g, function(_, slash, format, key, capture, optional, star){
                  
									_keys.push({'name': key, 'optional': !! optional});

                  slash = slash || '';
                 
                  return ''
                        + (optional ? '' : slash)
                        + '(?:'
                        + (optional ? slash : '')
                        + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')'
                        + (optional || '')
                        + (star ? '(/*)?' : '');
                })
                .replace(/([\/.])/g, '\\$1')
                .replace(/\*/g, '(.*)');

            // ----- important：reset index position of saved keys -----
            if(Object.prototype.toString.call(keys) === '[object Array]' && _keys.length > 0) {
                var stack = [], group = [], paramIndexs = [];
                for(var i = 0, len = path.length; i < len; ++i) {
                    var c = path.charAt(i), 
                        _unescaped = path.charAt(i-1) !== '\\';
                    <commit_msg>Commit path.js version 0.9<commit_after>/*!
 * Modified by yswang(<EMAIL>) at:
 * 2014/12/31 -> 0.8.5 Supported legacy IE(6,7).
 * 2015/01/04 -> 0.8.6 Upgrade route path parser.
 * 2015/01/16 -> 0.9 Use new route path parser, now it's powerful!
 * All supported route rules:
 * 		/users                 // Static rule: Path.map('/users')
 * 		/users/:id             // Named route parameter: Path.map('/users/:id') 
 *							   // --> this.params['id']
 * 		/users/:id(\\d+)       // Parameter muse be digits: Path.map('/users/:id(\\d+)')
 *							   // --> this.params['id']
 * 		/users/:id?            // Parameter is optional: Path.map('/users/:id?') 
 *							   // --> this.params['id'] || 'undefined'
 * 		/users/:id/:action     // Path.map('/users/:id/:action')
 *							   // --> this.params['id'], this.params['action']
 * 		/users/(\\d+)          // Regexp route parameter: Path.map('/users/(\\d+)')
 *							   // --> this.params[0]
 * 		/users/(\\d+)/(\\w+)   // Path.map('/users/(\\d+)/(\\w+)')
 *							   // --> this.params[0], this.params[1]
 * 		/users/:id/(\\w+)      // Named parameter and regexp parameter mixed use: Path.map('/users/:id/(\\w+)')
 *							   // --> this.params['id'], this.params[0]
 * 		/users/*               // Wildcard parameter: Path.map('/users/*') 
 *							   // --> this.params[0] || 'undefined'
 * 		['/A', '/B', '/C']	   // Array multi route, can matched any one given: Path.map(['/A', '/B', '/C'])
 *		/^#\/comments\/(\d+)$/ // Regexp route: Path.map(/^#\/comments\/(\d+)$/)
 * 
 * Other:
 * 		/users_:id_:action	  			   // /users_2_edit
 * 		/get.:id..comments\\?p=:page(\\d+) // get.1202..comments?page=1
 * 		/... as define yourself...					  
 */
;(function(window) {
    var Path = {
        'version': "0.9",
        'map': function (path) {
            var str_path = Path._pathToString(path);
            if(Path.routes.defined.hasOwnProperty(str_path)) {
                return Path.routes.defined[str_path];
            } else {
                return new Path.core.route(path);
            }
        },
        'root': function (path) {
            Path.routes.root = path;
        },
        'rescue': function (fn) {
            Path.routes.rescue = fn;
        },
        'history': {
            'initial':{}, // Empty container for "Initial Popstate" checking variables.
            'pushState': function(state, title, path){
                if(Path.history.supported){
                    if(Path.dispatch(path)){
                        window.history.pushState(state, title, path);
                    }
                } else {
                    if(Path.history.fallback){
                        window.location.hash = "#" + path;
                    }
                }
            },
            'popState': function(event){
                var initialPop = !Path.history.initial.popped && window.location.href == Path.history.initial.URL;
                Path.history.initial.popped = true;
                if(initialPop) { 
                    return; 
                }
                
                Path.dispatch(document.location.pathname);
            },
            'listen': function(fallback){
                Path.history.supported = !!(window.history && window.history.pushState);
                Path.history.fallback  = fallback;

                if(Path.history.supported){
                    Path.history.initial.popped = ('state' in window.history);
                    Path.history.initial.URL = window.location.href;
                    window.onpopstate = Path.history.popState;
                } else {
                    if(Path.history.fallback){
                        for(route in Path.routes.defined){
                            if(route.charAt(0) != "#"){
                              Path.routes.defined["#"+route] = Path.routes.defined[route];
                              Path.routes.defined["#"+route].path = "#"+route;
                            }
                        }
                        Path.listen();
                    }
                }
            }
        },
        'match': function (path, parameterize) {
            var route = null;
            for (var _dpath in Path.routes.defined) {
                route = Path.routes.defined[_dpath];
                if(route && route.match(path, parameterize)) {
                    return route;
                } 
            }
            return null;
        },
        'dispatch': function (passed_route) {
            var previous_route, matched_route;
            if (Path.routes.current !== passed_route) {
                Path.routes.previous = Path.routes.current;
                Path.routes.current = passed_route;

                matched_route = Path.match(passed_route, true);

                if (Path.routes.previous) {
                    previous_route = Path.match(Path.routes.previous);
                    if (previous_route !== null && typeof previous_route.do_exit === 'function') {
                        previous_route.do_exit();
                    }
                }

                if (matched_route !== null) {
                    matched_route.run();
                    return true;
                } else {
                    if (Path.routes.rescue !== null) {
                        Path.routes.rescue();
                    }
                }
            }
        },
        'listen': function () {
            // yswang add to hack legacy IE(6,7)
            Path._hackLegacyIE();

            var fn = function() {Path.dispatch(window.location.hash);};

            if(window.location.hash === "") {
                if (Path.routes.root !== null) {
                    window.location.hash = Path.routes.root;
                }
            }

            // The 'document.documentMode' checks below ensure that PathJS fires the right events
            // even in IE "Quirks Mode".
            if ("onhashchange" in window && (!document.documentMode || document.documentMode >= 8)) {
                window.onhashchange = fn;
            } else {
                setInterval(fn, 50);
            }

            if(window.location.hash !== "") {
                Path.dispatch(window.location.hash);
            }
        },
        'core': {
            'route': function (path) {
                this.path = Path._pathToString(path);
                // yswang
                this.pathKeys = [];
                this.pathRegExp = Path._pathRegExp(path, this.pathKeys, false, false);

                this.action = null;
                this.do_enter = [];
                this.do_exit = null;
                this.params = {};

                Path.routes.defined[Path._pathToString(path)] = this;
            }
        },
        'routes': {
            'current': null,
            'root': null,
            'rescue': null,
            'previous': null,
            'defined': {}
        },

        // yswang add to support complex path route
        '_pathToString': function(path) {
            if(Object.prototype.toString.call(path) === '[object Array]') {
                return '[' + path.join(',') + ']';
            }
             
            return path.toString();
        },
        '_pathRegExp': function(path, keys, sensitive, strict) {
            if (Object.prototype.toString.call(path) === '[object RegExp]') {
                return path;
            } 

            if (Object.prototype.toString.call(path) === '[object Array]') {
                path = '(' + path.join('|') + ')';
            }
            
            var _keys = [];
            path = path
                .concat(strict ? '' : '/?')
                // -- comment this to support path eg: /user/(\\d+)
                //.replace(/\/\(/g, '(?:/')
                .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?(\*)?/g, function(_, slash, format, key, capture, optional, star) {
                  
		  _keys.push({'name': key, 'optional': !! optional});

                  slash = slash || '';
                 
                  return ''
                        + (optional ? '' : slash)
                        + '(?:'
                        + (optional ? slash : '')
                        + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')'
                        + (optional || '')
                        + (star ? '(/*)?' : '');
                })
                .replace(/([\/.])/g, '\\$1')
                .replace(/\*/g, '(.*)');

            // ----- important：reset index position of saved keys -----
            if(Object.prototype.toString.call(keys) === '[object Array]' && _keys.length > 0) {
                var stack = [], group = [], paramIndexs = [];
                for(var i = 0, len = path.length; i < len; ++i) {
                    var c = path.charAt(i), 
                        _unescaped = path.charAt(i-1) !== '\\';
                    
{'fraction_non_alphanumeric': 0.15543945912722804, 'fraction_numerical': 0.005900430239704979, 'mean_word_length': 1.177013647310677, 'pattern_counts': {'":': 0, '<': 6, '<?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': '2686140', 'n_tokens_mistral': 4585, 'n_tokens_neox': 4267, 'n_words': 787}