Silly and likely non-important question about StringTemplates.

David Alayachew davidalayachew at gmail.com
Mon Oct 23 13:01:32 UTC 2023


Hello Rémi,

Thank you for your response!

I am making a SWING_HTML String Template Processor that turns basic
multi-line strings into ones that are <html> enclosed, and replace new
lines with <br>. So, for me, most of my Strings are already made, and thus,
don't need to have anything "inserted" into them.

   private static final Processor<String, RuntimeException> SWING_HTML =
      st ->
         "<html>"
         +
         st
            .interpolate()
            .lines()
            .collect(java.util.stream.Collectors.joining("<br>"))
         +
         "</html>"
         ;

It would be nice if Java put this particular processor into the Swing
library itself at some point. But it's easy enough for me to implement
myself, which is a nice thing about String Templates. Plus, this feature
composes -- I can make an italics or bold processor that can translate to
the various html tags that Swing supports. And it's safer than just putting
in the tags myself because the curly braces will turn into compiler errors
if I don't align them correctly. Plus, curly braces are a syntax feature,
so most ide's (even VIM and EMACS!) will give you hints about where your
curly braces are, making it much easier to trace issues with this.

Thank you for your time and help!
David Alayachew

On Mon, Oct 23, 2023 at 1:06 AM Remi Forax <forax at univ-mlv.fr> wrote:

>
>
> ------------------------------
>
> *From: *"David Alayachew" <davidalayachew at gmail.com>
> *To: *"amber-dev" <amber-dev at openjdk.org>
> *Sent: *Monday, October 23, 2023 6:35:00 AM
> *Subject: *Silly and likely non-important question about StringTemplates.
>
> Hello Amber Dev Team,
>
> I've been playing with StringTemplates a bit more, and I had a quick
> question.
>
> I repeatedly find myself in the same situation -- I have a String that is
> already in a variable, and I want it to be the full String in the
> StringTemplate. What is the recommended way to do it?
>
> For example.
>
> String abc = "xyz";
> MY_PROCESSOR. <--- what goes here?
>
>
> MY_PROCESSOR."\{abc}"
>
>
> Thank you for your time!
> David Alayachew
>
>
> regards,
> Rémi
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20231023/1b0b1828/attachment.htm>


More information about the amber-dev mailing list