]> mj.ucw.cz Git - temple.git/commitdiff
Added optional tilde expansion
authorMartin Mares <mj@ucw.cz>
Wed, 12 Aug 2015 10:32:04 +0000 (12:32 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 12 Aug 2015 10:32:04 +0000 (12:32 +0200)
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

index 0c6b29a859d0422fb0ea16317a3f830246d9fa95..99a2d15d610202a17489ce03010e40b02449309b 100644 (file)
@@ -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 @_;