CFLib.org – Common Function Library Project

RemoveEmptyStructureKeys(structure)

Last updated April 19, 2004

author

Brian Rinaldi

Version: 1 | Requires: CF5 | Library: DataManipulationLib

Description:
Removes any empty structure keys from within a structure. This is often useful when passing FORM scope variables to a component as an argumentCollection.

Return Values:
Returns a structure.

Example:

<cfset s = structNew()>
<cfset s.foo = "">
<cfset s.goo = "something">
<cfdump var="#removeEmptyStructureKeys(s)#">

Parameters:

Name Description Required
structure Structure to modify. Yes

Full UDF Source:

/**
 * Removes any empty structure keys from within a structure.
 * version 2 by Raymond Camden, added var, slimmed things down a bit.
 * 
 * @param structure      Structure to modify. (Required)
 * @return Returns a structure. 
 * @author Brian Rinaldi (brinaldi@criticaldigital.com) 
 * @version 1, April 19, 2004 
 */
function removeEmptyStructureKeys(structure) {
    var newStructure = structNew();
    var keys = structKeyList(arguments.structure);
    var name = "";
    var i = 1;
    for (;i lte listLen(keys);i=i+1) {
        name = listGetAt(keys,i);
        if (not isSimpleValue(arguments.structure[name])) {
            newStructure[name] = arguments.structure[name];
        }
        else if (arguments.structure[name] neq "") {
            newStructure[name] = arguments.structure[name];
        }
    }
    return newStructure;
}

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

Created by Raymond Camden / Design by Justin Johnson