Replace characters < 0x20 that aren't IRC formatting with their U+24xx equivalents

This commit is contained in:
Juhani Krekelä 2018-05-26 22:34:48 +03:00
parent 902804cf2f
commit 46f7854d13
2 changed files with 12 additions and 1 deletions

View File

@ -24,7 +24,6 @@ TODO
* Make VM and transformMultiplyLoops use a Proxied object that gives out 0
for nonexistent elements for tape and allows using [] interface
* Keep a cache of compiled programs in `ircbotRun()`
* Replace non-IRC low bytes with their U+2400 versions in `ircbotRun()`
* Support for other types of EOF?
### gir.html

12
gir.js
View File

@ -937,6 +937,18 @@ function ircbotRun(program, input, maxCycles = 400000) {
let result = runVM(vm, maxCycles);
let output = decodeUTF8(result.state.output);
// Replace all characters < 0x20 except for IRC formatting codes
// with their graphical representations at U+24xx
let formattingChars = [0x02, 0x03, 0x0f, 0x12, 0x15];
output = Array.from(output).map(c => {
let codePoint = c.codePointAt(0);
if(codePoint < 0x20 && !formattingChars.includes(codePoint)) {
return String.fromCodePoint(0x2400 + codePoint);
} else {
return c;
}
}).join('');
// Did we run into maxCycles?
let executedTooLong = maxCycles != null &&
result.cycles >= maxCycles;