hexString

Converts a hex literal to a string at compile time.

Takes a string made of hexadecimal digits and returns the matching string by converting each pair of digits to a character. The input string can also include white characters, which can be used to keep the literal string readable in the source code.

The function is intended to replace the hexadecimal literal strings starting with 'x', which could be removed to simplify the core language.

  1. template hexString(string hexData)
  2. template hexString(wstring hexData)
  3. template hexString(dstring hexData)
    template hexString (
    dstring hexData
    ) if (
    hexData.isHexLiteral
    ) {
    enum dstring hexString;
    }

Parameters

hexData

string to be converted.

Return Value

a string, a wstring or a dstring, according to the type of hexData.

Examples

// conversion at compile time
auto string1 = hexString!"304A314B";
assert(string1 == "0J1K");
auto string2 = hexString!"304A314B"w;
assert(string2 == "0J1K"w);
auto string3 = hexString!"304A314B"d;
assert(string3 == "0J1K"d);

Meta