[phobos] std.base64 replacement
Daniel Murphy
yebblies at gmail.com
Mon Oct 11 22:31:57 PDT 2010
While this is range based, I had something different in mind.
(Not these function names, just the basic idea of the signatures)
struct Base64Encoder(Range) if (isInputRange!Range && is(ElementType!Range
== ubyte))
{
// range methods
@property char front() { ... }
void popFront() { ... }
@property size_t length() { ... }
...
};
Base64Encoder!(Range) Base64Encode(Range)(Range r) if (isInputRange!Range &&
is(ElementType!Range == ubyte))
{
return Base64Encoder!Range(r);
}
This way encoding would convert an input range of ubyte to an input range of
char, and decoding would convert Range!char to Range!ubyte.
This way you would be able to use it with std.algorithm, std.range etc.
When called with an array the range would be able to provide length and be
bidirectional.
This way there would be no allocations inside the range at all.
You could create and fill a buffer using
auto buffer = array(encode(data));
or fill an existing buffer using
copy(encode(data), buffer);
At this point I don't know if everything would be better off using char or
dchar ranges.
@Andrei
Is it an improvement for the range to yield char[] instead of char?
@Sean
Would copy(decode(buffer), buffer) cover your use case sufficiently?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20101012/7ddfcbe1/attachment-0001.html>
More information about the phobos
mailing list