Class $sf.lib.lang.ParamHash
Intantiable class used to convert a delimited string into an object.
For example querystrings: "name_1=value_1&name_2=value_2" ==> {name_1:value_1,name_2:value_2};
Note that property values could also contain the same sPropDelim and sValueDelim strings. Proper string encoding should occur
to not trip up the parsing of the string. Said values may be ascii escaped, and in turn, along with the bRecurse constructor parameter set to true, will cause nested ParamHash objects to be created.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
$sf.lib.lang.ParamHash(sString, sPropDelim, sValueDelim, bNoOverwrite, bRecurse)
|
Method Summary
Class Detail
$sf.lib.lang.ParamHash(sString, sPropDelim, sValueDelim, bNoOverwrite, bRecurse)
var ph = new $sf.lib.lang.ParamHash("x=1&y=1&z=1");
alert(ph.x); // == 1
alert(ph.y); // == 1
alert(ph.z); // == 1
var ph = new $sf.lib.lang.ParamHash("x:1;y:2;z:3", ";", ":");
alert(ph.x); // == 1
alert(ph.y); // == 2
alert(ph.z); // == 3
var ph = new $sf.lib.lang.ParamHash("x=1&y=1&z=1&z=2");
alert(ph.x); // == 1
alert(ph.y); // 1
alert(ph.z); //Note that z == 2 b/c of 2 properties with the same name
var ph = new $sf.lib.lang.ParamHash("x=1&y=1&z=1&z=2",null,null,true); //null for sPropDelim and sValueDelim == use default values of "&" and "=" respectively
alert(ph.x); // == 1
alert(ph.y); // 1
alert(ph.z); //Note that z == 1 b/c bNoOverwrite was set to true
//You can also do recursive processing if need be
var points = new $sf.lib.lang.ParamHash(),
point_1 = new $sf.lib.lang.ParamHash(),
point_2 = new $sf.lib.lang.ParamHash();
point_1.x = 100;
point_1.y = 75;
point_2.x = 200;
point_2.y = 150;
points.point_1 = point_1;
points.point_2 = point_2;
var point_str = points.toString(); // == "point_1=x%3D100%26y%3D75%26&point_2=x%3D200%26y%3D150%26&";
var points_copy = new $sf.lib.lang.ParamHash(point_str, null, null, true, true); //note passing true, b/c we want to recurse
alert(points_copy.point_1.x) // == "100";
- Parameters:
- {String} sString Optional
- The delimited string to be converted
- {String} sPropDelim Optional, Default: "&"
- The substring delimiter used to seperate properties. Default is "&".
- {String} sValueDelim Optional, Default: "="
- The substring delimited used to seperate values. Default is "=".
- {Boolean} bNoOverwrite Optional, Default: false
- If true, when a name is encountered more than 1 time in the string it will be ignored.
- {Boolean} bRecurse Optional, Default: false
- If true, when a value of a property that is parsed also has both the sPropDelim and sValueDelim inside, convert that value to another ParamHash object automatically
Method Detail
-
{String} toString(sPropDelim, sValueDelim, escapeProp, dontEscapeValue)Converts a ParamHash object back into a string using the property and value delimiters specifed (defaults to "&" and "="). Again this method works recursively. If an object is found as a property, it will convert that object into a ParamHash string and then escape it. Note also that this class's valueOf method is equal to this method.
- Parameters:
- {String} sPropDelim Optional, Default: "&"
- The substring delimiter used to seperate properties. Default is "&".
- {String} sValueDelim Optional, Default: "="
- The substring delimited used to seperate values. Default is "=".
- {Boolean} escapeProp Optional, Default: false
- Whether or not to ascii escape the name of a property
- {Boolean} dontEscapeValue Optional, Default: false
- Do not escape values or properties automatically
- Returns:
- {String} the encoded string representation of the object.