Utility Functions: REExtractAll() and REExtractAllNoCase()

Since it had been so long since I released utility functions, I'm doing another double header today! Not that its really that hard since these two are exactly the same... but any way, continuing where yesterday's REFindAll() and REFindAllNoCase() left off, these two new functions actually return the matching values!

 

Utility Functions: REFindAll() and REFindAllNoCase()

Its been a while since I released a utility function, so today I bring you a very closely related pair that solve a very simple problem thats missing with ColdFusion's Regular Expression functions. Given a regular expression in ColdFusion, you can find out if there is a match for that regular expression in a given string, and where it is, but you can't find out the location of ALL of the values that match the regular expression.

 

Using ColdFusion to Zip Individual Files

I ran into an interesting situation this morning that didn't have an obvious answer. I needed to create a zip with a few specific files out of a directory with lots of possible files. The problem is that <cfzip /> is designed to work against whole directories, so at first I kept thinking that I'd have to make a temporary directory, move the files to it, and then zip the directory, but a little more persistence found the right answer.

 

Utility Functions: ListIsValid() and ListRemoveInvalid()

A gear One technique I often use is to create gateway objects to my database that allow the user to pass in multiple IDs, rather then a single one. I've run into a problem though; what if the user passes through something that is a valid list, but is not a valid list of the type I need? Read more to see ListIsValid() abd ListRemoveInvalid().

 

Utility Functions: CreateMapping() and RemoveMapping()

Some more "stolen" code for today's pair of utility functions. Thanks to FusionGrokker's post on controlling mappings in CF7. As FusionGrokker points out, these functions work in CF7, but its actually hacking global mapping values, so you could have problems.

<cffunction name="CreateMapping" output="false" returntype="void">
    <cfargument name="mapping" type="string" required="true" />
    <cfargument name="path" type="string" required="true" />
    
    <cfset var factory = CreateObject("java", "coldfusion.server.ServiceFactory") />
    <cfset var mappings = factory.runtimeService.getMappings() />
    
    <cfset mappings[arguments.mapping] = arguments.path />
    
    <cfreturn />
</cffunction>

<cffunction name="RemoveMapping" output="false" returntype="void">
    <cfargument name="mapping" type="string" required="true" />
    
    <cfset var factory = CreateObject("java", "coldfusion.server.ServiceFactory") />
    <cfset var mappings = factory.runtimeService.getMappings() />
    
    <cfset StructDelete(mappings, arguments.mapping) />
    
    <cfreturn />
</cffunction>

 

Utility Function: StructDeleteKeys()

A gear I often need to delete struct keys based on a list of items. Its not that I can't just loop the list and call StructDelete(), but it gets old, and this function makes it a little easier.

<cffunction name="StructDeleteKeys" returntype="void">
    <cfargument name="struct" type="struct" requried="true" />
    <cfargument name="keyList" type="string" requried="true" />
    <cfargument name="delimiters" type="string" required="false" default="," />
    
    <cfloop list="#arguments.keyList#" delimiters="#arguments.delimiters#" index="key">
        <cfset StructDelete(arguments.struct, key) />
    </cfloop>
    
    <cfreturn />
</cffunction>

 

More Entries

Post a job. Find one. authenticjobs.com