* Parses key/value pairs into hash object. * * Understands the following formats: * - name: word; * - name: [word, word]; * - name: "string"; * - name: 'string'; * * For example: * name1: value; name2: [value, value]; name3: 'value' * * @param {String} str Input string. * @retu
(str)
| 737 | * @return {Object} Returns deserialized object. |
| 738 | */ |
| 739 | function parseParams(str) |
| 740 | { |
| 741 | var match, |
| 742 | result = {}, |
| 743 | arrayRegex = new XRegExp("^\\[(?<values>(.*?))\\]$"), |
| 744 | regex = new XRegExp( |
| 745 | "(?<name>[\\w-]+)" + |
| 746 | "\\s*:\\s*" + |
| 747 | "(?<value>" + |
| 748 | "[\\w-%#]+|" + // word |
| 749 | "\\[.*?\\]|" + // [] array |
| 750 | '".*?"|' + // "" string |
| 751 | "'.*?'" + // '' string |
| 752 | ")\\s*;?", |
| 753 | "g" |
| 754 | ) |
| 755 | ; |
| 756 | |
| 757 | while ((match = regex.exec(str)) != null) |
| 758 | { |
| 759 | var value = match.value |
| 760 | .replace(/^['"]|['"]$/g, '') // strip quotes from end of strings |
| 761 | ; |
| 762 | |
| 763 | // try to parse array value |
| 764 | if (value != null && arrayRegex.test(value)) |
| 765 | { |
| 766 | var m = arrayRegex.exec(value); |
| 767 | value = m.values.length > 0 ? m.values.split(/\s*,\s*/) : []; |
| 768 | } |
| 769 | |
| 770 | result[match.name] = value; |
| 771 | } |
| 772 | |
| 773 | return result; |
| 774 | }; |
| 775 | |
| 776 | /** |
| 777 | * Wraps each line of the string into <code/> tag with given style applied to it. |