View source code
Display the source code in std/digest/package.d from which thispage was generated on github.
Report a bug
If you spot a problem with this page, click here to create aBugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinglocal clone.

Function std.digest.fromHexStringAsRange

Converts a hex text string to a range of bytes.

auto fromHexStringAsRange(String)(
  String hex
) pure nothrow @nogc @safe
if (isSomeString!String);

The input to this function MUST be valid. std.digest.isHexString can be used to check for this if needed.

Parameters

NameDescription
hex String representation of a hexdecimal-encoded byte array.

Returns

A forward range of bytes.

Example

import std.range.primitives : ElementType, isForwardRange;
import std.traits : ReturnType;

// The decoder implements a forward range.
static assert(isForwardRange!(ReturnType!(fromHexStringAsRange!string)));
static assert(isForwardRange!(ReturnType!(fromHexStringAsRange!wstring)));
static assert(isForwardRange!(ReturnType!(fromHexStringAsRange!dstring)));

// The element type of the range is always `ubyte`.
static assert(
    is(ElementType!(ReturnType!(fromHexStringAsRange!string)) == ubyte)
);
static assert(
    is(ElementType!(ReturnType!(fromHexStringAsRange!wstring)) == ubyte)
);
static assert(
    is(ElementType!(ReturnType!(fromHexStringAsRange!dstring)) == ubyte)
);

Authors

Johannes Pfau

License

Boost License 1.0.