toolkit/crashreporter/KeyValueParser.jsm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 6
michael@0 7 this.EXPORTED_SYMBOLS = [
michael@0 8 "parseKeyValuePairs",
michael@0 9 "parseKeyValuePairsFromFile"
michael@0 10 ];
michael@0 11
michael@0 12 const Cc = Components.classes;
michael@0 13 const Ci = Components.interfaces;
michael@0 14
michael@0 15 this.parseKeyValuePairs = function parseKeyValuePairs(text) {
michael@0 16 let lines = text.split('\n');
michael@0 17 let data = {};
michael@0 18 for (let i = 0; i < lines.length; i++) {
michael@0 19 if (lines[i] == '')
michael@0 20 continue;
michael@0 21
michael@0 22 // can't just .split() because the value might contain = characters
michael@0 23 let eq = lines[i].indexOf('=');
michael@0 24 if (eq != -1) {
michael@0 25 let [key, value] = [lines[i].substring(0, eq),
michael@0 26 lines[i].substring(eq + 1)];
michael@0 27 if (key && value)
michael@0 28 data[key] = value.replace(/\\n/g, "\n").replace(/\\\\/g, "\\");
michael@0 29 }
michael@0 30 }
michael@0 31 return data;
michael@0 32 }
michael@0 33
michael@0 34 this.parseKeyValuePairsFromFile = function parseKeyValuePairsFromFile(file) {
michael@0 35 let fstream = Cc["@mozilla.org/network/file-input-stream;1"].
michael@0 36 createInstance(Ci.nsIFileInputStream);
michael@0 37 fstream.init(file, -1, 0, 0);
michael@0 38 let is = Cc["@mozilla.org/intl/converter-input-stream;1"].
michael@0 39 createInstance(Ci.nsIConverterInputStream);
michael@0 40 is.init(fstream, "UTF-8", 1024, Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
michael@0 41 let str = {};
michael@0 42 let contents = '';
michael@0 43 while (is.readString(4096, str) != 0) {
michael@0 44 contents += str.value;
michael@0 45 }
michael@0 46 is.close();
michael@0 47 fstream.close();
michael@0 48 return parseKeyValuePairs(contents);
michael@0 49 }

mercurial