Replace certain keys with respective values in a string.
    @param template: the string in which replacements should be made
    @param replacements: a dict or a list of pairs of keys and values
498783
def substitute_vars(template, replacements):
    
    result = template
    for (key, value) in replacements:
        result = result.replace('${' + key + '}' , value)
    if '${' in result:
        logging.warning("A variable was not replaced in '%s'.", result)
    return result
1213533
public function replaceTemplateTypesWithStandins(
        array &$template_types,
        array &$generic_params,
        Codebase $codebase = null,
        Type\Atomic $input_type = null,
        bool $replace = true,
        bool $add_upper_bound = false,
        int $depth = 0
    ) {
        // do nothing
    }
186712
private void replaceStringsWithAliases() {
    for (Entry<String, StringInfo> entry : stringInfoMap.entrySet()) {
      String literal = entry.getKey();
      StringInfo info = entry.getValue();
      if (shouldReplaceWithAlias(literal, info)) {
        for (StringOccurrence occurrence : info.occurrences) {
          replaceStringWithAliasName(
              occurrence, info.getVariableName(literal), info);
        }
      }
    }
  }
268460
public void setTemplate(ElemTemplate template)
  {
    XPath matchXPath = template.getMatch();
    
    if (null == template.getName() && null == matchXPath)
    {  
      template.error(XSLTErrorResources.ER_NEED_NAME_OR_MATCH_ATTRIB,
          new Object[]{ "xsl:template" });
    }
    
    if (null != template.getName())
    {
      ElemTemplate existingTemplate = (ElemTemplate) m_namedTemplates.get(template.getName());
      if (null == existingTemplate)
      {
        m_namedTemplates.put(template.getName(), template);
      }
      else
      {
        int existingPrecedence =
                        existingTemplate.getStylesheetComposed().getImportCountComposed();
        int newPrecedence = template.getStylesheetComposed().getImportCountComposed();
        if (newPrecedence > existingPrecedence)
        {
          // This should never happen
          m_namedTemplates.put(template.getName(), template);
        }
        else if (newPrecedence == existingPrecedence)
          template.error(XSLTErrorResources.ER_DUPLICATE_NAMED_TEMPLATE,
                       new Object[]{ template.getName() });
      }
    }

    

    if (null != matchXPath)
    {
      Expression matchExpr = matchXPath.getExpression();

      if (matchExpr instanceof StepPattern)
      {
        insertPatternInTable((StepPattern) matchExpr, template);
      }
      else if (matchExpr instanceof UnionPattern)
      {
        UnionPattern upat = (UnionPattern) matchExpr;
        StepPattern[] pats = upat.getPatterns();
        int n = pats.length;

        for (int i = 0; i < n; i++)
        {
          insertPatternInTable(pats[i], template);
        }
      }
      else
      {

        // TODO: assert error
      }
    }
  }
438686
public static void print(String template, Object... values) {
		out.print(StrUtil.format(template, values));
	}
654286
public static String mergeFromTemplate(String template, Map<String, ?> values) {
        for (String param : values.keySet()) {
            template = template.replace("{{" + param + "}}", values.get(param) == null ? "" : values.get(param).toString());
        }
        return template.replaceAll("\n|\r|  ", "");
    }
548153
def multiple_replace(string, replacements):
    # type: (str, Dict[str,str]) -> str
    
    pattern = re.compile("|".join([re.escape(k) for k in sorted(replacements, key=len, reverse=True)]), flags=re.DOTALL)
    return pattern.sub(lambda x: replacements[x.group(0)], string)
828244
public static StringTemplate stringTemplate(Template template, List<?> args) {
        return new StringTemplate(template, ImmutableList.copyOf(args));
    }
1248285
public static StringTemplate stringTemplate(String template, List<?> args) {
        return stringTemplate(createTemplate(template), args);
    }
1298427
def get_template_substitution_values(self, value):
        
        return {
            'initial': os.path.basename(conditional_escape(value)),
            'initial_url': conditional_escape(value.url),
        }
1128908
def update_template(template,**kwargs):
    
    tmpl = db.DBSession.query(Template).filter(Template.id==template.id).one()
    tmpl.name = template.name
    if template.description:
        tmpl.description = template.description

    #Lazy load the rest of the template
    for tt in tmpl.templatetypes:
        for ta in tt.typeattrs:
            ta.attr

    if template.layout:
        tmpl.layout = get_layout_as_string(template.layout)

    type_dict = dict([(t.id, t) for t in tmpl.templatetypes])
    existing_templatetypes = []

    if template.types is not None or template.templatetypes is not None:
        types = template.types if template.types is not None else template.templatetypes
        for templatetype in types:
            if templatetype.id is not None:
                type_i = type_dict[templatetype.id]
                _update_templatetype(templatetype, type_i)
                existing_templatetypes.append(type_i.id)
            else:
                #Give it a template ID if it doesn't have one
                templatetype.template_id = template.id
                new_templatetype_i = _update_templatetype(templatetype)
                existing_templatetypes.append(new_templatetype_i.id)

    for tt in tmpl.templatetypes:
        if tt.id not in existing_templatetypes:
            delete_templatetype(tt.id)

    db.DBSession.flush()

    return tmpl
1034150
function format(template, values) {
	return Object
		.entries(values)
		.filter(
			([key]) => /^[a-z0-9_-]+$/gi.test(key)
		)
		.map(
			([key, value]) =>
				[new RegExp(`([^{]|^){${key}}([^}]|$)`,'g'), `$1${value}$2`]
		)
		.reduce(
			(str, [regexp, replacement]) => {
				return str.replace(regexp, replacement)
			}, template
		)
		.replace(/({|}){2}/g, '$1')
}
344475
public void replace( String param, String value ) {
        int [] range;
        while ( (range = findTemplate( param )) != null )
            buff.replace( range[0], range[1], value );
    }
1100559
public static function renderTemplate($template, $replacements){
		foreach ($replacements as $find => $replace) {
			$template = \str_replace($find, $replace, $template);
		}
		return $template;
	}
648543
def expand(template, variables=None):
    
    if variables is None:
        variables = {}
    return patterns.sub(functools.partial(_replace, variables), template)
413660
protected function replaceVariablesInTemplate(string $template, array $variables) : string
    {
        $template = preg_replace_callback(
            '/\{\{\s*' . self::REGEX_VARIABLE . '\s*\}\}/i',
            function (array $matches) use ($variables): string {
                return (string) $this->getValue($matches, $variables);
            },
            $template
        );

        return $template;
    }
411191
protected void modifyTemplate(Template template, String key, HttpServletRequest request,
			HttpServletResponse response, Object... args)
	{

	}