-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathline2xml.js
More file actions
33 lines (28 loc) · 807 Bytes
/
line2xml.js
File metadata and controls
33 lines (28 loc) · 807 Bytes
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
var xml2js = require("xml2js");
process.stdin.on('readable', function() {
var chunk = process.stdin.read();
if (chunk !== null) {
parseLine(chunk);
}
});
function parseLine (line) {
if (line.charAt(line.length-1) == "\n") line = line.slice(0, -1);
}
function cutCommand(line, index){
//console.log("cutCommand", line, index);
if (index == undefined) index = 0;
var i = 0;
var sp_index = 0;
var sp_index_old = 0;
while (i <= index && sp_index > -1) {
sp_index_old = sp_index;
sp_index = line.indexOf(" ", sp_index_old+1);
i++;
}
var res;
if (sp_index > -1) res = line.slice(sp_index_old, sp_index);
else res = line.slice (sp_index_old);
//console.log("cutCommand", index, i, sp_index_old, sp_index, res);
if (res.charAt(0) == " ") res = res.slice(1);
return res;
}