' ' ASP/VBScript Dictionary extract ' Author: WangYe ' For more information please visit ' ' This code is distributed under the BSD license ' ' collection 集合或者字典,可以通过For Each访问的 ' Request.Form 或者 Request.QueryString ' specified 指定必须存在的属性,假如该属性不存在,将自动创建一个 ' prefix 每个属性的前缀修饰 ' callback 对于集合或者字典的每个元素(key-value)的值进行函数调用 ' 函数原型: ' Function filter(key, value) ' filter = value ' End If ' 最终值将以该函数返回的值为准 ' Function extract(collection, ByVal specified, prefix, callback) Dim VarName, VarValue, DynObj, searchKey specified = "," & Replace(specified, " ", "") & ","
Set DynObj = New DynamicObject For Each key In collection searchKey = "," & key & "," If InStr(1, specified, searchKey, 1)>0 Then specified = Replace(specified, searchKey, "") If Left(specified, 1) <> "," Then specified = "," & specified End If If Right(specified, 1) <> "," Then specified = specified & "," End If End If
VarName = prefix & key
VarValue = collection(key) If callback<>"" Then VarValue = GetRef(callback)(key, VarValue) End If