You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Arend v. Reinersdorff (JIRA)" <ji...@apache.org> on 2013/01/18 22:04:12 UTC

[jira] [Created] (LANG-867) StrSubstitutor: Ability to turn off substitution in values

Arend v. Reinersdorff created LANG-867:
------------------------------------------

             Summary: StrSubstitutor: Ability to turn off substitution in values
                 Key: LANG-867
                 URL: https://issues.apache.org/jira/browse/LANG-867
             Project: Commons Lang
          Issue Type: Improvement
          Components: lang.text.*
            Reporter: Arend v. Reinersdorff
            Priority: Minor


In StrSubstitutor variable replacement works in a recursive way. And currently there's no way to turn this off.

Why turn it off: I want to replace some variables in a simple template. Some of the replacemnt values are arbitrary user input.

At the moment I escape all dollar signs in the replacement values with "$$". This is annoying. Especially as I use one template with variables as a value for another variable. Here I have to escape twice.

Here's some example code. At the moment it prints "Hello world". The commented line is my suggestion for this feature. If it works, it should print "Hello ${key2}":

    Map<String, String> valueMap = new HashMap<>();
    valueMap.put("key", "$${key2}");
    valueMap.put("key2", "world");

    String source = "Hello ${key}";

    StrSubstitutor strSubstitutor = new StrSubstitutor(valueMap);
    // strSubstitutor.setEnableSubstitutionInValues(false);
    System.out.println(strSubstitutor.replace(source));


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira