isValidNickname

Examines a string and judges whether or not it *looks* like a nickname.

It only looks for invalid characters in the name as well as it length.

pure @safe nothrow @nogc
isValidNickname
(
const string nickname
,)

Parameters

nickname string

String nickname.

server IRCServer

The current IRCServer with all its settings.

Return Value

Type: auto

true if the nickname string is judged to be a nickname, false if not.

Examples

assert("kameloso".isValidNickname(server));
assert("kameloso^".isValidNickname(server));
assert("kamelåså".isValidNickname(server));
assert(!"#kameloso".isValidNickname(server));
assert(!"k&&me##so".isValidNickname(server));
import std.range : repeat;
import std.conv : to;

IRCServer s;

immutable validNicknames =
[
    "kameloso",
    "kameloso^",
    "zorael-",
    "hirr{}",
    "asdf`",
    "[afk]me",
    "a-zA-Z0-9",
    `\`,
];

immutable invalidNicknames =
[
    //"",
    'X'.repeat(s.maxNickLength+1).to!string,
    "åäöÅÄÖ",
    "\n",
    "¨",
    "@pelle",
    "+calvin",
    "&hobbes",
    "#channel",
    "$deity",
    "0kameloso",
    "-kameloso",
    "1oz",
];

foreach (immutable nickname; validNicknames)
{
    assert(nickname.isValidNickname(s), nickname);
}

foreach (immutable nickname; invalidNicknames)
{
    assert(!nickname.isValidNickname(s), nickname);
}

version(TwitchSupport)
{
    // Twitch supports numbers as first character
    s.daemon = IRCServer.Daemon.twitch;
    assert("1oz".isValidNickname(s));
}