<commit_before>// -*- Mode: JavaScript; tab-width: 4 -*- vim:tabstop=4 syntax=javascript:
/* 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/. */
// Module: Transform text.

module.version = 1.2;
module.alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

module.cmd_tr =
function cmd_tr(dest, msg, nick, host, at, serv, relay)
{	const args = /^"(\"?[^"]+(?:\"[^"]*)*)" "(\"?[^"]+(?:\"[^"]*)*)" "(\"?[^"]+(?:\"[^"]*)*)"$/.exec(msg);
	if (!args)
		aucgbot.msg(dest, at + 'Invalid usage. Usage: tr "<text>" "<trFromTable>" "<trToTable>"');
	else
		aucgbot.msg(dest, at + tr.apply(null, args));
	return true;
}
module.cmd_rot13 =
function cmd_rot13(dest, msg, nick, host, at, serv, relay)
{	aucgbot.msg(dest, at + tr(msg, this.alphabet + this.alphabet.toLowerCase(), "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"));
	return true;
}
module.cmd_revtr =
function cmd_revtr(dest, msg, nick, host, at, serv, relay)
{	aucgbot.msg(dest, at + tr(msg, this.alphabet + this.alphabet.toLowerCase(), this.reverseABC + this.reverseABC.toLowerCase()));
	return true;
}
module.cmd_rev =
function cmd_rev(dest, msg, nick, host, at, serv, relay)
{	aucgbot.msg(dest, at + msg.reverse());
	return true;
}

// based on http://www.svendtofte.com/code/usefull_prototypes/
// and I guess from https://developer.mozilla.org/en/A_re-introduction_to_JavaScript
String.prototype.reverse =
function reverse()
{	var s = "";
	for (var i = this.length - 1; i >= 0; i--)
	    s += this[i];
	return s;
}
module.reverseABC = module.alphabet.reverse();

function tr(str, fromTable, toTable)
{	for (var s = "", i = 0, j = 0, k = ""; i < str.length; i++)
	{	if ((j = fromTable.indexOf(str[i])) == -1)
			k = str[i];
		else if (!(k = toTable[j]))
			k = "";
		s += k;
	}
	return s;
}<commit_msg>[tr] add rot47 command<commit_after>// -*- Mode: JavaScript; tab-width: 4 -*- vim:tabstop=4 syntax=javascript:
/* 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/. */
// Module: Transform text.

module.version = 1.3;
module.alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
module.alphaLC = "abcdefghijklmnopqrstuvwxyz";

module.cmd_tr =
function cmd_tr(dest, msg, nick, host, at, serv, relay)
{	const args = /^"(\"?[^"]+(?:\"[^"]*)*)" "(\"?[^"]+(?:\"[^"]*)*)" "(\"?[^"]+(?:\"[^"]*)*)"$/.exec(msg);
	if (!args)
		aucgbot.msg(dest, at + 'Invalid usage. Usage: tr "<text>" "<trFromTable>" "<trToTable>"');
	else
		aucgbot.msg(dest, at + tr.apply(null, args));
	return true;
}
module.cmd_rot13 =
function cmd_rot13(dest, msg, nick, host, at, serv, relay)
{	aucgbot.msg(dest, at + tr(msg, this.alphabet + this.alphaLC, "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"));
	return true;
}
module.cmd_rot47 =
function cmd_rot47(dest, msg, nick, host, at, serv, relay)
{	aucgbot.msg(dest, at + tr(msg, "!\"#$%&\'()*+,-./0123456789:;<=>?@" + this.alphabet + "[\\]^_`" + this.alphaLC + "{|}~", "PQRSTUVWXYZ[\\]^_`" + this.alphaLC + "{|}~!\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO"));
module.cmd_revtr =
function cmd_revtr(dest, msg, nick, host, at, serv, relay)
{	aucgbot.msg(dest, at + tr(msg, this.alphabet + this.alphaLC, this.reverseABC + this.reverseABC.toLowerCase()));
	return true;
}
module.cmd_rev =
function cmd_rev(dest, msg, nick, host, at, serv, relay)
{	aucgbot.msg(dest, at + msg.reverse());
	return true;
}

// from http://www.svendtofte.com/code/usefull_prototypes/
// and https://developer.mozilla.org/en/A_re-introduction_to_JavaScript
String.prototype.reverse =
function reverse()
{	var s = "";
	for (var i = this.length - 1; i >= 0; i--)
	    s += this[i];
	return s;
}
module.reverseABC = module.alphabet.reverse();

function tr(str, fromTable, toTable)
{	var s = "";
	for (var i = 0, j = 0, k = ""; i < str.length; i++)
	{	if ((j = fromTable.indexOf(str[i])) == -1)
			k = str[i];
		else if (!(k = toTable[j]))
			k = "";
		s += k;
	}
	return s;
}
{'fraction_non_alphanumeric': 0.21317452600875061, 'fraction_numerical': 0.014584346135148274, 'mean_word_length': 4.235368956743002, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '541340', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1610, 'n_words': 388}