< Summary

Class:RegexProfanityFilter
Assembly:ProfanityFiltering
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/ProfanityFiltering/RegexProfanityFilter.cs
Covered lines:9
Uncovered lines:0
Coverable lines:9
Total lines:24
Line coverage:100% (9 of 9)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
RegexProfanityFilter(...)0%110100%
Filter(...)0%330100%
ToRegex(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/ProfanityFiltering/RegexProfanityFilter.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Text;
 3using System.Text.RegularExpressions;
 4
 5public class RegexProfanityFilter
 6{
 7    private readonly Regex regex;
 8
 339    public RegexProfanityFilter(IProfanityWordProvider wordProvider)
 10    {
 3311        var explicitWords = ToRegex(wordProvider.GetExplicitWords());
 3312        var nonExplicitWords = ToRegex(wordProvider.GetNonExplicitWords());
 3313        regex = new Regex(@$"\b({explicitWords})\b|({nonExplicitWords})", RegexOptions.IgnoreCase);
 3314    }
 15
 16    public string Filter(string message)
 17    {
 11418        if (string.IsNullOrEmpty(message)) return message;
 10619        return regex.Replace(message,
 1520            match => new StringBuilder().Append('*', match.Value.Length).ToString());
 21    }
 22
 6623    private string ToRegex(IEnumerable<string> words) => string.Join("|", words);
 24}