/*
Parses a string in order to substitue placeholders
with provided params object.

@param {String} originalString
@param {Object} params
@return {String} substituted string
486651
function substitute(originalString, params) {
	"use strict";

	var result = originalString;
	if (params) {
		Object.keys(params).forEach(function(key) {
			result = result.replace(new RegExp('{' + key + '}', 'g'), params[key]);
		});
	}
	return result;
}
748557
function normaliseParams(params) {
			if (typeof params === 'string') {
				params = params.split(' ');
			}
			else if (!$.isArray(params)) {
				var opts = [];
				for (var name in params) {
					opts[0] = name;
					opts[1] = params[name];
				}
				params = opts;
			}
			return params;
		}
1269754
function pickParams(params, keys) {
    params = _.cloneDeep(params);
    // decamelize all options
    for (var key in params) {
        var value = params[key];
        delete params[key];
        // TODO: handle this inconsistency consistently in the library :(
        // 'base64String': introduced by 'image.upload()'
        if (["base64String"].indexOf(key) === -1) {
            key = decamelize(key, "_");
        }
        params[key] = value;
    }
    if (SETTINGS.enforce_params_filter) {
        return _.pick(params, keys);
    }
    return params;
}
196941
function (param) {
        var split = param.split('='),
            key, value;
        key = split[0].trim();
        value = (split[1]) ? split[1].trim() : true;

        if (_.isString(value) && value[0] === '"') {
            value = value.slice(1, -1);
        }

        return { key: key, value: value };
    }
1190704
function parsePlaceholders (source) {
  return source.match(/\([^\)]+\)/g).reduce(function (result, placeholder) {
    placeholder = placeholder.replace(/^\(([^\)]+)\)$/, '$1');
    var keyValue = placeholder.split(':');
    result[keyValue[0]] = {
      content: keyValue[1]
    };
    return result;
  }, {});
}
1174952
function regexFromString(string) {
  var r = /::|\*\*|:[a-zA-Z_]+|\*/g;
  var match;
  var regexString = '^';
  var previousIndex = 0;
  var regexKeys = [];
  var starKey = 0;
  while ((match = r.exec(string)) !== null) {
    var matched = match[0];
    var index = match.index;
    regexString += escapeRegex(string.slice(previousIndex, index));
    previousIndex = index;
    if (matched === '**') {
      regexString += '\\*\\*';
      previousIndex += 2;
    } else if (matched === '::') {
      regexString += '::';
      previousIndex += 2;
    } else if (matched === '*') {
      regexString += '(.*)';
      regexKeys.push(starKey);
      previousIndex += 1;
      starKey++;
    } else {  // :foo
      regexString += '([^/]+)';
      regexKeys.push(matched.slice(1));
      previousIndex += matched.length;
    }
  }
  regexString += escapeRegex(string.slice(previousIndex)) + '$';
  var regex = new RegExp(regexString);
  regex.keys = regexKeys;
  return regex;
}
57649
function(str, obj) {
    var replacer = function(wholeMatch, key) {
      return obj[key] === undefined ? wholeMatch : obj[key];
    },
    regexp = new RegExp('{{\\s*([a-z0-9-_]+)\\s*}}',"ig");

    for(var beforeReplace = ""; beforeReplace !== str; str = (beforeReplace = str).replace(regexp, replacer)){

    }
    return str;
  }
458998
function _parseParams(params) {
  return params.map((param) => {
    let result;
    switch (param.type) {
      case 'Identifier':
        result = new Param(param.name);
        break;
      case 'AssignmentPattern':
        result = new Param(param.left.name, true);
        break;
      case 'ObjectPattern': {
        const objParams = param.properties.map((objParam) => objParam.value);
        result = new Param('arguments', false, _parseParams(objParams));
        break;
      }
      default:
    }
    return result;
  });
}
281813
function parseString(str, options){
  var ret = reduce(String(str).split(options.separator), function(ret, pair){
    var eql = indexOf(pair, '=')
      , brace = lastBraceInKey(pair)
      , key = pair.substr(0, brace || eql)
      , val = pair.substr(brace || eql, pair.length)
      , val = val.substr(indexOf(val, '=') + 1, val.length);

    // ?foo
    if ('' == key) key = pair, val = '';
    if ('' == key) return ret;

    return merge(ret, decode(key), decode(val));
  }, { base: {} }).base;

  return compact(ret);
}
679712
function replace(translation, replacements) {
    // check if the object has a replace property
    if (!translation.replace) {
      return translation;
    }

    return translation.replace(matcher, function (placeholder) {
      // remove the identifiers (can be set on the module level)
      var key = placeholder.replace(identifiers[0], '').replace(identifiers[1], '');

      if (replacements[key] !== undefined) {
        return replacements[key];
      } // warn user that the placeholder has not been found


      if (warnings) {
        console.group ? console.group('i18n: Not all placeholders found') : console.warn('i18n: Not all placeholders found');
        console.warn('Text:', translation);
        console.warn('Placeholder:', placeholder);

        if (console.groupEnd) {
          console.groupEnd();
        }
      } // return the original placeholder


      return placeholder;
    });
  }
1345038
function parseParamString(paramString) {
    var obj = {};

    if ( typeof paramString !== "undefined" ){
        paramString
            .substring(1, paramString.length - 1) //strip off { and }
            .replace(/([a-zA-z-]+)=(.*?)(, |$)/g, function(_, header, val) {
              //Force "true" and "false" into Boolean
              if (val === "true") val = true;
              if (val === "false") val = false;

              obj[header.toLowerCase()] = val;
            });
    }

    return obj;
}
949169
def with_params(self, params):
        
        return self.replace(params=_merge_maps(self.params, params))
925352
function formatParams_(params) {
  var query = '';
  if (params) {
    params.f = params.f || 'json';
    for (var x in params) {
      if (params.hasOwnProperty(x) && params[x] !== null && params[x] !== undefined) { // wont sent undefined.
        //jslint complaint about escape cause NN does not support it.
        var val = formatRequestString_(params[x]); 
        query += (query.length > 0?'&':'')+(x + '=' + (escape ? escape(val) : encodeURIComponent(val)));
      }
    }
  }
  return query;
}
695397
function paramsToString (params) {
  const paramKvs = keys(mapKeys(params, (v, k) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`))
  return join(paramKvs.sort(), '&')
}
569705
function paramify(fn){
  //get arguments to function as array of strings
  var args=fn.args=fn.args||      //cache result in args property of function
      fn.toString()               //get string version of function
      .replace(/\/\/.*$|\/\*[\s\S]*?\*\//mg, '')   //strip comments
      .match(/\(.*?\)/m)[0]       //find argument list, including parens
      .match(/[^\s(),]+/g)        //find arguments
  ;
  return args; // or fn?
}
757656
function replacePlaceholder(str, value, _state) {
	if (typeof str === 'string') {
		const ranges = findUnescapedTokens(str, placeholder);
		if (ranges.length) {
			if (_state) {
				_state.replaced = true;
			}

			str = replaceRanges(str, ranges, value);
		}
	}

	return str;
}
478869
public static String regexpReplace(String str, String regex, String replacement) {
		if (regex.isEmpty()) {
			return str;
		}
		try {
			// we should use StringBuffer here because Matcher only accept it
			StringBuffer sb = new StringBuffer();
			Matcher m = REGEXP_PATTERN_CACHE.get(regex).matcher(str);
			while (m.find()) {
				m.appendReplacement(sb, replacement);
			}
			m.appendTail(sb);
			return sb.toString();
		} catch (Exception e) {
			LOG.error(
				String.format("Exception in regexpReplace('%s', '%s', '%s')", str, regex, replacement),
				e);
			// return null if exception in regex replace
			return null;
		}
	}