First domain string.
Second domain string.
Whether or not comparison should be done on a case-sensitive basis.
The number of domains the two strings share.
TODO: Support partial globs.
int numDomains = sharedDomains("irc.freenode.net", "leguin.freenode.net"); assert(numDomains == 2); // freenode.net int numDomains2 = sharedDomains("Portlane2.EU.GameSurge.net", "services.gamesurge.net", caseSensitive:false); assert(numDomains2 == 2); // gamesurge.net
import std.conv : text; immutable n1 = sharedDomains("irc.freenode.net", "help.freenode.net"); assert((n1 == 2), n1.text); immutable n2 = sharedDomains("irc.rizon.net", "services.rizon.net"); assert((n2 == 2), n2.text); immutable n3 = sharedDomains("www.google.com", "www.yahoo.com"); assert((n3 == 1), n3.text); immutable n4 = sharedDomains("www.google.se", "www.google.co.uk"); assert((n4 == 0), n4.text); immutable n5 = sharedDomains("", string.init); assert((n5 == 0), n5.text); immutable n6 = sharedDomains("irc.rizon.net", "rizon.net"); assert((n6 == 2), n6.text); immutable n7 = sharedDomains("rizon.net", "rizon.net"); assert((n7 == 2), n7.text); immutable n8 = sharedDomains("net", "net"); assert((n8 == 1), n8.text); immutable n9 = sharedDomains("forum.dlang.org", "..."); assert((n9 == 0), n8.text); immutable n10 = sharedDomains("blahrizon.net", "rizon.net"); assert((n10 == 1), n10.text); immutable n11 = sharedDomains("rizon.net", "blahrizon.net"); assert((n11 == 1), n11.text); immutable n12 = sharedDomains("rizon.net", "irc.rizon.net"); assert((n12 == 2), n12.text); immutable n13 = sharedDomains("irc.gamesurge.net", "Stuff.GameSurge.net", caseSensitive:false); assert((n13 == 2), n13.text); immutable n14 = sharedDomains("irc.freenode.net", "irc.FREENODE.net", caseSensitive:false); assert((n14 == 3), n14.text); immutable n15 = sharedDomains("irc.SpotChat.org", "irc.FREENODE.net", caseSensitive:false); assert((n15 == 0), n15.text);
Calculates how many dot-separated suffixes two strings share.
This is useful to see to what extent two addresses are similar.