www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Base64 of String without casting

reply tcak <1ltkrs+3wyh1ow7kzn1k sharklasers.com> writes:
I understand that Base64 uses Ranges, and since String is seen 
and used as unicode by Ranges (please tell me if I am wrong).

I am guessing, for this reason, auto btoa = 
std.base64.Base64.encode("Blah"); doesn't work. You need to be 
casting the string to ubyte[] to make it work which doesn't look 
and feel nice at all.

Can/shall we add another alias into the module for encode method, 
so it accepts a string, and casts it to ubyte[] by itself?
Jun 01 2016
parent Rene Zwanenburg <renezwanenburg gmail.com> writes:
On Wednesday, 1 June 2016 at 09:31:51 UTC, tcak wrote:
 I understand that Base64 uses Ranges, and since String is seen 
 and used as unicode by Ranges (please tell me if I am wrong).

 I am guessing, for this reason, auto btoa = 
 std.base64.Base64.encode("Blah"); doesn't work. You need to be 
 casting the string to ubyte[] to make it work which doesn't 
 look and feel nice at all.

 Can/shall we add another alias into the module for encode 
 method, so it accepts a string, and casts it to ubyte[] by 
 itself?
This should do the trick: https://dlang.org/phobos/std_string.html#.representation
Jun 01 2016