<commit_before>(function() {

    var trimLeft = /^\s+/,
        trimRight = /\s+$/;
    function trim(str) {
        return str.replace(trimLeft, '').replace(trimRight, '');
    }

    function getFirstChild(element) {
        return element.firstChild;
    }
    function getFirstGrandChild(element) {
        return element.firstChild.firstChild;
    }
    function getSecondGrandChild(element) {
        return element.firstChild.firstChild.nextSibling;
    }
    function getFirstGreatGrandChild(element) {
        return element.firstChild.firstChild.firstChild;
    }
    function getFirstGreatGreatGrandChild(element) {
        return element.firstChild.firstChild.firstChild.firstChild;
    }

    function Parser(before, after, getFirstResult) {
        if (before) {
            this.before = before;
        }
        if (after) {
            this.after = after;
        }
        if (getFirstResult) {
            this.getFirstResult = getFirstResult;
        }
    }
    Parser.prototype = {
        before: '',
        after: '',
        parse: function(html, doc) {
            var parser = doc.createElement('div');
            var fragment = doc.createDocumentFragment();
            parser.innerHTML = this.before + html + this.after;
            var node = this.getFirstResult(parser);
            var nextNode;
            while (node) {
                nextNode = node.nextSibling;
                fragment.appendChild(node);
                node = nextNode;
            }
            return fragment;
        },
        getFirstResult: getFirstChild
    };

    var parsers = {
        'td': new Parser('<table><tbody><tr>', '</tr></tbody></table>', getFirstGreatGreatGrandChild),
        'tr': new Parser('<table><tbody>', '</tbody></table>', getFirstGreatGrandChild),
        'tbody': new Parser('<table>', '</table>', getFirstGrandChild),
        'col': new Parser('<table><colgroup>', '</colgroup></table>', getFirstGreatGrandChild),
        // Without the option in the next line, the parsed option will always be selected.
        'option': new Parser('<select><option>a</option>', '</select>', getSecondGrandChild)
    };
    parsers.th = parsers.td;
    parsers.thead = parsers.tbody;
    parsers.tfoot = parsers.tbody;
    parsers.caption = parsers.tbody;
    parsers.colgroup = parsers.tbody;

    var tagRegExp = /^<([a-z]+)/i; // first group must be tag name

/**

@property arbutus.parseHTML

@parameter html {string} The string of HTML to be parsed.

@parameter doc {Document} Optional document object to create the new DOM nodes.

@return {DocumentFragment}

@description

The html string will be trimmed.

Returns a document fragment that has the children defined by the html string.

var fragment = arbutus.parseHTML('<p>alpha beta</p>');
document.body.appendChild(fragment);

Note that a call to this function is relatively expensive and you probably
don't want to have a loop of thousands with calls to this function.

*/
    arbutus.parseHTML = function(html, doc) {
        // IE will trim when setting innerHTML so unify for all browsers
        html = trim(html);
        var matches = html.match(tagRegExp),
            parser = (matches && parsers[matches[1].toLowerCase()]) ||
                     Parser.prototype;
        return parser.parse(html, doc || document);
    };

}());<commit_msg>more straightforward implementation with a closure<commit_after>(function() {

    var trimLeft = /^\s+/,
        trimRight = /\s+$/;
    function trim(str) {
        return str.replace(trimLeft, '').replace(trimRight, '');
    }

    function getFirstChild(element) {
        return element.firstChild;
    }
    function getFirstGrandChild(element) {
        return element.firstChild.firstChild;
    }
    function getSecondGrandChild(element) {
        return element.firstChild.firstChild.nextSibling;
    }
    function getFirstGreatGrandChild(element) {
        return element.firstChild.firstChild.firstChild;
    }
    function getFirstGreatGreatGrandChild(element) {
        return element.firstChild.firstChild.firstChild.firstChild;
    }

    function makeParser(before, after, getFirstResult) {
        return function(html, doc) {
            var parser = doc.createElement('div');
            var fragment = doc.createDocumentFragment();
            parser.innerHTML = before + html + after;
            var node = getFirstResult(parser);
            var nextNode;
            while (node) {
                nextNode = node.nextSibling;
                fragment.appendChild(node);
                node = nextNode;
            }
            return fragment;
        };
    }

    var defaultParser = makeParser('', '', getFirstChild);

    var parsers = {
        'td': makeParser('<table><tbody><tr>', '</tr></tbody></table>', getFirstGreatGreatGrandChild),
        'tr': makeParser('<table><tbody>', '</tbody></table>', getFirstGreatGrandChild),
        'tbody': makeParser('<table>', '</table>', getFirstGrandChild),
        'col': makeParser('<table><colgroup>', '</colgroup></table>', getFirstGreatGrandChild),
        // Without the option in the next line, the parsed option will always be selected.
        'option': makeParser('<select><option>a</option>', '</select>', getSecondGrandChild)
    };
    parsers.th = parsers.td;
    parsers.thead = parsers.tbody;
    parsers.tfoot = parsers.tbody;
    parsers.caption = parsers.tbody;
    parsers.colgroup = parsers.tbody;

    var tagRegExp = /^<([a-z]+)/i; // first group must be tag name

/**

@property arbutus.parseHTML

@parameter html {string} The string of HTML to be parsed.

@parameter doc {Document} Optional document object to create the new DOM nodes.

@return {DocumentFragment}

@description

The html string will be trimmed.

Returns a document fragment that has the children defined by the html string.

var fragment = arbutus.parseHTML('<p>alpha beta</p>');
document.body.appendChild(fragment);

Note that a call to this function is relatively expensive and you probably
don't want to have a loop of thousands with calls to this function.

*/
    arbutus.parseHTML = function(html, doc) {
        // IE will trim when setting innerHTML so unify for all browsers
        html = trim(html);
        var parser = defaultParser;
        var matches = html.match(tagRegExp);        
        if (matches) {
            var name = matches[1].toLowerCase();
            if (Object.prototype.hasOwnProperty.call(parsers, name)) {
                parser = parsers[name];
            }
        }
        return parser(html, doc || document);
    };

}());
{'fraction_non_alphanumeric': 0.11905123916679337, 'fraction_numerical': 0.0003040900106431504, 'mean_word_length': 2.5965008201202844, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 47, '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': '6226709', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1784, 'n_words': 482}