<commit_before>/*
**  BindingJS -- View Data Binding for JavaScript <http://bindingjs.com>
**  Copyright (c) 2014 <NAME> <http://engelschall.com>
**
**  This Source Code Form is subject to the terms of the Mozilla Public
**  License, v. 2.0. If a copy of the MPL was not distributed with this
**  file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

/*  create namespace  */
_api.dom = {};

/*  convert an XML string into a DOM document  */
_api.dom.xml2doc = function (xml) {
    var doc;

    /*  attempt 1: the portable jQuery way  */
    if (typeof $.parseXML === "function")
        doc = $.parseXML(xml);

    /*  attempt 2: the modern W3C way  */
    else if (typeof window.DOMParser !== "undefined") {
        var parser = new DOMParser();
        doc = parser.parseFromString(txt, "text/xml");
    }

    /*  attempt 3: the ancient Microsoft way  */
    else if (typeof window.ActiveXObject !== "undefined") {
        doc = new window.ActiveXObject("Microsoft.XMLDOM");
        doc.async = false;
        doc.loadXML(txt);
    }

    /*  else we have to give up...  */
    else 
        throw new Error("no XML parser found");

    return doc;
};

/*  convert a HTML string into a DOM fragment  */
_api.dom.html2dom = function (html) {
    /*  the necessary (= valid) inner wrapper elements  */
    var wrapMap = {
        option:   [ 1, "<select multiple='multiple'>", "</select>" ],
        legend:   [ 1, "<fieldset>", "</fieldset>" ],
        area:     [ 1, "<map>", "</map>" ],
        param:    [ 1, "<object>", "</object>" ],
        thead:    [ 1, "<table>", "</table>" ],
        tr:       [ 2, "<table><tbody>", "</tbody></table>" ],
        col:      [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
        td:       [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
        body:     [ 0, "", "" ],
        _default: [ 1, "<div>", "</div>" ]
    };
    wrapMap.optgroup = wrapMap.option;
    wrapMap.tbody    = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
    wrapMap.th       = wrapMap.td;

    /*  create an outer wrapper element  */
    var element = document.createElement("div");
    var match = /<\s*\w.*?>/g.exec(html);
    if (match != null) {
        /*  regular HTML element  */
        var tag = match[0].replace(/</g, "").replace(/>/g, "").split(" ")[0];
        var map = wrapMap[tag] || wrapMap._default;
        var element;
        html = map[1] + html + map[2];
        element.innerHTML = html;
        var j = map[0] + 1;
        while (j--)
            element = element.lastChild;<commit_msg>fix bugs and make ESLint happy again<commit_after>/*
**  BindingJS -- View Data Binding for JavaScript <http://bindingjs.com>
**  Copyright (c) 2014 <NAME> <http://engelschall.com>
**
**  This Source Code Form is subject to the terms of the Mozilla Public
**  License, v. 2.0. If a copy of the MPL was not distributed with this
**  file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

/*  create namespace  */
_api.dom = {};

/*  convert an XML string into a DOM document  */
_api.dom.xml2doc = function (xml) {
    var doc;
    /* global $: true */
    /* global window: true */
    /* global document: true */

    /*  attempt 1: the portable jQuery way  */
    if (typeof $.parseXML === "function")
        doc = $.parseXML(xml);

    /*  attempt 2: the modern W3C way  */
    else if (typeof window.DOMParser !== "undefined") {
        var parser = new window.DOMParser();
        doc = parser.parseFromString(xml, "text/xml");
    }

    /*  attempt 3: the ancient Microsoft way  */
    else if (typeof window.ActiveXObject !== "undefined") {
        doc = new window.ActiveXObject("Microsoft.XMLDOM");
        doc.async = false;
        doc.loadXML(xml);
    }

    /*  else we have to give up...  */
    else 
        throw new Error("no XML parser found");

    return doc;
};

/*  convert a HTML string into a DOM fragment  */
_api.dom.html2dom = function (html) {
    /*  the necessary (= valid) inner wrapper elements  */
    var wrapMap = {
        option:   [ 1, "<select multiple='multiple'>", "</select>" ],
        legend:   [ 1, "<fieldset>", "</fieldset>" ],
        area:     [ 1, "<map>", "</map>" ],
        param:    [ 1, "<object>", "</object>" ],
        thead:    [ 1, "<table>", "</table>" ],
        tr:       [ 2, "<table><tbody>", "</tbody></table>" ],
        col:      [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
        td:       [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
        body:     [ 0, "", "" ],
        _default: [ 1, "<div>", "</div>" ]
    };
    wrapMap.optgroup = wrapMap.option;
    wrapMap.tbody    = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
    wrapMap.th       = wrapMap.td;

    /*  create an outer wrapper element  */
    var element = document.createElement("div");
    var match = /<\s*\w.*?>/g.exec(html);
    if (match !== null) {
        /*  regular HTML element  */
        var tag = match[0].replace(/</g, "").replace(/>/g, "").split(" ")[0];
        var map = wrapMap[tag] || wrapMap._default;
        html = map[1] + html + map[2];
        element.innerHTML = html;
        var j = map[0] + 1;
        while (j--)
            element = element.lastChild;
{'fraction_non_alphanumeric': 0.1815594763801935, 'fraction_numerical': 0.011383039271485486, 'mean_word_length': 2.2048632218844983, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '4860785', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1626, 'n_words': 481}