Skip to content

Instantly share code, notes, and snippets.

@Macagare

Macagare/normalize.cfm

Last active Dec 25, 2015
Embed
What would you like to do?
normalize query string for query of queries
<cffunction name="normalizeChar" returntype="string" hint="Replaces characters with their non accented closest equivalents" output="true">
<cfargument name="str" type="string" required="true" />
<cfreturn ReplaceList( str,"á,é,í,ó,ú,ý,à,è,ì,ò,ù,â,ê,î,ô,û,ã,ñ,õ,ä,ë,ï,ö,ü,ÿ,À,È,Ì,Ò,Ù,Á,É,Í,Ó,Ú,Ý,Â,Ê,Î,Ô,Û,Ã,Ñ,Õ,Ä,Ë,Ï,Ö,Ü",
"a,e,i,o,y,u,a,e,i,o,u,a,e,i,o,u,a,n,o,a,e,i,o,u,y,A,E,I,O,U,A,E,I,O,U,Y,A,E,I,O,U,A,N,O,A,E,I,O,U") />
</cffunction>
<cffunction name="normalizeColumn" returntype="query" output="true" hint="normalize single column and add new column [column]_norm">
<cfargument name="qSource" type="query" required="true" />
<cfargument name="column" type="string" required="true" />
<cfset var normColumn = arguments.column & "_norm" />
<cfif len(arguments.column) and listFindNoCase(arguments.qSource.columnList, arguments.column) >
<cfset QueryAddColumn(arguments.qSource, normColumn, ArrayNew(1) ) />
<cfloop query="arguments.qSource">
<cfset QuerySetCell(arguments.qSource, normColumn,
lcase( normalizeChar(arguments.qSource[arguments.column][arguments.qSource.currentRow]) ),
arguments.qSource.currentRow) />
</cfloop>
</cfif>
<cfreturn arguments.qSource />
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.