From a12bd0e4273328ae75cee3339e0dbe17ff31efed Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 12 Aug 2015 12:32:04 +0200 Subject: [PATCH] Added optional tilde expansion Tilde is often used as a non-breaking space, but what exactly that means depends on context. Therefore, a tilde expands to itself by default and the expansion can be changed via $T::tilde. Inspired by a patch from KSP repository. --- UCW/Temple.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/UCW/Temple.pm b/UCW/Temple.pm index 0c6b29a..99a2d15 100644 --- a/UCW/Temple.pm +++ b/UCW/Temple.pm @@ -162,8 +162,13 @@ sub parse_string($$) { pos $t = 0; for (;;) { $current_pos = pos $t; - if ($t =~ /\G([^\@]+)/cgs) { + # Scan for the first occurrence of an active character ("@", "~") + if ($t =~ /\G([^\@~]+)/cgs) { out $1 if $cond[0] > 0; + } elsif ($t =~ /\G~/cgs) { + out $T::tilde if $cond[0] > 0; + } elsif ($t =~ /\G\@~/cgs) { + out "~" if $cond[0] > 0; } elsif ($t =~ /\G\@\s*\n/cgs) { # @ at end of line is ignored and eats the end of line } elsif ($t =~ /\G\@#[^\n]*\n/cgs) { @@ -247,6 +252,7 @@ import UCW::Temple; our $temp; our $out_func = sub { print @_; }; +our $tilde = '~'; sub include { my $fn = shift @_; -- 2.39.2