March 15, 2015
On 3/15/2015 2:34 PM, Walter Bright wrote:
> P.S. Also need to include all the examples in the dlang reference as unittest
> cases.

Also, HexStrings can handle w and d postfixes. Use the lexer.c code for TOK::hexStringConstant() as a guide to be sure all the permutations are covered.
March 15, 2015
On 3/15/2015 2:29 PM, bearophile wrote:
> There is an enhancement request on this (for the built in hex strings).

A link would be helpful!

March 15, 2015
Walter Bright:

> Unfortunately, it needs to be a dropin replacement for x"...", which returns a string/wstring/dstring.

This is bad. 99% of the times you don't want a string/wstring/dstring out of a hex string:

https://issues.dlang.org/show_bug.cgi?id=10454
https://issues.dlang.org/show_bug.cgi?id=5909

Bye,
bearophile
March 15, 2015
On Sunday, 15 March 2015 at 21:34:22 UTC, Walter Bright wrote:
> On 3/15/2015 2:18 PM, Baz wrote:
>> On Sunday, 15 March 2015 at 19:47:06 UTC, Walter Bright wrote:
>>> HexStrings:
>>>
>>>    http://dlang.org/lex.html#HexString
>>>
>>> They're rarely used, but very useful when needed. But, as the octal literals
>>> have shown, they can be easily replaced with a library template:
>>>
>>>    x"00 FBCD 32FD 0A"
>>>
>>> becomes:
>>>
>>>    hex!"00 FBCD 32FD 0A"
>>>
>>> Thoughts? Anyone want to write the hex template?
>>
>> I'd be interested. Here's a quick draft based on octal:
>>
>> http://dpaste.dzfl.pl/656a94cdfdba
>>
>
> I think you've got the right idea. Time for a pull request?
>
> P.S. Also need to include all the examples in the dlang reference as unittest cases.

Yes, i'll send a PR tomorrow of tuesday.

March 15, 2015
On 2015-03-15 at 22:41, bearophile wrote:
> Walter Bright:
>
>> Unfortunately, it needs to be a dropin replacement for x"...", which returns a string/wstring/dstring.
>
> This is bad. 99% of the times you don't want a string/wstring/dstring out of a hex string:

Then maybe hex!"..." should produce the desired ubyte[] and something with a different name (for example hexString!"...") would be the drop-in replacement for x"...", returning a string. The more complex name being a hint that what you really need is hex.
March 15, 2015
On 3/15/2015 2:44 PM, Baz wrote:
> Yes, i'll send a PR tomorrow of tuesday.

Good!
March 15, 2015
On Sun, Mar 15, 2015 at 11:32:04PM +0100, FG via Digitalmars-d wrote:
> On 2015-03-15 at 22:41, bearophile wrote:
> >Walter Bright:
> >
> >>Unfortunately, it needs to be a dropin replacement for x"...", which returns a string/wstring/dstring.
> >
> >This is bad. 99% of the times you don't want a string/wstring/dstring out of a hex string:
> 
> Then maybe hex!"..." should produce the desired ubyte[] and something with a different name (for example hexString!"...") would be the drop-in replacement for x"...", returning a string. The more complex name being a hint that what you really need is hex.

+1. I like this.

I was quite disappointed when I first learned that x"..." returns a string rather than immutable(ubyte)[]. I have quite a number of use cases in mind where I'd want to specify hex values to represent binary data, but can't think of any where I'd want to do that to represent string data. Needing to use casts with x"..." just looks wrong.

So using hex!"..." for immutable(ubyte)[] gets +1 from me.  Leave hexString!"..." to emulate the current behaviour of x"...".


T

-- 
War doesn't prove who's right, just who's left. -- BSD Games' Fortune
March 15, 2015
On 3/15/15 12:46 PM, Walter Bright wrote:
> HexStrings:
>
>      http://dlang.org/lex.html#HexString
>
> They're rarely used, but very useful when needed. But, as the octal
> literals have shown, they can be easily replaced with a library template:
>
>      x"00 FBCD 32FD 0A"
>
> becomes:
>
>      hex!"00 FBCD 32FD 0A"
>
> It'll simplify the core language slightly.
>
> Thoughts? Anyone want to write the hex template? Any other ideas on
> things that can removed from the core language and replaced with library
> entities?

hexString and hexBytes. -- Andrei
March 15, 2015
Andrei Alexandrescu:

> hexString and hexBytes. -- Andrei

Can you show me one or two different use cases of hexString?

Bye,
bearophile
March 15, 2015
On 3/15/15 2:37 PM, Walter Bright wrote:
> On 3/15/2015 1:38 PM, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm@gmx.net>"
> wrote:
>> Can we make it so it returns a ubyte[]?
>
> Unfortunately, it needs to be a dropin replacement for x"...", which
> returns a string/wstring/dstring.

That's what nice about library artifacts vs. language artifacts: you can add more of the former! Define hexBytes and hexString. -- Andrei