|
|
@ -42,24 +42,35 @@ function safe (val) { |
|
|
|
return (val+"").replace(/[\n\r]+/g, " "); |
|
|
|
} |
|
|
|
|
|
|
|
// ForEaches over an object. The only thing faster is to inline this function.
|
|
|
|
function objectEach(obj, fn, thisObj) { |
|
|
|
var keys, key, i, length; |
|
|
|
keys = Object.keys(obj); |
|
|
|
length = keys.length; |
|
|
|
for (i = 0; i < length; i++) { |
|
|
|
key = keys[i]; |
|
|
|
fn.call(thisObj, obj[key], key, obj); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
exports.stringify = function (obj) { |
|
|
|
// if the obj has a "-" section, then do that first.
|
|
|
|
var ini = ""; |
|
|
|
var ini = []; |
|
|
|
if ("-" in obj) { |
|
|
|
for (var key in obj["-"]) { |
|
|
|
ini += safe(key)+" = "+safe(obj["-"][key])+"\n"; |
|
|
|
} |
|
|
|
objectEach(obj["-"], function (value, key) { |
|
|
|
ini[ini.length] = safe(key) + " = " + safe(value) + "\n"; |
|
|
|
}); |
|
|
|
} |
|
|
|
for (var section in obj) if (section !== "-") { |
|
|
|
ini += "[" + safe(section) + "]\n"; |
|
|
|
for (var key in obj[section]) { |
|
|
|
|
|
|
|
ini += safe(key) + ((obj[section][key] === true) |
|
|
|
objectEach(obj, function (section, name) { |
|
|
|
if (name === "-") return; |
|
|
|
ini[ini.length] = "[" + safe(name) + "]\n"; |
|
|
|
objectEach(section, function (value, key) { |
|
|
|
ini[ini.length] = safe(key) + ((value === true) |
|
|
|
? "\n" |
|
|
|
: " = "+safe(obj[section][key])+"\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
return ini; |
|
|
|
: " = "+safe(value)+"\n"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
return ini.join(""); |
|
|
|
}; |
|
|
|
|
|
|
|
exports.encode = exports.stringify; |
|
|
|