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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson