-
Notifications
You must be signed in to change notification settings - Fork 2
Guide 1.2꞉ Filtering Output
Each NameGenerator
can be configured to prevent specific substrings or patterns from showing up in names.
Filtering is completely optional, but is useful in avoiding awkward sounding combinations of characters.
Here is a basic example to prevent the substrings ist
and ck
from appearing in names:
var g = new NameGenerator()
.DoNotAllow("ist") // Will prevent names like "Misty"
.DoNotAllow("ck"); // Will prevent names like "Brock"
The DoNotAllow(string)
method of NameGenerator
supports formatted strings describing regular expressions.
Here is a basic example that prevents a specific prefix and suffix:
var g = new NameGenerator()
.DoNotAllow("rd$") // Prevents "Picard", but not "Varda"
.DoNotAllow("^ri"); // Prevents "Riker", but not "Dorian"
When you call DoNotAllow(string)
on a NameGenerator
, you are actually configuring the internal NameFilter
.
You can choost to customize the NameFilter
directly if needed. Here's an example of instantiating a new NameFilter
and passing it onto a new NameGenerator
:
var f = new NameFilter()
.DoNotAllowStart("thr") // Prevents "Thrond", but not "Athrun"
.DoNotAllowSubstring("tse") // Prevents "Tsen", "Betsey", etc.
.DoNotAllowEnding("j") // Prevents "Kaj", but not "Javal"
.DoNotAllow(@"(\w)\1\1"); // Prevents "Mareeen", but not "Mareen"
var g = new NameGenerator()
.UsingFilter(f);
Or in a more compact way:
var g = new NameGenerator()
.UsingFilter(x => x
.DoNotAllowStart("thr")
.DoNotAllowSubstring("tse")
.DoNotAllowEnding("j")
.DoNotAllow(@"(\w)\1\1"));