ircColourByHash

Returns the passed dstring coloured with an IRC colour depending on the hash of the string, making for good "random" (uniformly distributed) nick colours in IRC messages.

  1. string ircColourByHash(string word, Flag!"extendedOutgoingColours" extendedOutgoingColours)
  2. dstring ircColourByHash(dstring word, Flag!"extendedOutgoingColours" extendedOutgoingColours)
    @safe pure
    dstring
    ircColourByHash
    (
    const dstring word
    ,
    const Flag!"extendedOutgoingColours" extendedOutgoingColours
    )

Parameters

word dstring

dstring` to tint.

extendedOutgoingColours Flag!"extendedOutgoingColours"

Whether or not to use extended colours (16-98).

Return Value

Type: dstring

The passed dstring` encased within IRC colour coding.

Examples

alias I = IRCControlCharacter;

// Colour based on hash

{
    immutable actual = "kameloso".ircColourByHash(Yes.extendedOutgoingColours);
    immutable expected = I.colour ~ "23kameloso" ~ I.colour;
    assert((actual == expected), actual);
}
{
    immutable actual = "kameloso^".ircColourByHash(Yes.extendedOutgoingColours);
    immutable expected = I.colour ~ "56kameloso^" ~ I.colour;
    assert((actual == expected), actual);
}
{
    immutable actual = "kameloso^11".ircColourByHash(Yes.extendedOutgoingColours);
    immutable expected = I.colour ~ "91kameloso^11" ~ I.colour;
    assert((actual == expected), actual);
}
{
    immutable actual = "flerrp".ircColourByHash(Yes.extendedOutgoingColours);
    immutable expected = I.colour ~ "90flerrp" ~ I.colour;
    assert((actual == expected), actual);
}