diff --git a/ProfanityFilter/ProfanityFilter/AllowList.cs b/ProfanityFilter/ProfanityFilter/AllowList.cs index b3e1a4a..b321a0a 100644 --- a/ProfanityFilter/ProfanityFilter/AllowList.cs +++ b/ProfanityFilter/ProfanityFilter/AllowList.cs @@ -21,96 +21,97 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; +using System.Linq; using ProfanityFilter.Interfaces; namespace ProfanityFilter { - public class AllowList : IAllowList - { - List _allowList; + public class AllowList : IAllowList + { + HashSet _allowList; - public AllowList() - { - _allowList = new List(); - } + public AllowList() + { + _allowList = new HashSet(); + } - /// - /// Return an instance of a read only collection containing allow list - /// - public ReadOnlyCollection ToList - { - get - { - return new ReadOnlyCollection(_allowList); - } - } + /// + /// Return an instance of a read only collection containing allow list + /// + public ReadOnlyCollection ToList + { + get + { + return new ReadOnlyCollection(_allowList.ToList()); + } + } - /// - /// Add a word to the profanity allow list. This means a word that is in the allow list - /// can be ignored. All words are treated as case insensitive. - /// - /// The word that you want to allow list. - public void Add(string wordToAllowlist) - { - if (string.IsNullOrEmpty(wordToAllowlist)) - { - throw new ArgumentNullException(nameof(wordToAllowlist)); - } + /// + /// Add a word to the profanity allow list. This means a word that is in the allow list + /// can be ignored. All words are treated as case insensitive. + /// + /// The word that you want to allow list. + public void Add(string wordToAllowlist) + { + if (string.IsNullOrEmpty(wordToAllowlist)) + { + throw new ArgumentNullException(nameof(wordToAllowlist)); + } - if (!_allowList.Contains(wordToAllowlist.ToLower(CultureInfo.InvariantCulture))) - { - _allowList.Add(wordToAllowlist.ToLower(CultureInfo.InvariantCulture)); - } - } + if (!_allowList.Contains(wordToAllowlist.ToLower(CultureInfo.InvariantCulture))) + { + _allowList.Add(wordToAllowlist.ToLower(CultureInfo.InvariantCulture)); + } + } - /// - /// - /// - /// - /// - public bool Contains(string wordToCheck) - { - if (string.IsNullOrEmpty(wordToCheck)) - { - throw new ArgumentNullException(nameof(wordToCheck)); - } + /// + /// + /// + /// + /// + public bool Contains(string wordToCheck) + { + if (string.IsNullOrEmpty(wordToCheck)) + { + throw new ArgumentNullException(nameof(wordToCheck)); + } - return _allowList.Contains(wordToCheck.ToLower(CultureInfo.InvariantCulture)); - } + return _allowList.Contains(wordToCheck.ToLower(CultureInfo.InvariantCulture)); + } - /// - /// Return the number of items in the allow list. - /// - /// The number of items in the allow list. - public int Count - { - get - { - return _allowList.Count; - } - } + /// + /// Return the number of items in the allow list. + /// + /// The number of items in the allow list. + public int Count + { + get + { + return _allowList.Count; + } + } - /// - /// Remove all words from the allow list. - /// - public void Clear() - { - _allowList.Clear(); - } + /// + /// Remove all words from the allow list. + /// + public void Clear() + { + _allowList.Clear(); + } - /// - /// Remove a word from the profanity allow list. All words are treated as case insensitive. - /// - /// The word that you want to use - /// True if the word is successfuly removes, False otherwise. - public bool Remove(string wordToRemove) - { - if (string.IsNullOrEmpty(wordToRemove)) - { - throw new ArgumentNullException(nameof(wordToRemove)); - } + /// + /// Remove a word from the profanity allow list. All words are treated as case insensitive. + /// + /// The word that you want to use + /// True if the word is successfuly removes, False otherwise. + public bool Remove(string wordToRemove) + { + if (string.IsNullOrEmpty(wordToRemove)) + { + throw new ArgumentNullException(nameof(wordToRemove)); + } - return _allowList.Remove(wordToRemove.ToLower(CultureInfo.InvariantCulture)); - } - } + return _allowList.Remove(wordToRemove.ToLower(CultureInfo.InvariantCulture)); + } + } } diff --git a/ProfanityFilter/ProfanityFilter/ProfanityList.cs b/ProfanityFilter/ProfanityFilter/ProfanityList.cs index 9f49e42..c850d1d 100644 --- a/ProfanityFilter/ProfanityFilter/ProfanityList.cs +++ b/ProfanityFilter/ProfanityFilter/ProfanityList.cs @@ -17,6 +17,8 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +using System.Collections.Generic; + namespace ProfanityFilter { /// @@ -27,7 +29,7 @@ namespace ProfanityFilter /// public partial class ProfanityBase { - private readonly string[] _wordList = + private readonly HashSet _wordList = new HashSet() { "2 girls 1 cup", "2 girls one cup",