Skip to content

Instantly share code, notes, and snippets.

@Macagare
Last active December 25, 2015 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Macagare/6934747 to your computer and use it in GitHub Desktop.
Save Macagare/6934747 to your computer and use it in GitHub Desktop.
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