Skip to content

Commit

Permalink
get rid of most dependencies, simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed May 25, 2012
1 parent 86aeab7 commit 3902d4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
12 changes: 6 additions & 6 deletions base64.dylan
Expand Up @@ -58,15 +58,15 @@ define function base64-encode
when (sidx + n < string.size)
let char-code :: <integer> = as(<integer>, string[sidx + n]);
value := logior(value, logand(#xFF, char-code));
inc!(chars);
chars := chars + 1;
end;
when (n = 1)
value := ash(value, 8);
end;
end;
result[didx + 3] := encoding-vector[iff(chars > 3, logand(value, #x3F), 64)];
result[didx + 3] := encoding-vector[if (chars > 3) logand(value, #x3F) else 64 end];
value := ash(value, -6);
result[didx + 2] := encoding-vector[iff(chars > 2, logand(value, #x3F), 64)];
result[didx + 2] := encoding-vector[if (chars > 2) logand(value, #x3F) else 64 end];
value := ash(value, -6);
result[didx + 1] := encoding-vector[logand(value, #x3F)];
value := ash(value, -6);
Expand All @@ -92,15 +92,15 @@ define function base64-decode
let value = decoding-vector[as(<integer>, char)];
unless (value == -1 | value == 64)
bitstore := logior(ash(bitstore, 6), value);
inc!(bitcount, 6);
bitcount := bitcount + 6;
when (bitcount >= 8)
dec!(bitcount, 8);
bitcount := bitcount - 8;
let code = logand(ash(bitstore, 0 - bitcount), #xFF);
if (zero?(code))
exit-block();
else
result[ridx] := as(<byte-character>, code);
inc!(ridx);
ridx := ridx + 1;
bitstore := logand(bitstore, #xFF);
end;
end;
Expand Down
7 changes: 2 additions & 5 deletions library.dylan
Expand Up @@ -5,17 +5,14 @@ License: This code is in the public domain
Warranty: Distributed WITHOUT WARRANTY OF ANY KIND

define library base64
use dylan;
use common-dylan;
use io;
use uncommon-dylan;
export base64;
end;

define module base64
use dylan;
use common-extensions, exclude: { format-to-string };
use uncommon-dylan, exclude: { split };
use streams;
use dylan-extensions, import: { <byte-character>, when };
export
base64-encode,
base64-decode;
Expand Down

0 comments on commit 3902d4b

Please sign in to comment.