# Copyright 2005-2007 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ pragma.syntax("0.9") def ASCIIRange :DeepFrozen := 0..!128 def mapStream :DeepFrozen := def getCharacter :DeepFrozen := def ::"US-ASCII" implements DeepFrozen, ExitViaHere { to __printOn(tw :TextWriter) { tw.print("") } to decode(octetStream, ==([].asMap())) { return mapStream.chunked(String, 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.fromValuesOf(out) } }) } to encode(charStream, ==([].asMap())) { # XXX should be int8 return mapStream.chunked(List[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() } }) } }