Noodle/Helpers/Censor.cs
/// <summary>
/// Determines whether [is profanity free] [the specified STR].
/// </summary>
/// <param name="str">The STR.</param>
/// <returns>
///   <c>true</c> if [is profanity free] [the specified STR]; otherwise, <c>false</c>.
/// </returns>
Determines whether [is profanity free] [the specified STR].
Determines whether [ is profanity free ] [ the specified STR ] .
public static bool IsInappropriate(string str)
        {
            if (string.IsNullOrEmpty(str))
                return false;
            List<string> foundWords = new List<string>();
            var strToCheck = " " + str + " ";
            foreach (var censoredWord in _allWords)
            {
                var isSpecialCharBefore = false;
                var isSpecialCharAfter = false;
                if (strToCheck.ToLowerInvariant().IndexOf(censoredWord, System.StringComparison.Ordinal) > -1)
                {
                    foreach (var spec in _specialCharsForString)
                    {
                        if (strToCheck.ToLowerInvariant().IndexOf(spec + censoredWord, System.StringComparison.Ordinal) > -1)
                        {
                            isSpecialCharBefore = true;
                            break;
                        }
                    }
                    foreach (var spec in _specialCharsForString)
                    {
                        if (strToCheck.ToLowerInvariant().IndexOf(censoredWord + spec, System.StringComparison.Ordinal) > -1)
                        {
                            isSpecialCharAfter = true;
                            break;
                        }
                    }
                }
                if (isSpecialCharBefore && isSpecialCharAfter)
                {
                    foundWords.Add(censoredWord);
                }
            }
            var strWithoutPunctuation = RemoveSpecialCharacters(strToCheck);
            foreach (var hardStopWord in _hardStopWords)
            {
                if (strWithoutPunctuation.IndexOf(hardStopWord, System.StringComparison.Ordinal) > -1)
                {
                    foundWords.Add(hardStopWord);
                }
            }
            var foundWordsWithoutDupes = foundWords.Distinct().ToList();
            if (foundWordsWithoutDupes.Count > 0)
                Log.Instance.Trace("\r\n*** String under test: {0} \r\n*** Inappropriate words found: {1}", str, string.Join(",", foundWords));
            return foundWordsWithoutDupes.Count > 0;
        }
public static bool IsInappropriate ( string str ) { if ( string . IsNullOrEmpty ( str ) ) return false ; List < string > foundWords = new List < string > ( ) ; var strToCheck = " " + str + " " ; foreach ( var censoredWord in _allWords ) { var isSpecialCharBefore = false ; var isSpecialCharAfter = false ; if ( strToCheck . ToLowerInvariant ( ) . IndexOf ( censoredWord , System . StringComparison . Ordinal ) > - 1 ) { foreach ( var spec in _specialCharsForString ) { if ( strToCheck . ToLowerInvariant ( ) . IndexOf ( spec + censoredWord , System . StringComparison . Ordinal ) > - 1 ) { isSpecialCharBefore = true ; break ; } } foreach ( var spec in _specialCharsForString ) { if ( strToCheck . ToLowerInvariant ( ) . IndexOf ( censoredWord + spec , System . StringComparison . Ordinal ) > - 1 ) { isSpecialCharAfter = true ; break ; } } } if ( isSpecialCharBefore && isSpecialCharAfter ) { foundWords . Add ( censoredWord ) ; } } var strWithoutPunctuation = RemoveSpecialCharacters ( strToCheck ) ; foreach ( var hardStopWord in _hardStopWords ) { if ( strWithoutPunctuation . IndexOf ( hardStopWord , System . StringComparison . Ordinal ) > - 1 ) { foundWords . Add ( hardStopWord ) ; } } var foundWordsWithoutDupes = foundWords . Distinct ( ) . ToList ( ) ; if ( foundWordsWithoutDupes . Count > 0 ) Log . Instance . Trace ( " \r \n \r \n " , str , string . Join ( " " , foundWords ) ) ; return foundWordsWithoutDupes . Count > 0 ; }
Determines whether [is profanity free] [the specified STR].
Determines whether [ is profanity free ] [ the specified STR ] .
//check all words/phrases/patterns // basic word check //check for special character before //check for special character after // only add if specialChar before AND after //check without punctuation //check hard stop words //remove dupes // if inappropriate words are found, return true
None
str
string
None