# Copyright 2005 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ pragma.enable("easy-return") pragma.disable("explicit-result-guard") def ASCIIRange := 0..!128 def mapStream := def getCharacter := def "US-ASCII" { # implements DeepFrozen to __printOn(tw :TextWriter) { tw.print("") } to decode(octetStream, ==([].asMap())) { return mapStream.chunked(char, octetStream, def asciiChunkDecoder { to __printOn(tw :TextWriter) { tw.write("from ASCII") } to run(inn) { def out := [].diverge(char) out.setSize(inn.size()) for i => octett in inn { out[i] := getCharacter(octett :ASCIIRange) } return __makeTwine.fromSequence(out) } }) } to encode(charStream, ==([].asMap())) { return mapStream.chunked(int, charStream, def asciiChunkEncoder { to __printOn(tw :TextWriter) { tw.write("to ASCII") } to run(inn) { def out := [].diverge(ASCIIRange) out.setSize(inn.size()) for i => ch in inn { out[i] := ch.getCodepoint() } return out.snapshot() } }) } }