Replace string in the template text

@param varMap variable map
@return replaced string
341218
public String replace(Map<String, String> varMap)
   {
      StringBuilder newString = new StringBuilder();

      int p = 0;
      int p0 = 0;
      while (true)
      {
         p = templateText.indexOf("${", p);
         if (p == -1)
         {
            newString.append(templateText.substring(p0, templateText.length()));
            break;
         }
         else
         {
            newString.append(templateText.substring(p0, p));
         }
         p0 = p;
         p = templateText.indexOf("}", p);
         if (p != -1)
         {
            String varName = templateText.substring(p0 + 2, p).trim();
            if (varMap.containsKey(varName))
            {
               newString.append(varMap.get(varName));
               p0 = p + 1;
            }
         }
      }
      return newString.toString();
   }
991409
function replaceInString(string, variables) {
    const model = createModel(string);
    let offset = 0;
    let output = '';

    for (let i = 0, il = model.variables.length; i < il; i++) {
        const v = model.variables[i];
        let value = v.name in variables ? variables[v.name] : v.name;
        if (typeof value === 'function') {
            value = value(model.string, v, offset + v.location);
        }

        output += model.string.slice(offset, v.location) + value;
        offset = v.location + v.length;
    }

    return output + model.string.slice(offset);
}
244624
public static <T extends ViewTraverse<T>> Map<String, Object> replaceDataReferences(
            final Map<String, Object> input,
            final T currentContext,
            final BiFunction<Integer, String, T> viewMap,
            final Converter<String, String> converter,
            final MultiDataContext<T, DataContext> data,
            boolean failOnUnexpanded,
            boolean blankIfUnexpanded
    )
    {
        final HashMap<String, Object> output = new HashMap<>();
        for (final String s : input.keySet()) {
            Object o = input.get(s);
            output.put(
                    s,
                    replaceDataReferencesInObject(o,
                                                  currentContext,
                                                  viewMap,
                                                  converter,
                                                  data,
                                                  failOnUnexpanded,
                                                  blankIfUnexpanded
                    )
            );
        }
        return output;
    }
402363
public static String replace(String string, Map<String,String> ht)
    {
        return Utility.replace(new StringBuilder(string), ht).toString();
    }
411944
def _replace_variables(data, variables):
    """"""
    formatter = string.Formatter()
    return [formatter.vformat(item, [], variables) for item in data]
84070
VariableMap getStringMap() {
    ImmutableMap.Builder<String, String> map = ImmutableMap.builder();
    for (Result result : Iterables.filter(results.values(), USED_RESULTS)) {
      map.put(result.replacement, result.original);
    }

    VariableMap stringMap = new VariableMap(map.build());
    return stringMap;
  }
284880
public static String replaceStrByMap(Map<String, String> requestParameters,
            String sourceContent) {

        String contentAfterReplace = sourceContent;

        for (Entry<String, String> entry : requestParameters.entrySet()) {

            String sourceContentHelperNew = contentAfterReplace;
            String varName = entry.getKey();
            String replacement = entry.getValue();

            if (varName.contains(PcConstants.NODE_REQUEST_PREFIX_REPLACE_VAR)) {

                String varTrueName = "$"
                        + varName
                                .replace(
                                        PcConstants.NODE_REQUEST_PREFIX_REPLACE_VAR,
                                        "");
                sourceContentHelperNew = contentAfterReplace.replace(
                        varTrueName, replacement);
                contentAfterReplace = sourceContentHelperNew;
            }

        }

        return contentAfterReplace;
    }
697325
public Assignment mapVariables(Map<Integer, Integer> varMap) {
    int[] newVarNums = new int[vars.length];
    Object[] newValues = new Object[vars.length];

    int numFilled = 0;
    for (int i = 0; i < vars.length; i++) {
      if (varMap.containsKey(vars[i])) {
        newVarNums[numFilled] = varMap.get(vars[i]);
        newValues[numFilled] = values[i];
        numFilled++;
      }
    }
    
    if (numFilled < newVarNums.length) {
      newVarNums = Arrays.copyOf(newVarNums, numFilled);
      newValues = Arrays.copyOf(newValues, numFilled);
    }
    return Assignment.fromUnsortedArrays(newVarNums, newValues);
  }
1238919
@Override
  public <O> O replaceTerms(Map substitutions) throws KbTypeException, CreateException {
    return wrapped().replaceTerms(substitutions);
  }
317191
public static function replaceTemplateVariables($string, $arrayOfVars)
    {
        self::$tempFV = $arrayOfVars;

        $ret = preg_replace_callback("/\%([A-Za-z]{1}[\w\-\_\:\.\[\]\=\#\~]+?)\%/",
                                     array('StringUtils', '_fvCallback'),
                                     $string);

        return $ret;
    }
500820
public static String strMapToStr(Map<String, String> map) {

        StringBuilder sb = new StringBuilder();

        if (map == null || map.isEmpty())
            return sb.toString();

        for (Entry<String, String> entry : map.entrySet()) {

            sb.append("< " + entry.getKey() + ", " + entry.getValue() + "> ");
        }
        return sb.toString();

    }
530915
@Nullable
    public static String replaceMacro( @CheckForNull String s, @Nonnull Map<String,String> properties) {
        return replaceMacro(s, new VariableResolver.ByMap<>(properties));
    }
701184
private void reusePreviouslyUsedVariableMap(SortedSet<Assignment> varsToRename) {
    // If prevUsedRenameMap had duplicate values then this pass would be
    // non-deterministic.
    // In such a case, the following will throw an IllegalArgumentException.
    checkNotNull(prevUsedRenameMap.getNewNameToOriginalNameMap());
    for (Assignment a : varsToRename) {
      String prevNewName = prevUsedRenameMap.lookupNewName(a.oldName);
      if (prevNewName == null || reservedNames.contains(prevNewName)) {
        continue;
      }

      if (a.isLocal
          || (!externNames.contains(a.oldName)
              && prevNewName.startsWith(prefix))) {
        reservedNames.add(prevNewName);
        finalizeNameAssignment(a, prevNewName);
      }
    }
  }
169187
public static String convert(final String text, final List<String> vars) {
		String[] array = new String[vars.size()];
		StringBuilder sb = new StringBuilder();
		convert(sb,text,vars.toArray(array));
		return sb.toString();
	}
832750
def replace_content(content, project_vars):
    

    for k, v in project_vars.items():
        content = content.replace(f'__{k}__', v)

    return content
1250349
public static Map<String, String> transformMap(final Map<String, Object> paramMap) {
        final Map<String, String> paramStrMap = new LinkedHashMap<String, String>();
        for (final Map.Entry<String, Object> entry : paramMap.entrySet()) {
            paramStrMap.put(entry.getKey(), entry.getValue().toString());
        }

        return paramStrMap;
    }
628932
public static String render(Template template, Map<String, Object> bindingMap) {
		template.binding(bindingMap);
		return template.render();
	}