[ 
https://issues.apache.org/jira/browse/TEXT-127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16561581#comment-16561581
 ] 

Jean-Baptiste REICH commented on TEXT-127:
------------------------------------------

My purpose is to manage this kind of use case:

Assuming that ${var} is unknown when I have this:

 
{code:java}
String templateString = "Current behavior: $${var} ${var}.";{code}
 

This results in

 
{code:java}
String replacedString = "Current behavior: ${var} ${var}.";{code}
 

So I would like to avoid using an unknown variable. For this, I would like to 
have this behavior:
{code:java}
String templateString = "Var is unknown: $${var} ${var}.";
 ==> throws an exception{code}
{code:java}
String templateString = "Var is unknown: $${var} ${var:-value1}.";
String replacedString = "Var is unknown: ${var} value1.";{code}
{code:java}
String templateString = "Var is known and equals to value2: $${var} ${var}.";
String replacedString = "Var is known and equals to value2: ${var} 
value2.";{code}
{code:java}
String templateString = "Var is known and equals to value2: $${var} 
${var:-value1}.";
String replacedString = "Var is known and equals to value2: ${var} 
value2.";{code}
Thank you

> Detect when a variable is unknown in StringSubstitutor
> ------------------------------------------------------
>
>                 Key: TEXT-127
>                 URL: https://issues.apache.org/jira/browse/TEXT-127
>             Project: Commons Text
>          Issue Type: Improvement
>            Reporter: Jean-Baptiste REICH
>            Priority: Minor
>
> Currently, StringSubstitutor is not replacing a variable that is unknown. It 
> would be nice to define the behavior in this case and to allow raising an 
> exception.
> A workaround is to define a custom StringLookup that raises an exception when 
> the variable is unknown but this prevent from using the default value feature 
> from StringSubstitutor



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to