//-- //-- Augmented methods for the JavaScript String() object //-- // Get characters from the right end of a string String.prototype.right = function(n) { return n < this.length ? this.slice(this.length-n) : this; }; // Trim whitespace from both ends of a string String.prototype.trim = function() { return this.replace(/^\s*|\s*$/g,""); }; // Convert a string from a CSS style property name to a JavaScript style name ("background-color" -> "backgroundColor") String.prototype.unDash = function() { var t,s = this.split("-"); if(s.length > 1) { for(t=1; t currPos) r.push(this.substring(currPos,match.index)); r.push(substrings[parseInt(match[1],10)]); currPos = subRegExp.lastIndex; } } while(match); if(currPos < this.length) r.push(this.substring(currPos,this.length)); return r.join(""); }; // Escape any special RegExp characters with that character preceded by a backslash String.prototype.escapeRegExp = function() { var s = "\\^$*+?()=!|,{}[]."; var t,c = this; for(t=0; t to ">" and " to """ String.prototype.htmlEncode = function() { return this.replace(/&/mg,"&").replace(//mg,">").replace(/\"/mg,"""); }; // Convert "&" to &, "<" to <, ">" to > and """ to " String.prototype.htmlDecode = function() { return this.replace(/</mg,"<").replace(/>/mg,">").replace(/"/mg,"\"").replace(/&/mg,"&"); }; // Parse a space-separated string of name:value parameters //# where: //# - the name or the value can be optional (in which case separate defaults are used instead) //# - in case of ambiguity, a lone word is taken to be a value //# - if 'cascadeDefaults' is set to true, then the defaults are modified by updated by each specified name or value //# - name prefixes are not allowed if the 'noNames' parameter is true //# - if both the name and value are present they must be separated by a colon //# - the name and the value may both be quoted with single- or double-quotes, double-square brackets //# - names or values quoted with {{double-curly braces}} are evaluated as a JavaScript expression //# - as long as the 'allowEval' parameter is true // The result is an array of objects: // result[0] = object with a member for each parameter name, value of that member being an array of values // result[1..n] = one object for each parameter, with 'name' and 'value' members String.prototype.parseParams = function(defaultName,defaultValue,allowEval,noNames,cascadeDefaults) { var parseToken = function(match,p) { var n; if(match[p]) // Double quoted n = match[p]; else if(match[p+1]) // Single quoted n = match[p+1]; else if(match[p+2]) // Double-square-bracket quoted n = match[p+2]; else if(match[p+3]) // Double-brace quoted try { n = match[p+3]; if(allowEval && config.evaluateMacroParameters != "none") { if(config.evaluateMacroParameters == "restricted") { if(window.restrictedEval) { n = window.restrictedEval(n); } } else { n = window.eval(n); } } } catch(ex) { throw "Unable to evaluate {{" + match[p+3] + "}}: " + exceptionText(ex); } else if(match[p+4]) // Unquoted n = match[p+4]; else if(match[p+5]) // empty quote n = ""; return n; }; var r = [{}]; var dblQuote = "(?:\"((?:(?:\\\\\")|[^\"])+)\")"; var sngQuote = "(?:'((?:(?:\\\\\')|[^'])+)')"; var dblSquare = "(?:\\[\\[((?:\\s|\\S)*?)\\]\\])"; var dblBrace = "(?:\\{\\{((?:\\s|\\S)*?)\\}\\})"; var unQuoted = noNames ? "([^\"'\\s]\\S*)" : "([^\"':\\s][^\\s:]*)"; var emptyQuote = "((?:\"\")|(?:''))"; var skipSpace = "(?:\\s*)"; var token = "(?:" + dblQuote + "|" + sngQuote + "|" + dblSquare + "|" + dblBrace + "|" + unQuoted + "|" + emptyQuote + ")"; var re = noNames ? new RegExp(token,"mg") : new RegExp(skipSpace + token + skipSpace + "(?:(\\:)" + skipSpace + token + ")?","mg"); var match; do { match = re.exec(this); if(match) { var n = parseToken(match,1); if(noNames) { r.push({name:"",value:n}); } else { var v = parseToken(match,8); if(v == null && defaultName) { v = n; n = defaultName; } else if(v == null && defaultValue) { v = defaultValue; } r.push({name:n,value:v}); if(cascadeDefaults) { defaultName = n; defaultValue = v; } } } } while(match); // Summarise parameters into first element var t; for(t=1; t