String line prefixed with prefix, potentially including separating characters.
Prefix to strip.
The passed line with the prefix sliced away.
string prefixed = "kameloso: sudo MODE +o #channel :user"; string command = prefixed.stripSeparatedPrefix("kameloso"); assert((command == "sudo MODE +o #channel :user"), command);
immutable lorem = "say: lorem ipsum".stripSeparatedPrefix("say"); assert((lorem == "lorem ipsum"), lorem); immutable notehello = "note!!!! zorael hello".stripSeparatedPrefix("note"); assert((notehello == "zorael hello"), notehello); immutable sudoquit = "sudo quit :derp".stripSeparatedPrefix("sudo"); assert((sudoquit == "quit :derp"), sudoquit); /*immutable eightball = "8ball predicate?".stripSeparatedPrefix(""); assert((eightball == "8ball predicate?"), eightball);*/ immutable isnotabot = "kamelosois a bot".stripSeparatedPrefix("kameloso"); assert((isnotabot == "kamelosois a bot"), isnotabot); immutable isabot = "kamelosois a bot" .stripSeparatedPrefix("kameloso", demandSeparatingChars: false); assert((isabot == "is a bot"), isabot); immutable doubles = "kameloso is a snek" .stripSeparatedPrefix("kameloso"); assert((doubles == "is a snek"), doubles);
Strips a prefix word from a string, optionally also stripping away some non-word characters (currently ":;?! ").
This is to make a helper for stripping away bot prefixes, where such may be "kameloso: ".