<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
I think I’m missing something. Why wouldn’t you just;
<div><br>
</div>
<div><font face="Consolas">import java.lang.StringTemplate.Processor;<br>
</font>
<div><font face="Consolas"><br>
</font></div>
<div>
<div><font face="Consolas">Processor<URL, RuntimeException> urlEncode = template -> URLEncoder.encode(template.interpolate(), UTF_8));</font></div>
<div><font face="Consolas"><br>
</font></div>
<div><font face="Consolas">Processor<String, RuntimeException> CSV = template -> StringEscapeUtils.<a href="https://commons.apache.org/proper/commons-lang/apidocs/src-html/org/apache/commons/lang3/StringEscapeUtils.html#line.768" style="caret-color: rgb(53, 56, 51); font-size: 14px; background-color: rgb(255, 255, 255); text-decoration: none; color: rgb(74, 103, 130);">escapeCsv</a>(template.interpolate());<br>
</font><br>
</div>
<div><br>
<div></div>
</div>
<blockquote type="cite">
<div>
<div>On Oct 26, 2023, at 4:47 PM, Rob Spoor <openjdk@icemanx.nl> wrote:</div>
<br class="Apple-interchange-newline">
<div>
<div>I've been reading up on string templates, and I think it's a very cool feature. However, writing a custom processor can be a lot of copy-paste work if you want STR but with some extra translation applied. For instance, if I'd want to have a URL encoding
 processor I would have to write everything from scratch.<br>
<br>
I think it would be useful to overload interpolate (both static and non-static) with a custom Function<Object, String> as additional arguments. This would work like STR if that provided String::valueOf as function.<br>
<br>
With this method, creating a URL encoding processor would be as simple as this:<br>
<br>
   var urlEncode = template -> template.interpolate(o -><br>
           URLEncoder.encode(String.valueOf(o), UTF_8));<br>
<br>
   var url = urlEncode."https://host/path/\{id}?param=\{value\}";<br>
<br>
<br>
Likewise, a processor backed by Apache Commons Text's StringEscapeUtils would now be just as simple:<br>
<br>
   var CSV = template -> template.interpolate(o -><br>
           StringEscapeUtils.ESCAPE_CSV.translate(String.valueOf(o));<br>
<br>
   var csv = CSV."""<br>
           Header1, Header2, Header3<br>
           "\{value1}", "\{value2}", "\{value3}"<br>
           """;<br>
<br>
<br>
If the JVM allows it, the existing interpolate method can even delegate to the new overload providing String::valueOf.<br>
</div>
</div>
</div>
<br>
</blockquote>
</div>
</div>
</body>
</html>