chrisrueger commented on PR #111:
URL: https://github.com/apache/freemarker/pull/111#issuecomment-2253057806

   Thanks for your remarks. Just to add , since I have not written it 
explicitly: Basically I was only looking for the equivalent of Apache Commons 
[StringUtils.isBlank(...)](https://github.com/apache/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/StringUtils.java#L3623)
  but as a FM built-in. Just because it is a check people often need. 
   
   We already know `??` and `!` and use it. Usually our templates are full of 
`!` (maybe not always the most elegant, but easier for most our users to ignore 
null and just have it an empty string) 
   
   `someString!?is_blank` appeared to be a bit more descriptive (given the 
meaning of "blank" vs. "empty" is known to the template author). So somebody 
came to me asking if there is a `?is_blank` built-in. 
   I said, no, but we could create our own `${isBlank(string)}` template 
function - but a built-in seemed nicer. Just how it came to this PR .
   
    
   
   
   
   > And also, sometimes you want to treat a blank `s` as if it was `null`, 
because really it should be `null`, but the data source you receive it from 
doesn't normalize it.
   
   True, but that was not my intention with "is_blank". 
   
   This sounds like Apache 
[StringUtils.trimToNull(...)](https://github.com/apache/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/StringUtils.java#L9124)
 
   
   We sometimes get data (from who knows where) and we need to ask the question 
**in the template** "does this field contain only spaces"? 
   
   we usually do:
   
   `<#if firstName!?trim != "">do something</#if>`
   
   or
   
   `<#if firstName?? && firstName?trim != "">
   do some larger stuff like creating an XML-fragment...
   </#if>`
   
   We thought that 
   
   `<#if firstName!?is_blank>do something</#if>` is more descriptive. 
   
   Anyway I can try adding also `?blank_to_null` if you think this should also 
be there. 
   
   Sorry maybe I just thought too simplistic :)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to