Skip to content

Commit

Permalink
Make string parsing CTFEable
Browse files Browse the repository at this point in the history
  • Loading branch information
Geod24 committed Aug 22, 2019
1 parent 0d9dc44 commit 9417884
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions source/geod24/bitblob.d
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ public struct BitBlob (size_t Bits)
assert(hexstr.length == (Width * 2), ErrorMsg);

auto range = hexstr.byChar.map!(std.ascii.toLower!(char));
foreach (size_t idx, chunk; range.map!(fromHex).chunks(2).retro.enumerate)
this.data[idx] = cast(ubyte)((chunk[0] << 4) + chunk[1]);
size_t idx;
foreach (chunk; range.map!(fromHex).chunks(2).retro)
this.data[idx++] = cast(ubyte)((chunk[0] << 4) + chunk[1]);
}

/***************************************************************************
Expand Down Expand Up @@ -351,6 +352,13 @@ unittest
assert(collectException!AssertError(Hash(buff)) !is null);
}

// Make sure the string parsing works at CTFE
unittest
{
static immutable BitBlob!256 CTFEability = BitBlob!256(GenesisBlockHashStr);
static assert(CTFEability[] == GenesisBlockHash);
}

version (unittest)
{
private:
Expand Down

0 comments on commit 9417884

Please sign in to comment.