A string to search for the substring nickname.
The nickname substring to find in haystack.
True if haystack contains needle in such a way that it is guaranteed to not be a different nickname.
assert("kameloso".containsNickname("kameloso")); assert(" kameloso ".containsNickname("kameloso")); assert(!"kam".containsNickname("kameloso")); assert(!"kameloso^".containsNickname("kameloso")); assert(!string.init.containsNickname("kameloso")); //assert(!"kameloso".containsNickname("")); // For now let this be false. assert("@kameloso".containsNickname("kameloso")); assert(!"www.kameloso.com".containsNickname("kameloso")); assert("kameloso.".containsNickname("kameloso")); assert("kameloso/".containsNickname("kameloso")); assert(!"/kameloso/".containsNickname("kameloso")); assert(!"kamelosoooo".containsNickname("kameloso")); assert(!"".containsNickname("kameloso")); version(Colours) { assert("\033[1mkameloso".containsNickname("kameloso")); assert("\033[2;3mkameloso".containsNickname("kameloso")); assert("\033[12;34mkameloso".containsNickname("kameloso")); assert(!"\033[0m0mkameloso".containsNickname("kameloso")); assert(!"\033[kameloso".containsNickname("kameloso")); assert(!"\033[mkameloso".containsNickname("kameloso")); assert(!"\033[0kameloso".containsNickname("kameloso")); assert(!"\033[0mmkameloso".containsNickname("kameloso")); assert(!"\033[0;mkameloso".containsNickname("kameloso")); assert("\033[12mkameloso\033[1mjoe".containsNickname("kameloso")); assert(!"0mkameloso".containsNickname("kameloso")); }
Searches a string for a substring that isn't surrounded by characters that can be part of a nickname. This can detect a nickname in a string without getting false positives from similar nicknames.
Tries to detect nicknames enclosed in terminal formatting. As such, call this *after* having translated IRC-to-terminal such with kameloso.irccolours.mapEffects.
Uses indexOf internally with hopes of being more resilient to weird UTF-8.