|
@ -42,24 +42,35 @@ function safe (val) { |
|
|
return (val+"").replace(/[\n\r]+/g, " "); |
|
|
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) { |
|
|
exports.stringify = function (obj) { |
|
|
// if the obj has a "-" section, then do that first.
|
|
|
// if the obj has a "-" section, then do that first.
|
|
|
var ini = ""; |
|
|
var ini = []; |
|
|
if ("-" in obj) { |
|
|
if ("-" in obj) { |
|
|
for (var key in obj["-"]) { |
|
|
objectEach(obj["-"], function (value, key) { |
|
|
ini += safe(key)+" = "+safe(obj["-"][key])+"\n"; |
|
|
ini[ini.length] = safe(key) + " = " + safe(value) + "\n"; |
|
|
} |
|
|
}); |
|
|
} |
|
|
} |
|
|
for (var section in obj) if (section !== "-") { |
|
|
objectEach(obj, function (section, name) { |
|
|
ini += "[" + safe(section) + "]\n"; |
|
|
if (name === "-") return; |
|
|
for (var key in obj[section]) { |
|
|
ini[ini.length] = "[" + safe(name) + "]\n"; |
|
|
|
|
|
objectEach(section, function (value, key) { |
|
|
ini += safe(key) + ((obj[section][key] === true) |
|
|
ini[ini.length] = safe(key) + ((value === true) |
|
|
? "\n" |
|
|
? "\n" |
|
|
: " = "+safe(obj[section][key])+"\n"); |
|
|
: " = "+safe(value)+"\n"); |
|
|
} |
|
|
}); |
|
|
} |
|
|
}); |
|
|
return ini; |
|
|
return ini.join(""); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
exports.encode = exports.stringify; |
|
|
exports.encode = exports.stringify; |
|
|