- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertQueryStringToStruct.cfm
More file actions
Latest commit
25 lines (22 loc) · 1.65 KB
/
Copy pathconvertQueryStringToStruct.cfm
File metadata and controls
25 lines (22 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<cffunctionname="convertQueryStringToStruct"access="public"returntype="struct"output="false"hint="I accept a url query string and return it as a structure.">
<cfargumentname="querystring"type="string"required="true"hint="I am the query string for which to parse.">
<cfargumentname="querystringdelimiters"type="string"required="false"default="&"hint="I am the delimiters of the query string.">
<cfargumentname="querystringassignmentoperator"type="string"required="false"default="="hint="I am the assignment operator of the query string.">
<!--- var local used to support versions older than ColdFusion 9 --->
<cfsetvarlocal=structnew()>
<!--- structnew() to support versions older than ColdFusion 7 instead of {} --->
<cfsetlocal.querystringstruct=structnew()>
<cflooplist="#arguments.querystring#"index="local.querystringindex"delimiters="#arguments.querystringdelimiters#">
<cfsetlocal.querystringkey=urldecode(listfirst(local.querystringindex,arguments.querystringassignmentoperator))>
<cfif!find(arguments.querystringassignmentoperator,local.querystringindex)>
<cfsetlocal.querystringvalue="">
<cfelse>
<cfsetlocal.querystringvalue=replacenocase(urldecode(listrest(local.querystringindex,arguments.querystringassignmentoperator,true)),local.querystringkey&arguments.querystringassignmentoperator,"")>
</cfif>
<cfif!structkeyexists(local.querystringstruct,local.querystringkey)>
<cfsetstructinsert(local.querystringstruct,local.querystringkey,[])>
</cfif>
<cfsetarrayappend(local.querystringstruct[local.querystringkey],local.querystringvalue)>
</cfloop>
<cfreturnlocal.querystringstruct>
</cffunction>