Silly and likely non-important question about StringTemplates.

David Alayachew davidalayachew at gmail.com
Mon Oct 23 13:53:16 UTC 2023


Ah yes, thank you very much.

The beauty of this is that, if I had caught that error later, only one
place in my code needs to change. Everything would flow through that.

A shame that I can't signify this with some type, so that I know that the
String has already been SWING_HTML'ified (in the vein of Lexi Lambda's "Parse,
don't validate"
<https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/>). I
could wrap it in a wrapper, but I can't put the wrapper into my JLabel.

On Mon, Oct 23, 2023 at 9:08 AM <forax at univ-mlv.fr> wrote:

>
>
> ------------------------------
>
> *From: *"David Alayachew" <davidalayachew at gmail.com>
> *To: *"Remi Forax" <forax at univ-mlv.fr>
> *Cc: *"amber-dev" <amber-dev at openjdk.org>
> *Sent: *Monday, October 23, 2023 3:01:32 PM
> *Subject: *Re: Silly and likely non-important question about
> StringTemplates.
>
> 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.
>
>
> Hello,
> don't forget to escape <, > et & correctly.
>
>
> Thank you for your time and help!
> David Alayachew
>
>
> regards,
> Rémi
>
>
>
> 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/c215ddc9/attachment-0001.htm>


More information about the amber-dev mailing list