mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
976983960d
Update the ini parser to support some more whitespace cases, turn lines without an equal sign into a "flag" that's just true if set, and support comments.
30 lines
644 B
JavaScript
30 lines
644 B
JavaScript
exports.parse = function(d) {
|
|
var ini = {'-':{}};
|
|
|
|
var section = '-';
|
|
|
|
var lines = d.split('\n');
|
|
for (var i=0; i<lines.length; i++) {
|
|
var line = lines[i].trim(),
|
|
rem = line.indexOf(";");
|
|
|
|
if (rem !== -1) line = line.substr(0, rem);
|
|
|
|
var re = /^\[([^\]]*)\]$|^([^=]+)(=(.*))?$/i;
|
|
|
|
var match = line.match(re);
|
|
if (match != null) {
|
|
if (match[1] != undefined) {
|
|
section = match[1].trim();
|
|
ini[section] = {};
|
|
} else {
|
|
var key = match[2].trim(),
|
|
value = (match[3]) ? (match[4] || "").trim() : true;
|
|
ini[section][key] = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
return ini;
|
|
}
|