-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertQueryStringToStruct.cfm
More file actions
25 lines (22 loc) · 1.65 KB
/
convertQueryStringToStruct.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
<cffunction name="convertQueryStringToStruct" access="public" returntype="struct" output="false" hint="I accept a url query string and return it as a structure.">
<cfargument name="querystring" type="string" required="true" hint="I am the query string for which to parse.">
<cfargument name="querystringdelimiters" type="string" required="false" default="&" hint="I am the delimiters of the query string.">
<cfargument name="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 --->
<cfset var local = structnew()>
<!--- structnew() to support versions older than ColdFusion 7 instead of {} --->
<cfset local.querystringstruct = structnew()>
<cfloop list="#arguments.querystring#" index="local.querystringindex" delimiters="#arguments.querystringdelimiters#">
<cfset local.querystringkey = urldecode(listfirst(local.querystringindex,arguments.querystringassignmentoperator))>
<cfif !find(arguments.querystringassignmentoperator,local.querystringindex)>
<cfset local.querystringvalue = "">
<cfelse>
<cfset local.querystringvalue = replacenocase(urldecode(listrest(local.querystringindex,arguments.querystringassignmentoperator,true)),local.querystringkey & arguments.querystringassignmentoperator,"")>
</cfif>
<cfif !structkeyexists(local.querystringstruct,local.querystringkey)>
<cfset structinsert(local.querystringstruct,local.querystringkey,[])>
</cfif>
<cfset arrayappend(local.querystringstruct[local.querystringkey],local.querystringvalue)>
</cfloop>
<cfreturn local.querystringstruct>
</cffunction>