From: Martin Mares Date: Wed, 12 Aug 2015 10:32:04 +0000 (+0200) Subject: Added optional tilde expansion X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=a12bd0e4273328ae75cee3339e0dbe17ff31efed;p=temple.git 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. --- 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 @_;