Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
41
Task/Rot-13/Jsish/rot-13.jsish
Normal file
41
Task/Rot-13/Jsish/rot-13.jsish
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/local/bin/jsish
|
||||
/* ROT-13 in Jsish */
|
||||
function rot13(msg:string) {
|
||||
return msg.replace(/([a-m])|([n-z])/ig, function(m,p1,p2,ofs,str) {
|
||||
return String.fromCharCode(
|
||||
p1 ? p1.charCodeAt(0) + 13 : p2 ? p2.charCodeAt(0) - 13 : 0) || m;
|
||||
});
|
||||
}
|
||||
provide('rot13', Util.verConvert("1.0"));
|
||||
|
||||
/* rot13 command line utility */
|
||||
if (isMain()) {
|
||||
/* Unit testing */
|
||||
if (Interp.conf('unitTest') > 0) {
|
||||
; rot13('ABJURER nowhere 123!');
|
||||
; rot13(rot13('Same old same old'));
|
||||
return;
|
||||
}
|
||||
|
||||
/* rot-13 of data lines from given filenames or stdin, to stdout */
|
||||
function processFile(fname:string) {
|
||||
var str;
|
||||
if (fname == "stdin") fname = "./stdin";
|
||||
if (fname == "-") fname = "stdin";
|
||||
var fin = new Channel(fname, 'r');
|
||||
while (str = fin.gets()) puts(rot13(str));
|
||||
fin.close();
|
||||
}
|
||||
|
||||
if (console.args.length == 0) console.args.push('-');
|
||||
for (var fn of console.args) {
|
||||
try { processFile(fn); } catch(err) { puts(err, "processing", fn); }
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=!EXPECTSTART!=
|
||||
rot13('ABJURER nowhere 123!') ==> NOWHERE abjurer 123!
|
||||
rot13(rot13('Same old same old')) ==> Same old same old
|
||||
=!EXPECTEND!=
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue