<commit_before>var EventedHandler = function(cbs) {
    //map the handlers to their callbacks
    this.writeComment = stripData(cbs.oncomment);
    this.writeDirective = stripData(cbs.onprocessinginstruction);
    this.writeText = stripData(cbs.ontext);
    this.done = cbs.onend || emptyFunction;

    //if someone wants to listen to that
    this.reset = cbs.onreset || emptyFunction;
    this.error = cbs.onerror; //if nothing was set, the error is thrown

    //functions to be called within writeTag
    this.onOpenTag = openTagCB(cbs.onopentag, cbs.onattribute);
    this.onCloseTag = cbs.onclosetag || emptyFunction;

    //privates
    this._stack = [];
};

var emptyFunction = function() {};
var stripData = function(callback) {
    if (typeof callback !== "function") return emptyFunction;
    return function(data) {
        callback(data.data);
    };
};
var openTagCB = function(openTag, attribute) {
    function open(name, attributes) {
        openTag({ name: name, attributes: attributes });
    }
    function attr(name, attributes) {
        for (var i in attributes) attribute({ name: i, value: attributes[i] });
    }
    if (openTag) {
        if (attribute)
            return function(name, attributes) {
                open(name, attributes);
                attr(null, attributes);
            };
        else return open;
    } else if (attribute) return attr;
    else return emptyFunction;
};

//HTML Tags that shouldn't contain child nodes
var emptyTags = {
    area: true,
    base: true,
    basefont: true,
    br: true,
    col: true,
    frame: true,
    hr: true,
    img: true,
    input: true,
    isindex: true,
    link: true,
    meta: true,
    param: true,
    embed: true
};

EventedHandler.prototype.writeTag = function(element) {
    var closing = element.name.charAt(0) === "/",
        name = closing ? element.name.substring(1) : element.name,
        attributes = element.attribs || {},
        empty = emptyTags[name];

    if (closing) {
        if (!empty) {
            var i = this._stack.length - 1;
            while (i !== -1 && this._stack[i--].name !== name) {}
            if ((i += 1) !== 0)
                while (i < this._stack.length)
                    this.onCloseTag(this._stack.pop().name);
        } else if (name === "br") {
            //special case for <br>s
            this.onOpenTag(name, attributes);
            this.onCloseTag(name);
        }
    } else {
        this.onOpenTag(name, attributes);
        if (empty) this.onCloseTag(name);
        else this._stack.push(element);
    }
};<commit_msg>Some steps preparing for the upcoming changes<commit_after>var EventedHandler = function(cbs) {
    //map the handlers to their callbacks
    this.writeComment = stripData(cbs.oncomment);
    this.writeDirective = stripData(cbs.onprocessinginstruction);
    this.writeText = stripData(cbs.ontext);
    this.done = cbs.onend || emptyFunction;

    //if someone wants to listen to that
    this.reset = cbs.onreset || emptyFunction;
    this.error = cbs.onerror; //if nothing was set, the error is thrown

    //functions to be called within writeTag
    this.onopentag = openTagCB(cbs.onopentag, cbs.onattribute);
    this.onclosetag = cbs.onclosetag || emptyFunction;

    //privates
    this._stack = [];
};

var emptyFunction = function() {};
var stripData = function(callback) {
    if (typeof callback !== "function") return emptyFunction;
    return function(data) {
        callback(data.data);
    };
};
var openTagCB = function(openTag, attribute) {
    function open(name, attributes) {
        openTag({ name: name, attributes: attributes });
    }
    function attr(name, attributes) {
        for (var i in attributes) attribute({ name: i, value: attributes[i] });
    }
    if (openTag) {
        if (attribute)
            return function(name, attributes) {
                open(name, attributes);
                attr(null, attributes);
            };
        else return open;
    } else if (attribute) return attr;
    else return emptyFunction;
};

//HTML Tags that shouldn't contain child nodes
var emptyTags = {
    area: true,
    base: true,
    basefont: true,
    br: true,
    col: true,
    frame: true,
    hr: true,
    img: true,
    input: true,
    isindex: true,
    link: true,
    meta: true,
    param: true,
    embed: true
};

EventedHandler.prototype.writeTag = function(element) {
    var closing = element.name.charAt(0) === "/",
        name = closing ? element.name.substring(1) : element.name,
        attributes = element.attribs || {},
        empty = emptyTags[name];

    if (closing) {
        if (!empty) {
            var i = this._stack.length - 1;
            while (i !== -1 && this._stack[i--].name !== name) {}
            if ((i += 1) !== 0)
                while (i < this._stack.length)
                    this.onclosetag(this._stack.pop().name);
        } else if (name === "br") {
            //special case for <br>s
            this.onopentag(name, attributes);
            this.onclosetag(name);
        }
    } else {
        this.onopentag(name, attributes);
        if (empty) this.onclosetag(name);
        else this._stack.push(element);
    }
};
{'fraction_non_alphanumeric': 0.12846153846153846, 'fraction_numerical': 0.002307692307692308, 'mean_word_length': 2.3064208518753975, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '76184', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1545, 'n_words': 414}