MCPcopy Create free account
hub / github.com/unconed/TermKit / parseParams

Function parseParams

HTML/external/syntaxhighlighter_3.0.83/src/shCore.js:739–774  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

737 * @return {Object} Returns deserialized object.
738 */
739function 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.

Callers 1

shCore.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected