<commit_before>var MT = require('message').Type;
var Views = {utils: {}};
var hideClasses = (function(){
	var nbpow = 17, i = 1, max = i << nbpow, classes = [];
	while (i <= max) {
		classes.push("hide-" + i);
		i = i << 1;
	}
	return classes.join(" ");
})();

Views._decorator = {sender: {}, content: {}};
//Views._decorator.sender[MT.Notice] = '';
//Views._decorator.sender[MT.Action] = '';
Views._decorator.sender[MT.Nick] = '<->';
Views._decorator.sender[MT.Mode] = '***';
Views._decorator.sender[MT.Join] = '-->';
Views._decorator.sender[MT.Part] = '<--';
Views._decorator.sender[MT.Quit] = '<--';
Views._decorator.sender[MT.Kick] = '<-*';
//Views._decorator.sender[MT.Kill] = '';
Views._decorator.sender[MT.Server] = function(nick) {
	return nick || "*";
};
//Views._decorator.sender[MT.Info] = '';
//Views._decorator.sender[MT.Error] = '';
//Views._decorator.sender[MT.DayChange] = '-';
Views._decorator.sender[MT.Topic] = '*';
Views._decorator.sender[MT.NetsplitJoin] = '=>';
Views._decorator.sender[MT.NetsplitQuit] = '<=';
//Views._decorator.sender[MT.Invite] = '';

//Views._decorator.content[MT.Notice] = '';
//Views._decorator.content[MT.Action] = '';
Views._decorator.content[MT.Nick] = function(nick, content) {
	return Views.utils.stripnick(nick) + " is now known as " + content;
};
Views._decorator.content[MT.Mode] = function(nick, content) {
	return "Mode " + content + " by " + Views.utils.stripnick(nick);
};
Views._decorator.content[MT.Join] = function(nick, content) {
	return Views.utils.stripnick(nick) + " has joined";
};
Views._decorator.content[MT.Part] = function(nick, content) {
	return Views.utils.stripnick(nick) + " has left";
};
Views._decorator.content[MT.Quit] = function(nick, content) {
	return Views.utils.stripnick(nick) + " has quit";
};
Views._decorator.content[MT.Kick] = function(nick, content) {
	var ind = content.indexOf(" ");
	return Views.utils.stripnick(nick) + " has kicked " + content.slice(0, ind) + " (" + content.slice(ind+1) + ")";
};
//Views._decorator.content[MT.Kill] = '';
//Views._decorator.content[MT.Server] = '';
//Views._decorator.content[MT.Info] = '';
//Views._decorator.content[MT.Error] = '';
//Views._decorator.content[MT.DayChange] = '-';
//Views._decorator.content[MT.Topic] = ''; // as is
//Views._decorator.content[MT.NetsplitJoin] = ''; // as is
//Views._decorator.content[MT.NetsplitQuit] = '<='; // as is
//Views._decorator.content[MT.Invite] = '';

Views.RE = {};
Views.RE.BOLD = new RegExp(String.fromCharCode(2)+"(.*?)"+String.fromCharCode(2), "g");
Views.RE.NORMAL = new RegExp(String.fromCharCode(15)+"(.*?)"+String.fromCharCode(15), "g");
Views.RE.ITALIC = new RegExp(String.fromCharCode(29)+"(.*?)"+String.fromCharCode(29), "g");
Views.RE.UNDERLINE = new RegExp(String.fromCharCode(31)+"(.*?)"+String.fromCharCode(31), "g");
Views.RE.COLOR = new RegExp(String.fromCharCode(3)+"([0-9]{0,2}),?([0-9]{0,2})(.*?)"+String.fromCharCode(3),"g");

var tagsToReplace = {
	'&': '&amp;',
	'<': '&lt;',
	'>': '&gt;',
	'"': '&quot;',
	'\'': '&#x27;',
	'/': '&#x2F;'
}, re = /[&<>]/g;

Views.utils.makeLinks = function(str) {
	if (!str) return null;
	return str.replace(re, function (tag) {
		return tagsToReplace[tag] || tag;
	});
};

Views.utils.escapetags = function(str) {
	if (!str) return null;
	return str.replace(re, function (tag) {
		return tagsToReplace[tag] || tag;
	});
};

Views.utils.stripname = function(s) {
	if (!s) return '';
	if (s[0] === '#') {
		return s.substring(1);
	}
	return s;
};

Views.utils.stripnick = function(s) {
	if (!s) return '';
	var ind = s.indexOf('!');
	if (ind !== -1) {
		return s.slice(0, ind);
	}
	return s;
};



Views.utils.HHmmss = function(d) {
	var dateObject = null;
	if (d instanceof Date) {
		dateObject = d;
	} else {
		dateObject = new Date(d);
	}
	var h = dateObject.getHours(), m = dateObject.getMinutes(), s = dateObject.getSeconds();
	if (h < 10) h = '0'+h;
	if (m < 10) m = '0'+m;
	if (s < 10) s = '0'+s;
	return [h, m, s].join(':');
};

Views.utils.hashCode = function(s) {
  var hash = 0, i, chr, len;
  if (s.length == 0) return hash;
  for (i = 0, len = s.length; i < len; i++) {
    chr   = s.charCodeAt(i);
    hash  = ((hash << 5) - hash) + chr;
    hash |= 0; // Convert to 32bit integer
  }
  return hash;
};

Views.utils.nickHash = function(s) {
	return Math.abs(Views.utils.hashCode(s)) % 16;
};

Views.utils.getHtmlStyledMessage = function(message) {
    
    message = message.replace(Views.RE.BOLD, function(match, m1) {
        if (m1.length > 0) {
            return "<b>"+m1+"</b>";
        }
        return '';
    });
    
    message = message.replace(Views.RE.NORMAL, "$1");
    
    message = message.replace(Views.RE.ITALIC, function(match, m1) {
        if (m1.length > 0) {
            return "<i>"+m1+"</i>";
        }
        return '';
    });
    
    message = message.replace(Views.RE.UNDERLINE, function(match, m1) {
        if (m1.length > 0) {
            return "<u>"+m1+"</u>";
        }
        return '';
    });
    
    message = message.replace(Views.RE.COLOR, function(match, fg, bg, m3) {
        if (m3.length > 0) {
            classes = [];
            if (fg.length > 0) {
                classes.push("mirc-fg-"+fg);
            }
            if (bg.length > 0) {
                classes.push("mirc-bg-"+bg);
            }
            return '<span class="'+classes.join(" ")+'">'+m3+'</span>';
        }
        return '';
    });
    
    return message;
};

Views.alert = function(message) {
	$(".alert").removeClass("hidden");
	$(".alert .alert-text").html(message);
};<commit_msg>Accurate mirc syntax parsing fix (color, bold, etc.). Fixes #22<commit_after>var MT = require('message').Type;
var Views = {utils: {}};
var hideClasses = (function(){
	var nbpow = 17, i = 1, max = i << nbpow, classes = [];
	while (i <= max) {
		classes.push("hide-" + i);
		i = i << 1;
	}
	return classes.join(" ");
})();

Views._decorator = {sender: {}, content: {}};
//Views._decorator.sender[MT.Notice] = '';
//Views._decorator.sender[MT.Action] = '';
Views._decorator.sender[MT.Nick] = '<->';
Views._decorator.sender[MT.Mode] = '***';
Views._decorator.sender[MT.Join] = '-->';
Views._decorator.sender[MT.Part] = '<--';
Views._decorator.sender[MT.Quit] = '<--';
Views._decorator.sender[MT.Kick] = '<-*';
//Views._decorator.sender[MT.Kill] = '';
Views._decorator.sender[MT.Server] = function(nick) {
	return nick || "*";
};
//Views._decorator.sender[MT.Info] = '';
//Views._decorator.sender[MT.Error] = '';
//Views._decorator.sender[MT.DayChange] = '-';
Views._decorator.sender[MT.Topic] = '*';
Views._decorator.sender[MT.NetsplitJoin] = '=>';
Views._decorator.sender[MT.NetsplitQuit] = '<=';
//Views._decorator.sender[MT.Invite] = '';

//Views._decorator.content[MT.Notice] = '';
//Views._decorator.content[MT.Action] = '';
Views._decorator.content[MT.Nick] = function(nick, content) {
	return Views.utils.stripnick(nick) + " is now known as " + content;
};
Views._decorator.content[MT.Mode] = function(nick, content) {
	return "Mode " + content + " by " + Views.utils.stripnick(nick);
};
Views._decorator.content[MT.Join] = function(nick, content) {
	return Views.utils.stripnick(nick) + " has joined";
};
Views._decorator.content[MT.Part] = function(nick, content) {
	return Views.utils.stripnick(nick) + " has left";
};
Views._decorator.content[MT.Quit] = function(nick, content) {
	return Views.utils.stripnick(nick) + " has quit";
};
Views._decorator.content[MT.Kick] = function(nick, content) {
	var ind = content.indexOf(" ");
	return Views.utils.stripnick(nick) + " has kicked " + content.slice(0, ind) + " (" + content.slice(ind+1) + ")";
};
//Views._decorator.content[MT.Kill] = '';
//Views._decorator.content[MT.Server] = '';
//Views._decorator.content[MT.Info] = '';
//Views._decorator.content[MT.Error] = '';
//Views._decorator.content[MT.DayChange] = '-';
//Views._decorator.content[MT.Topic] = ''; // as is
//Views._decorator.content[MT.NetsplitJoin] = ''; // as is
//Views._decorator.content[MT.NetsplitQuit] = '<='; // as is
//Views._decorator.content[MT.Invite] = '';

Views.RE = {};
Views.RE.COLOR = new RegExp("^" + String.fromCharCode(3) + "(([0-9]{1,2})(,([0-9]{1,2}))?)");

var tagsToReplace = {
	'&': '&amp;',
	'<': '&lt;',
	'>': '&gt;',
	'"': '&quot;',
	'\'': '&#x27;',
	'/': '&#x2F;'
}, re = /[&<>]/g;

Views.utils.makeLinks = function(str) {
	if (!str) return null;
	return str.replace(re, function (tag) {
		return tagsToReplace[tag] || tag;
	});
};

Views.utils.escapetags = function(str) {
	if (!str) return null;
	return str.replace(re, function (tag) {
		return tagsToReplace[tag] || tag;
	});
};

Views.utils.stripname = function(s) {
	if (!s) return '';
	if (s[0] === '#') {
		return s.substring(1);
	}
	return s;
};

Views.utils.stripnick = function(s) {
	if (!s) return '';
	var ind = s.indexOf('!');
	if (ind !== -1) {
		return s.slice(0, ind);
	}
	return s;
};



Views.utils.HHmmss = function(d) {
	var dateObject = null;
	if (d instanceof Date) {
		dateObject = d;
	} else {
		dateObject = new Date(d);
	}
	var h = dateObject.getHours(), m = dateObject.getMinutes(), s = dateObject.getSeconds();
	if (h < 10) h = '0'+h;
	if (m < 10) m = '0'+m;
	if (s < 10) s = '0'+s;
	return [h, m, s].join(':');
};

Views.utils.hashCode = function(s) {
  var hash = 0, i, chr, len;
  if (s.length == 0) return hash;
  for (i = 0, len = s.length; i < len; i++) {
    chr   = s.charCodeAt(i);
    hash  = ((hash << 5) - hash) + chr;
    hash |= 0; // Convert to 32bit integer
  }
  return hash;
};

Views.utils.nickHash = function(s) {
	return Math.abs(Views.utils.hashCode(s)) % 16;
};

Views.utils.getHtmlStyledMessage = function(msg) {
    var out = '',
        nbSpan = 0,
        nbSpanColor = 0,
        spanAttributes = {
            bold: false,
            italic: false,
            underline: false
        },
        i = 0,
        match;

    var openSpan = function (classes) {
        nbSpan += 1;
        return '<span class="' + classes + '">';
    };

    var openColorSpan = function (fgclass, bgclass) {
        nbSpanColor += 1;
        var classes = fgclass;
        if (bgclass) {
            classes += ' ' + bgclass;
        }
        return openSpan(classes);
    };

    var closeSpan = function () {
        nbSpan -= 1;
        return '</span>';
    };

    var closeColorSpan = function () {
        nbSpanColor -= 1;
        return closeSpan();
    };

    for (i = 0; i < msg.length; i++) {
        switch (msg[i]) {
            case '\x02':
                if (spanAttributes.bold) {
                    out += closeSpan();
                } else {
                    out += openSpan('mirc-bold');
                }
                spanAttributes.bold = !spanAttributes.bold;
                break;
            case '\x1D':
                if (spanAttributes.italic) {
                    out += closeSpan();
                } else {
                    out += openSpan('mirc-italic');
                }
                spanAttributes.italic = !spanAttributes.italic;
                break;
            case '\x1F':
                if (spanAttributes.underline) {
                    out += closeSpan();
                } else {
                    out += openSpan('mirc-underline');
                }
                spanAttributes.underline = !spanAttributes.underline;
                break;
            case '\x03':
                match = msg.substr(i, 6).match(Views.RE.COLOR);
                var classfg = false,
                    classbg = false;
                if (match) {
                    i += match[1].length;
                    // 2 & 4
                    classfg = "mirc-fg-" + parseInt(match[2], 10);
                    if (match[4]) {
                        classbg = "mirc-bg-" + parseInt(match[4], 10);
                    }
                    out += openColorSpan(classfg, classbg);
                } else {
                    while (nbSpanColor > 0) {
                        out += closeColorSpan();
                    }
                }
                break;
            case '\x0F':
                while (nbSpan > 0) {
                    out += closeSpan();
                }
                spanAttributes.bold = spanAttributes.italic = spanAttributes.underline = spanAttributes.colour = false;
                break;
            default:
                out += msg[i];
                break;
        }
    }
    while (nbSpan > 0) {
        out += closeSpan();
    }
    return out;
};

Views.alert = function(message) {
	$(".alert").removeClass("hidden");
	$(".alert .alert-text").html(message);
};
{'fraction_non_alphanumeric': 0.20356517587139902, 'fraction_numerical': 0.011539073690911984, 'mean_word_length': 2.529064869418703, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 32, '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': '7559963', 'n_tokens_mistral': 4567, 'n_tokens_neox': 4368, 'n_words': 797}