Revision 1c9aacf6
Von Moritz Bunkus vor mehr als 15 Jahren hinzugefügt
SL/Template.pm | ||
---|---|---|
336 | 336 |
$new_contents .= $self->substitute_vars(substr($contents, 0, $pos_if), @indices); |
337 | 337 |
substr($contents, 0, $pos_if) = ""; |
338 | 338 |
|
339 |
if ($contents !~ m|^$self->{tag_start_qm}if\s*(not)?\s+(.*?)$self->{tag_end_qm}|) { |
|
339 |
# if ($contents !~ m|^$self->{tag_start_qm}if\s*(not)?\s+(.*?)$self->{tag_end_qm}|) { |
|
340 |
if ($contents !~ m/^$self->{tag_start_qm} |
|
341 |
\s* |
|
342 |
(not|\!)? # $1 -- Eventuelle Negierung |
|
343 |
\s* |
|
344 |
([^\s]+) # $2 -- Name der zu ?berpr?fenden Variablen |
|
345 |
( # $3 -- Beginn des optionalen Vergleiches |
|
346 |
\s* |
|
347 |
([!=])= # $4 -- Art des Vergleiches speichern |
|
348 |
\s* |
|
349 |
( # $5 -- Gequoteter String oder Bareword |
|
350 |
"(.*)(?<!\\)" # $6 -- Gequoteter String -- direkter Vergleich mit eq bzw. ne; Escapete Anf?hrungs als Teil des Strings belassen |
|
351 |
| |
|
352 |
([^\s]+) # $7 -- Bareword -- als Index f?r $form benutzen |
|
353 |
) |
|
354 |
)? |
|
355 |
\s* |
|
356 |
$self->{tag_end_qm} |
|
357 |
/x) { |
|
340 | 358 |
$self->{"error"} = "Malformed $self->{tag_start}if$self->{tag_end}."; |
341 | 359 |
$main::lxdebug->leave_sub(); |
342 | 360 |
return undef; |
343 | 361 |
} |
344 | 362 |
|
345 |
my ($not, $var) = ($1, $2); |
|
363 |
my $not = $1; |
|
364 |
my $var = $2; |
|
365 |
my $operator = $4; # '=' oder '!' oder undef, wenn kein Vergleich erkannt |
|
366 |
my $quoted = $5; # nur g?ltig, wenn quoted string angegeben (siehe unten); dann "value" aus <%if var == "value" %> |
|
367 |
my $bareword = $7; # undef, falls quoted string angegeben wurde; andernfalls "othervar" aus <%if var == othervar %> |
|
368 |
|
|
369 |
$not = !$not if ($operator && $operator eq '!'); |
|
346 | 370 |
|
347 | 371 |
substr($contents, 0, length($&)) = ""; |
348 | 372 |
|
... | ... | |
353 | 377 |
return undef; |
354 | 378 |
} |
355 | 379 |
|
356 |
my $form = $self->{form}; |
|
357 |
$form = $form->{TEMPLATE_ARRAYS} if @indices |
|
358 |
&& ref $form->{TEMPLATE_ARRAYS} eq 'HASH' |
|
359 |
&& ref $form->{TEMPLATE_ARRAYS}->{$var} eq 'ARRAY'; |
|
360 |
my $value = $form->{$var}; |
|
361 |
for (my $i = 0; $i < scalar(@indices); $i++) { |
|
362 |
last unless (ref($value) eq "ARRAY"); |
|
363 |
$value = $value->[$indices[$i]]; |
|
380 |
my $value = $self->_get_loop_variable($var, 0, @indices); |
|
381 |
my $hit = 0; |
|
382 |
|
|
383 |
if ($operator) { |
|
384 |
my $compare_to = $bareword ? $self->_get_loop_variable($bareword, 0, @indices) : $quoted; |
|
385 |
$hit = ($not && !($value eq $compare_to)) || (!$not && ($value eq $compare_to)); |
|
386 |
|
|
387 |
} else { |
|
388 |
$hit = ($not && ! $value) || (!$not && $value); |
|
364 | 389 |
} |
365 | 390 |
|
366 |
if (($not && !$value) || (!$not && $value)) {
|
|
391 |
if ($hit) {
|
|
367 | 392 |
my $new_text = $self->parse_block($block, @indices); |
368 | 393 |
if (!defined($new_text)) { |
369 | 394 |
$main::lxdebug->leave_sub(); |
Auch abrufbar als: Unified diff
Einführung RegEx für Vergleichsoperationen in <%if ...%>-Statements.