/* Hjson http://hjson.org */ "use strict"; var common=require("./hjson-common"); function makeComment(b, a, x) { var c; if (b) c={ b: b }; if (a) (c=c||{}).a=a; if (x) (c=c||{}).x=x; return c; } function extractComments(value, root) { if (value===null || typeof value!=='object') return; var comments=common.getComment(value); if (comments) common.removeComment(value); var i, length; // loop var any, res; if (Object.prototype.toString.apply(value) === '[object Array]') { res={ a: {} }; for (i=0, length=value.length; i0) { var text=rootComment(value, null, 1); text+="\n# Orphaned comments:\n"; dropped.forEach(function(c) { text+=("# "+c.path.join('/')+": "+mergeStr(c.b, c.a, c.e)).replace("\n", "\\n ")+"\n"; }); rootComment(value, text, 1); } } function saveComment(res, key, item, col) { var c=makeComment(item?item[0]:undefined, item?item[1]:undefined, col); if (c) res[key]=c; return c; } function droppedComment(path, c) { var res=makeComment(c.b, c.a); res.path=path; return res; } function dropAll(comments, dropped, path) { if (!comments) return; var i, length; // loop if (comments.a) { for (i=0, length=comments.a.length; i