Skip to content

Commit

Permalink
Merge pull request #3163 from WalterBright/crc32Of-doc
Browse files Browse the repository at this point in the history
Improve documentation for std.digest.crc.crc32Of
  • Loading branch information
yebblies committed Apr 8, 2015
2 parents 1f0cb2d + 75d33a3 commit b6b11bc
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions std/digest/crc.d
Expand Up @@ -308,13 +308,37 @@ unittest
/**
* This is a convenience alias for $(XREF digest.digest, digest) using the
* CRC32 implementation.
*
* Params:
* data = $(D InputRange) of $(D ElementType) implicitly convertible to $(D ubyte), $(D ubyte[]) or $(D ubyte[num]
* or one or more arrays of any type.
*
* Returns:
* CRC32 of data
*/
//simple alias doesn't work here, hope this gets inlined...
auto crc32Of(T...)(T data)
ubyte[4] crc32Of(T...)(T data)
{
return digest!(CRC32, T)(data);
}

///
unittest
{
ubyte[] data = [4,5,7,25];
assert(data.crc32Of == [167, 180, 199, 131]);

import std.utf : byChar;
assert("hello"d.byChar.crc32Of == [134, 166, 16, 54]);

ubyte[4] hash = "abc".crc32Of();
assert(hash == digest!CRC32("ab", "c"));

import std.range : iota;
enum ubyte S = 5, F = 66;
assert(iota(S, F).crc32Of == [59, 140, 234, 154]);
}

/**
* This is a convenience alias for $(XREF digest.digest, toHexString) producing the usual
* CRC32 string output.
Expand All @@ -323,12 +347,6 @@ public alias crcHexString = toHexString!(Order.decreasing);
///ditto
public alias crcHexString = toHexString!(Order.decreasing, 16);

///
unittest
{
ubyte[4] hash = crc32Of("abc");
assert(hash == digest!CRC32("abc")); //This is the same as above
}

/**
* OOP API CRC32 implementation.
Expand Down

0 comments on commit b6b11bc

Please sign in to comment.