Replace core language HexStrings with library entity

Baz via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 16 09:29:28 PDT 2015


On Sunday, 15 March 2015 at 21:41:06 UTC, 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:
>
> https://issues.dlang.org/show_bug.cgi?id=10454
> https://issues.dlang.org/show_bug.cgi?id=5909
>
> Bye,
> bearophile

this is the API that's about to be proposed, it named as 
suggested by A.A., and it handles the two issues you point out:

---
public string hexString(string hexData, bool putWhites = false)()
public string hexString(dstring hexData, bool putWhites = false)()
public string hexString(wstring hexData, bool putWhites = false)()

public ubyte[] hexBytes(string hexData)()
public ubyte[] hexBytes(dstring hexData)()
public ubyte[] hexBytes(wstring hexData)()
---

additionally to x string, a template parameter allows to put raw 
whites, e.g

---
assert(hexString!("30 30", true) == "0 1");
assert(hexString!("30 31") == "01"); // standard x string
---


More information about the Digitalmars-d mailing list