/** * The MIT License (MIT) * * Copyright (c) 2014 Gabriel Llamas * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ "use strict"; var hex = function (c){ switch (c){ case "0": return 0; case "1": return 1; case "2": return 2; case "3": return 3; case "4": return 4; case "5": return 5; case "6": return 6; case "7": return 7; case "8": return 8; case "9": return 9; case "a": case "A": return 10; case "b": case "B": return 11; case "c": case "C": return 12; case "d": case "D": return 13; case "e": case "E": return 14; case "f": case "F": return 15; } }; var parse = function (data, options, handlers, control){ var c; var code; var escape; var skipSpace = true; var isCommentLine; var isSectionLine; var newLine = true; var multiLine; var isKey = true; var key = ""; var value = ""; var section; var unicode; var unicodeRemaining; var escapingUnicode; var keySpace; var sep; var ignoreLine; var line = function (){ if (key || value || sep){ handlers.line (key, value); key = ""; value = ""; sep = false; } }; var escapeString = function (key, c, code){ if (escapingUnicode && unicodeRemaining){ unicode = (unicode << 4) + hex (c); if (--unicodeRemaining) return key; escape = false; escapingUnicode = false; return key + String.fromCharCode (unicode); } //code 117: u if (code === 117){ unicode = 0; escapingUnicode = true; unicodeRemaining = 4; return key; } escape = false; //code 116: t //code 114: r //code 110: n //code 102: f if (code === 116) return key + "\t"; else if (code === 114) return key + "\r"; else if (code === 110) return key + "\n"; else if (code === 102) return key + "\f"; return key + c; }; var isComment; var isSeparator; if (options._strict){ isComment = function (c, code, options){ return options._comments[c]; }; isSeparator = function (c, code, options){ return options._separators[c]; }; }else{ isComment = function (c, code, options){ //code 35: # //code 33: ! return code === 35 || code === 33 || options._comments[c]; }; isSeparator = function (c, code, options){ //code 61: = //code 58: : return code === 61 || code === 58 || options._separators[c]; }; } for (var i=~~control.resume; i 1 || code < 33 || code > 126){ throw new Error ("The comment token must be a single printable ASCII " + "character"); } c[comment] = true; }); options._comments = c; var separators = options.separators || []; if (!Array.isArray (separators)) separators = [separators]; var s = {}; separators.forEach (function (separator){ code = separator.charCodeAt (0); if (separator.length > 1 || code < 33 || code > 126){ throw new Error ("The separator token must be a single printable ASCII " + "character"); } s[separator] = true; }); options._separators = s; if (options.path){ if (!cb) throw new Error ("A callback must be passed if the 'path' " + "option is enabled"); if (options.include){ read (data, options, cb); }else{ fs.readFile (data, { encoding: "utf8" }, function (error, data){ if (error) return cb (error); build (data, options, ".", cb); }); } }else{ return build (data, options, ".", cb); } };