Regarding hex strings

monarch_dodra monarchdodra at gmail.com
Thu Oct 18 04:24:00 PDT 2012


On Thursday, 18 October 2012 at 10:39:46 UTC, monarch_dodra wrote:
>
> Yeah, that makes sense too. I'll try to toy around on my end 
> and see if I can write an "hex".

That was actually relatively easy!

Here is some usecase:

//----
void main()
{
     enum a = hex!"01 ff 7f";
     enum b = hex!0x01_ff_7f;
     ubyte[] c = hex!"0123456789abcdef";
     immutable(ubyte)[] bearophile1 = hex!"A1 B2 C3 D4";
     immutable(ubyte)[] bearophile2 = hex!0xA1_B2_C3_D4;

     a.writeln();
     b.writeln();
     c.writeln();
     bearophile1.writeln();
     bearophile2.writeln();
}
//----

And corresponding output:

//----
[1, 255, 127]
[1, 255, 127]
[1, 35, 69, 103, 137, 171, 205, 239]
[161, 178, 195, 212]
[161, 178, 195, 212]
//----

hex! was a very good idea actually, imo. I'll post my current 
impl in the next post.

That said, I don't know if I'd deprecate x"", as it serves a 
different role, as you have already pointed out, in that it 
*will* validate the code points.


More information about the Digitalmars-d mailing list