<commit_before>/* ************************************************************************

    License: MIT Licence

    Description:
        Debugger functionnality including nested group system like console
        usually provide

************************************************************************ */

(function (win, a) {
    'use strict';

    /**
     * Test if browser support or not the CSS in console.
     *
     * @method testBrowserSupportCSS
     * @private
     *
     * @param browser {String}              The browser name (firefox, ...)
     * @return                              True it does support, false it
     *                                      does not support...
    */
    function testBrowserSupportCSS(browser) {
        // TODO: Maybe too simple test...
        // IE does not support it...
        return (browser === 'opera' || browser === 'firefox' ||
                browser === 'chrome');
    }

    /**
     * We can have only one element printing at a time.
     * This variable is a kind of lock for this.
    */
    var concurrentConsoleAccess = false,
        browser = a.environment.get('browser'),
        cssSupport = testBrowserSupportCSS(browser);

    /**
     * Regex used for markdown parsing.
     *
     * Strongly inspired by: https://github.com/adamschwartz/log
     * All credit goes to him !!!!!
    */
    var formats = [{
        regex: /\*\*([^\*]+)\*\*/,
        replacer: function(m, p1) {
            return cssSupport ? '%c' + p1 + '%c' : p1;
        },
        styles: function() {
            return ['font-weight: bold', ''];
         }
    }, {
        regex: /\_\_([^\_]+)\_\_/,
        replacer: function(m, p1) {
            return cssSupport ? '%c' + p1 + '%c' : p1;
        },
        styles: function() {
            return ['font-style: italic', ''];
        }
    }, {
        regex: /\`\`\`([^\`]+)\`\`\`/,
        replacer: function(m, p1) {
            return cssSupport ? '%c' + p1 + '%c' : p1;
        },
        styles: function() {
            return ['background: rgb(255, 255, 219); padding: 1px 5px; border: 1px solid rgba(0, 0, 0, 0.1)', ''];
        }
    }, {
        regex: /\[c\=(?:\"|\')?((?:(?!(?:\"|\')\]).)*)(?:\"|\')?\]((?:(?!\[c\]).)*)\[c\]/,
        replacer: function(m, p1, p2) {
            return cssSupport ? '%c' + p2 + '%c' : p2;
        },
        styles: function(match) {
            return [match[1], ''];
        }
    }];


    /**
     * Detect if there is some markdown to parse...
     * @see https://github.com/adamschwartz/log
     *
     * @method hasMarkdownMatches
    */
    function hasMarkdownMatches(str) {
        var has = false;

        for (var i = 0, l = formats.length; i < l && !has; ++i) {
            if (formats[i].regex.test(str)) {
                has = true;
            }
        }

        return has;
    };

    /**
     * Get ordered matches for every markdown existing.
     * @see https://github.com/adamschwartz/log
     *
     * @method getOrderedMarkdownMatches
     * @private
     *
     * @param str {String}                  The string to markdown
     * @return {Array}                      The matches found
    */
    function getOrderedMarkdownMatches(str) {
        var matches = [];

        // Testing
        a.each(formats, function(format) {
            var match = str.match(format.regex);
            if (match) {
                matches.push({
                    format: format,
                    match: match
                });
            }
        });


        // Sorting
        matches = a.sortBy(matches, function(entry) {
            return entry.match.index;
        });

        return matches;
    }

    /**
     * Parse the value and replace it by correct CSS rules.
     *
     * @method markdown
     * @private
     *
     * @param str {String}                  The value to modify it's markdown
     * @return {Array}                      The value with CSS replaced as an
    */
    function markdown(str) {
        if (!a.isString(str)) {
            return [str];
        }

        var first, matches, styles;
        styles = [];
        while (hasMarkdownMatches(str)) {
            matches = getOrderedMarkdownMatches(str);
            first = matches[0];
            str = str.replace(first.format.regex, first.format.replacer);
            styles = styles.concat(first.format.styles(first.match));
        }

        if (cssSupport) {
            return [str].concat(styles);
        } else {
            return [str];
        }
    }

    /**
     * Test the minimum type for a given log.
     * Like we can test the 'log' can be printed or not according
     * to current verbose parameter configured in a.environment.
     *
     * @method testMinimumType
     * @private
     *
     * @param currentType                   The level to test
     * @return                              True the minimum level is OK for
     *                                      current test, false the minimum
     *                                      level is too high for current test.<commit_msg>Correct potential group missing on console.<commit_after>/* ************************************************************************

    License: MIT Licence

    Description:
        Debugger functionnality including nested group system like console
        usually provide

************************************************************************ */

(function (win, a) {
    'use strict';

    /**
     * Test if browser support or not the CSS in console.
     *
     * @method testBrowserSupportCSS
     * @private
     *
     * @param browser {String}              The browser name (firefox, ...)
     * @return                              True it does support, false it
     *                                      does not support...
    */
    function testBrowserSupportCSS(browser) {
        // TODO: Maybe too simple test...
        // IE does not support it...
        return (browser === 'opera' || browser === 'firefox' ||
                browser === 'chrome');
    }

    /**
     * We can have only one element printing at a time.
     * This variable is a kind of lock for this.
    */
    var concurrentConsoleAccess = false,
        browser = a.environment.get('browser'),
        cssSupport = testBrowserSupportCSS(browser),
        // Used only when system does not support groupCollapsed/group system
        // in console
        indent = 0;

    if (win.console) {
        if (!a.isFunction(win.console.groupCollapsed)) {
            win.console.groupCollapsed = function() {
                win.console.log(arguments);
                indent += 1;
            }
        }

        if (!a.isFunction(win.console.group)) {
            win.console.group = function() {
                win.console.log(arguments);
                indent += 1;
            }
        }

        if (!a.isFunction(win.console.groupEnd)) {
            win.console.groupEnd = function() {
                indent -= 1;
            }
        }
    }

    /**
     * Regex used for markdown parsing.
     *
     * Strongly inspired by: https://github.com/adamschwartz/log
     * All credit goes to him !!!!!
    */
    var formats = [{
        regex: /\*\*([^\*]+)\*\*/,
        replacer: function(m, p1) {
            return cssSupport ? '%c' + p1 + '%c' : p1;
        },
        styles: function() {
            return ['font-weight: bold', ''];
         }
    }, {
        regex: /\_\_([^\_]+)\_\_/,
        replacer: function(m, p1) {
            return cssSupport ? '%c' + p1 + '%c' : p1;
        },
        styles: function() {
            return ['font-style: italic', ''];
        }
    }, {
        regex: /\`\`\`([^\`]+)\`\`\`/,
        replacer: function(m, p1) {
            return cssSupport ? '%c' + p1 + '%c' : p1;
        },
        styles: function() {
            return ['background: rgb(255, 255, 219); padding: 1px 5px; border: 1px solid rgba(0, 0, 0, 0.1)', ''];
        }
    }, {
        regex: /\[c\=(?:\"|\')?((?:(?!(?:\"|\')\]).)*)(?:\"|\')?\]((?:(?!\[c\]).)*)\[c\]/,
        replacer: function(m, p1, p2) {
            return cssSupport ? '%c' + p2 + '%c' : p2;
        },
        styles: function(match) {
            return [match[1], ''];
        }
    }];


    /**
     * Detect if there is some markdown to parse...
     * @see https://github.com/adamschwartz/log
     *
     * @method hasMarkdownMatches
    */
    function hasMarkdownMatches(str) {
        var has = false;

        for (var i = 0, l = formats.length; i < l && !has; ++i) {
            if (formats[i].regex.test(str)) {
                has = true;
            }
        }

        return has;
    };

    /**
     * Get ordered matches for every markdown existing.
     * @see https://github.com/adamschwartz/log
     *
     * @method getOrderedMarkdownMatches
     * @private
     *
     * @param str {String}                  The string to markdown
     * @return {Array}                      The matches found
    */
    function getOrderedMarkdownMatches(str) {
        var matches = [];

        // Testing
        a.each(formats, function(format) {
            var match = str.match(format.regex);
            if (match) {
                matches.push({
                    format: format,
                    match: match
                });
            }
        });


        // Sorting
        matches = a.sortBy(matches, function(entry) {
            return entry.match.index;
        });

        return matches;
    }

    /**
     * Parse the value and replace it by correct CSS rules.
     *
     * @method markdown
     * @private
     *
     * @param str {String}                  The value to modify it's markdown
     * @return {Array}                      The value with CSS replaced as an
    */
    function markdown(str) {
        if (!a.isString(str)) {
            return [str];
        }

        var first, matches, styles;
        styles = [];
        while (hasMarkdownMatches(str)) {
            matches = getOrderedMarkdownMatches(str);
            first = matches[0];
            str = str.replace(first.format.regex, first.format.replacer);
            styles = styles.concat(first.format.styles(first.match));
        }

        // Correcting the indent if the group system
        // does not exist
        if (indent > 0) {
            for (var i = 0, l = indent.length; i < l; ++i) {
                str = '  ' + str;
            }
        }

        if (cssSupport) {
            return [str].concat(styles);
        } else {
            return [str];
        }
    }

    /**
     * Test the minimum type for a given log.
     * Like we can test the 'log' can be printed or not according
     * to current verbose parameter configured in a.environment.
     *
     * @method testMinimumType
     * @private
     *
     * @param currentType                   The level to test
     * @return                              True the minimum level is OK for
     *                                      current test, false the minimum
     *                                      level is too high for current test.
{'fraction_non_alphanumeric': 0.15731345963904103, 'fraction_numerical': 0.006464936697494837, 'mean_word_length': 1.4473742034717645, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3593434', 'n_tokens_mistral': 3178, 'n_tokens_neox': 3013, 'n_words': 827}