Found the solution: make the necessary replacements (so that the string has the desired
[\#amp#],
[\38] and
[\26] in it after the substitution), then
use the substitute result in a bang.
Only when used in a bang (and probably in a measure or a new variable as well) the above replacements are "unescaped" and the end result becomes the expected
Me & you & him & everybody went for a walk.
Finally I can make a
DecodeCharacterReference-like
Substitute statement to handle single or
multiple HTML/XML character reference encoding
at the moment I choose and
in whichever measure I choose (not just a WebParser measure) in
just a few steps and without parsing the string thousands of times replacing each codepoint separately. Of course, a few hundred variables like
amp or
comma below are needed, but this should be both fast and effective:
Code: Select all
[Variables]
amp=38
comma=44
[Rainmeter]
AccurateText=1
Update=1000
DynamicWindowSize=1
[MS_SourceString]
Measure=String
String="Me, & you, & him, & everybody went for a walk."
DynamicVariables=1
[MS_ResultString1]
Measure=String
String=[MS_SourceString]
UpdateDivider=-1
RegExpSubstitute=1
Substitute="(?s)&(?:amp|AMP|#0*38|(?i)#x0*26);":"&"
DynamicVariables=1
[MS_ResultString2]
Measure=String
String=[MS_SourceString]
UpdateDivider=-1
RegExpSubstitute=1
Substitute="&(\w+);":"[\#\1#]","&#?(\w+);":"[\\1]"
OnUpdateAction=[!SetOption MS_ResultString3 String [MS_ResultString2]]
DynamicVariables=1
[MS_ResultString3]
Measure=String
String=
UpdateDivider=-1
DynamicVariables=1
[MT_Test]
Meter=STRING
SolidColor=64,64,64,255
FontColor=255,255,255,255
MeasureName=MS_SourceString
MeasureName2=MS_ResultString1
MeasureName3=MS_ResultString2
MeasureName4=MS_ResultString3
Text="Source: %1#CRLF#Result1: %2#CRLF#Result2: %3#CRLF#Result3: %4"
DynamicVariables=1