WMS_MAIN/temp_find_headers_close.js
2026-04-27 16:09:26 +08:00

16 lines
688 B
JavaScript

const fs = require('fs');
const s = fs.readFileSync('methods/system.json', 'utf8');
function isEscaped(str, idx) { let cnt = 0; let j = idx - 1; while (j >= 0 && str[j] == '\\') { cnt++; j--; } return cnt % 2 === 1; }
const ph = s.indexOf('"headers"');
const posOpen = s.indexOf('[', ph);
let depth = 0; let inStr = false; let posClose = -1;
for (let i = posOpen; i < s.length; i++) {
const c = s[i];
if (c == '"' && !isEscaped(s, i)) inStr = !inStr;
if (inStr) continue;
if (c == '[') depth++;
else if (c == ']') { depth--; if (depth === 0) { posClose = i; break; } }
}
console.log('posOpen', posOpen, 'posClose', posClose);
console.log(s.slice(posClose - 40, posClose + 40));