What is Base64 part in Base64.encode
Moritz Maxeiner via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun May 14 14:22:20 PDT 2017
On Sunday, 14 May 2017 at 20:04:07 UTC, zabruk70 wrote:
> I look to std.base64 module source.
> And dont unerstand what is the "Base64" part in
> "Base64.encode(data)" example.
> I see std.base64 module use template Base64Impl.
> I see alias Base64 = Base64Impl!...
> But down understand.
> Base64 not module, not structure, not class?
The full line is `alias Base64 = Base64Impl!('+', '/');`, which
reads as (refer to [1][2]):
The symbol Base64 refers to the Base64Impl template instantiated
with the template parameters '+' and '/'.
> Template Base64Impl shoud produce function?
I don't understand what you're trying to express here.
As Base64Impl's documentation states[3], it contains a generic
Base64 implementation for which you can customize some of the
encoding characters at compile time via template parameters.
>
> I want create base32 encoder/decoder for example.
> But i dont need template.
> So how i can write Base32.encode()?
> By creating class Base32 with encode() member.
> By creating structute Base32 with encode() member.
> Any other options?
You can create a base32 encoder however you like, D has lots of
different ways you could approach this; you can even do it in a C
way with two functions base32_encode / base32_decode. Just pick
whatever you like.
PS: Please spellcheck.
[1] https://dlang.org/spec/declaration.html#alias
[2] https://dlang.org/spec/template.html
[3] https://github.com/dlang/phobos/blob/master/std/base64.d#L108
More information about the Digitalmars-d-learn
mailing list