Last active
September 29, 2022 08:04
-
-
Save jonahharris/6989148 to your computer and use it in GitHub Desktop.
Revisions
-
jonahharris renamed this gist
Oct 15, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jonahharris created this gist
Oct 15, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ function parseConnectString(str) { var strLen = str.length; var isFound = false; var sb = []; var par = []; for (var jj = 0; jj < strLen; ++jj) { var c = str[jj]; if (' ' === c) continue; if ('(' === c) { isFound = false; } else if (')' === c) { var child = par.shift(); if (true === isFound) { var value = sb.join(''); if (true === /^\+?(0|[1-9]\d*)$/.test(value)) child.value = parseInt(value); else child.value = value; sb = []; isFound = false; } if (0 === par.length) { var _objectify = function (arr) { var rv = {}; if ('object' === typeof arr['value']) { var val = {}; for (var ii = 0; ii < arr['value'].length; ++ii) { var obj = _objectify(arr['value'][ii]); for (var pair in obj) val[pair] = obj[pair]; } rv[arr['name']] = val; } else { rv[arr['name']] = arr['value']; } return rv; } return _objectify(child); } else { par[0].value.push(child); } } else if ('=' === c) { var child = { name: sb.join('') .toLowerCase(), value: [] }; par.unshift(child); sb = []; isFound = true; } else { sb.push(c); } } return {}; }