> Does anyone know of a way to get the key from a structure
> with the case used to create that key?
> For example, if a key was set as myStruct["myKey"], does
> anyone know how to determine that the key was "myKey" (as
> opposed to "MYKEY")?
> Any help would be appreciated.
> Thanks!
> Steve Bryant
> Bryant Web Consulting LLC
> www.BryantWebConsulting.com
> 918-449-9440
I've heard that using array notation preserves the case of structure
keys, i.e. try this sample:
<cfoutput>
<cfset stInfo = structnew()>
<cfset stInfo.withoutcase = "nocase">
<cfset stInfo["withCase"] = "withcase">
<cfloop item="x" collection="#stInfo#">
<div>#x#</div>
</cfloop>
</cfoutput>
I don't think I would rely on that however... A better solution might
be to store the case-sensitive names in a matching structure, i.e.
<cfset stInfo = structnew()>
<cfset stCase = structnew()>
<cfset stInfo.withcase = "mydata">
<cfset stCase.withcase = "withCase">
Admittedly that's not the nicest thing to have to do in the code but
it will work... I would write some functions or a CFC to manage the
data if you really need to preserve the case of these structure keys.
<cfcomponent displayname="CaseSensitiveStructure">
<cfset variables.data = structnew()>
<cfset variables.key = structnew()>
<cffunction name="getValue" access="public">
<cfargument name="key" type="string" required="true">
<cfreturn variables.data[arguments.key]>
</cffunction>
<cffunction name="setValue" access="public">
<cfargument name="key" type="string" required="true">
<cfargument name="data" type="any" required="true">
<cfset variables.key.key = key>
<cfset variables.data.key = data>
</cffunction>
<cffunction name="getKey" access="public">
<cfargument name="key" type="string" required="true">
<cfreturn variables.key[arguments.key]>
<cffunction>
<cffunction name="setKey" access="public">
<cfargument name="key" type="string" required="true">
<cfset variables.key.key = key>
</cffunction>
</cfcomponent>
The reason for using the variables scope instead of the "this" scope
in this example cfc is to prevent the structures holding your data
from being accessed from outside the CFC. You want to do this to make
sure that the data structure is never populated except by the
setValue() function which will ensure that you have a case-sensitive
value for your key in the key structure.
Let me guess -- you're working with someone else's xml schema and they
validate it as the standard for xml insists being case-sensitive and
they used mixed-case elements and attributes? ... I _LOATHE_ that... I
really think the standard for xml identifiers should have been case
insensitive, but in failing that, when writing a schema people should
pick a case (upper or lower) and stick with it. Few things irk me
more.
hth
s. isaac dealey 954.927.5117
new epoch : isn't it time for a change?
add features without fixtures with
the onTap open source framework
http://www.sys-con.com/story/?storyid=44477&DE=1
http://www.sys-con.com/story/?storyid=45569&DE=1
http://www.fusiontap.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net
http://www.cfhosting.net
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:186164
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54