Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 79 additions & 78 deletions ProfanityFilter/ProfanityFilter/AllowList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> _allowList;
public class AllowList : IAllowList
{
HashSet<string> _allowList;

public AllowList()
{
_allowList = new List<string>();
}
public AllowList()
{
_allowList = new HashSet<string>();
}

/// <summary>
/// Return an instance of a read only collection containing allow list
/// </summary>
public ReadOnlyCollection<string> ToList
{
get
{
return new ReadOnlyCollection<string>(_allowList);
}
}
/// <summary>
/// Return an instance of a read only collection containing allow list
/// </summary>
public ReadOnlyCollection<string> ToList
{
get
{
return new ReadOnlyCollection<string>(_allowList.ToList());
}
}

/// <summary>
/// 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.
/// </summary>
/// <param name="wordToAllowlist">The word that you want to allow list.</param>
public void Add(string wordToAllowlist)
{
if (string.IsNullOrEmpty(wordToAllowlist))
{
throw new ArgumentNullException(nameof(wordToAllowlist));
}
/// <summary>
/// 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.
/// </summary>
/// <param name="wordToAllowlist">The word that you want to allow list.</param>
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));
}
}

/// <summary>
///
/// </summary>
/// <param name="wordToCheck"></param>
/// <returns></returns>
public bool Contains(string wordToCheck)
{
if (string.IsNullOrEmpty(wordToCheck))
{
throw new ArgumentNullException(nameof(wordToCheck));
}
/// <summary>
///
/// </summary>
/// <param name="wordToCheck"></param>
/// <returns></returns>
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));
}

/// <summary>
/// Return the number of items in the allow list.
/// </summary>
/// <returns>The number of items in the allow list.</returns>
public int Count
{
get
{
return _allowList.Count;
}
}
/// <summary>
/// Return the number of items in the allow list.
/// </summary>
/// <returns>The number of items in the allow list.</returns>
public int Count
{
get
{
return _allowList.Count;
}
}

/// <summary>
/// Remove all words from the allow list.
/// </summary>
public void Clear()
{
_allowList.Clear();
}
/// <summary>
/// Remove all words from the allow list.
/// </summary>
public void Clear()
{
_allowList.Clear();
}

/// <summary>
/// Remove a word from the profanity allow list. All words are treated as case insensitive.
/// </summary>
/// <param name="wordToRemove">The word that you want to use</param>
/// <returns>True if the word is successfuly removes, False otherwise.</returns>
public bool Remove(string wordToRemove)
{
if (string.IsNullOrEmpty(wordToRemove))
{
throw new ArgumentNullException(nameof(wordToRemove));
}
/// <summary>
/// Remove a word from the profanity allow list. All words are treated as case insensitive.
/// </summary>
/// <param name="wordToRemove">The word that you want to use</param>
/// <returns>True if the word is successfuly removes, False otherwise.</returns>
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));
}
}
}
4 changes: 3 additions & 1 deletion ProfanityFilter/ProfanityFilter/ProfanityList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/// <summary>
Expand All @@ -27,7 +29,7 @@ namespace ProfanityFilter
/// </summary>
public partial class ProfanityBase
{
private readonly string[] _wordList =
private readonly HashSet<string> _wordList = new HashSet<string>()
{
"2 girls 1 cup",
"2 girls one cup",
Expand Down