diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-06 16:07:23 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-06 16:07:23 -0400 |
| commit | 6782cc5570e194791ca6cdd695b88897e9145564 (patch) | |
| tree | a428e9d954aca251212ec1cf15bd35e0badce630 /examples/base64/base64.tm | |
| parent | 448e805293989b06e07878a4a87fdd378f7c6e02 (diff) | |
No more colons for blocks
Diffstat (limited to 'examples/base64/base64.tm')
| -rw-r--r-- | examples/base64/base64.tm | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/examples/base64/base64.tm b/examples/base64/base64.tm index 714e223b..bf512a83 100644 --- a/examples/base64/base64.tm +++ b/examples/base64/base64.tm @@ -23,15 +23,15 @@ _dec : [Byte] = [ 49, 50, 51, 255, 255, 255, 255, 255, ] -lang Base64: - func parse(text:Text -> Base64?): +lang Base64 + func parse(text:Text -> Base64?) return Base64.from_bytes(text.bytes()) - func from_bytes(bytes:[Byte] -> Base64?): + func from_bytes(bytes:[Byte] -> Base64?) output := &[Byte(0) for _ in bytes.length * 4 / 3 + 4] src := Int64(1) dest := Int64(1) - while src + 2 <= Int64(bytes.length): + while src + 2 <= Int64(bytes.length) chunk24 := ( (Int32(bytes[src]) <<< 16) or (Int32(bytes[src+1]) <<< 8) or Int32(bytes[src+2]) ) @@ -43,7 +43,7 @@ lang Base64: output[dest+3] = _enc[1 + (chunk24 and 0b111111)] dest += 4 - if src + 1 == bytes.length: + if src + 1 == bytes.length chunk16 := ( (Int32(bytes[src]) <<< 8) or Int32(bytes[src+1]) ) @@ -51,7 +51,7 @@ lang Base64: output[dest+1] = _enc[1 + ((chunk16 >>> 4) and 0b111111)] output[dest+2] = _enc[1 + ((chunk16 <<< 2)and 0b111111)] output[dest+3] = _EQUAL_BYTE - else if src == bytes.length: + else if src == bytes.length chunk8 := Int32(bytes[src]) output[dest] = _enc[1 + ((chunk8 >>> 2) and 0b111111)] output[dest+1] = _enc[1 + ((chunk8 <<< 4) and 0b111111)] @@ -60,15 +60,15 @@ lang Base64: return Base64.from_text(Text.from_bytes(output[]) or return none) - func decode_text(b64:Base64 -> Text?): + func decode_text(b64:Base64 -> Text?) return Text.from_bytes(b64.decode_bytes() or return none) - func decode_bytes(b64:Base64 -> [Byte]?): + func decode_bytes(b64:Base64 -> [Byte]?) bytes := b64.text.bytes() output := &[Byte(0) for _ in bytes.length/4 * 3] src := Int64(1) dest := Int64(1) - while src + 3 <= Int64(bytes.length): + while src + 3 <= Int64(bytes.length) chunk24 := ( (Int32(_dec[1+bytes[src]]) <<< 18) or (Int32(_dec[1+bytes[src+1]]) <<< 12) or @@ -82,15 +82,15 @@ lang Base64: output[dest+2] = Byte(chunk24 and 0xFF) dest += 3 - while output[-1] == 0xFF: + while output[-1] == 0xFF output[] = output.to(-2) return output[] -func main(input=(/dev/stdin), decode=no): - if decode: +func main(input=(/dev/stdin), decode=no) + if decode b := Base64.from_text(input.read()!) say(b.decode_text()!) - else: + else text := input.read()! say(Base64.parse(text)!.text) |
