js 解析 ini 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// 解析 ini 文件
function splitLines(string){
return string.split(/\r?\n/);
}


function parseINI(string){
var lines = splitLines(string);
var categories = [];

function newCategory(name){
var cat = {name: name, fields: []};
categories.push(cat);
return cat;
}

var currentCategory = newCategory("TOP");

forEach(lines, function(line){
var match;
if (/^\s*(;.*)?$/.test(line)){
return;
}
else if (match = line.match(/^\[(.*)\]$/)){
currentCategory = newCategory(match[1]);
}
else if (match = line.match(/^(\w+)=(.*)$/)){
currentCategory.fields.puch({name: match[1], value: match[2]});
}
else{
throw new Error("Invalid line: " + line);
}
});

return categories;
}

js 解析 ini 文件
https://ccw1078.github.io/2017/11/12/js 解析 ini 文件/
作者
ccw
发布于
2017年11月12日
许可协议