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, bool extendedOutgoingColours)
  2. dstring ircColourByHash(dstring word, bool extendedOutgoingColours)
    @safe pure
    dstring
    ircColourByHash
    (
    const dstring word
    ,)

Parameters

word dstring

dstring` to tint.

extendedOutgoingColours bool

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(extendedOutgoingColours: true);
    immutable expected = I.colour ~ "23kameloso" ~ I.colour;
    assert((actual == expected), actual);
}
{
    immutable actual = "kameloso^".ircColourByHash(extendedOutgoingColours: true);
    immutable expected = I.colour ~ "56kameloso^" ~ I.colour;
    assert((actual == expected), actual);
}
{
    immutable actual = "kameloso^11".ircColourByHash(extendedOutgoingColours: true);
    immutable expected = I.colour ~ "91kameloso^11" ~ I.colour;
    assert((actual == expected), actual);
}
{
    immutable actual = "flerrp".ircColourByHash(extendedOutgoingColours: true);
    immutable expected = I.colour ~ "90flerrp" ~ I.colour;
    assert((actual == expected), actual);
}