naughtyFilter(body[, replaceType][, repeatValue][, naughtyList][, replaceString])
Last updated August 17, 2004
Version: 1 | Requires: CF5 | Library: StrLib
Description:
Replaces dirty words in text using naughtyList (Carlin's 7 dirty words as an example) with either middle characters only or full replacement of text.
Return Values:
Returns a string.
Example:
<cfset testTxt ="George Carlin's 7 Dirty words are shit piss fuck cunt cocksucker, mother fucker and tits">
<cfoutput>#naughtyFilter(testTxt,"FL")#</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
body | String to check. | Yes |
replaceType | If ALL, all characters are replaced. If FL, only the middle characters are replaced. Defaults to ALL. | No |
repeatValue | String to use for replacement when replaceType is FL. Defaults to * | No |
naughtyList | Default list of curse words. | No |
replaceString | Used for replacements when replaceType is ALL. | No |
Full UDF Source:
<!---
Replaces dirty words with pattern.
@param body String to check. (Required)
@param replaceType If ALL, all characters are replaced. If FL, only the middle characters are replaced. Defaults to ALL. (Optional)
@param repeatValue String to use for replacement when replaceType is FL. Defaults to * (Optional)
@param naughtyList Default list of curse words. (Optional)
@param replaceString Used for replacements when replaceType is ALL. (Optional)
@return Returns a string.
@author Chris Wigginton (c_wigginton@yahoo.com)
@version 1, November 30, 2004
--->
<cffunction name="naughtyFilter" returntype="string" hint="Replaces unmentionables with gobbledegook">
<cfargument name="body" type="string" required="yes" hint="Contains text to filter">
<cfargument name="replaceType" default="all" hint="ALL - all characters, FL - only the middle bits are replaced">
<cfargument name="repeatValue" default="*" hint="Character to repeat for replaced dirty characters">
<cfargument name="naughtyList" default="mother fucker,cocksucker,shit,piss,fuck,cunt,tits" hint="George Carlin's original 7 dirty words, not in his original order, but the longest listed first">
<cfargument name="replaceString" default="!@##$%^&*()!@##$%^&*()!@##$%^&*" hint="A replace string for ALL method, length must be at least as long as the longest dirty word">
<cfset var naughtyWord = "">
<cfset var replacement = "">
<cfloop list="#Arguments.naughtyList#" index="naughtyWord" delimiters=",">
<cfswitch expression="#UCase(Arguments.replaceType)#">
<cfcase value="FL">
<cfif Len(naughtyWord) GTE 3>
<cfset replacement = Left(naughtyWord,1) & RepeatString(Arguments.repeatValue,Len(naughtyWord) - 2) & Right(naughtyWord,1)>
<cfelse>
<cfset replacement = RepeatString(Arguments.repeatValue,Len(naughtyWord))>
</cfif>
</cfcase>
<cfdefaultcase>
<cfset replacement = Left(Arguments.replaceString,Len(naughtyWord))>
</cfdefaultcase>
</cfswitch>
<cfset Arguments.body = REReplaceNoCase(Arguments.body,naughtyWord,replacement, "ALL")>
</cfloop>
<cfreturn Arguments.body>
</cffunction>
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016