--- trunk/lib/WebPAC/Normalize.pm 2005/12/20 23:31:37 312 +++ trunk/lib/WebPAC/Normalize.pm 2005/12/31 13:42:11 333 @@ -11,11 +11,11 @@ =head1 VERSION -Version 0.07 +Version 0.08 =cut -our $VERSION = '0.07'; +our $VERSION = '0.08'; =head1 SYNOPSIS @@ -327,13 +327,17 @@ # remove filter{...} from beginning $filter_name = $1 if ($format =~ s/^filter{([^}]+)}//s); + # did we found any (att all) field from format in row? + my $found_any = 0; + # prefix before first field which we preserve it $found_any my $prefix; - my $all_found=0; + + my $f_step = 1; while ($format =~ s/^(.*?)(v|s)(\d+)(?:\^(\w))?//s) { my $del = $1 || ''; - $prefix ||= $del if ($all_found == 0); + $prefix = $del if ($f_step == 1); # repeatable index my $r = $i; @@ -343,13 +347,16 @@ my $tmp = $self->get_data(\$rec,$3,$4,$r,\$found); if ($found) { - push @out, $del; + $found_any += $found; + + # we will skip delimiter before first occurence of field! + push @out, $del unless($found_any == 1); push @out, $tmp; - $all_found += $found; } + $f_step++; } - return if (! $all_found); + return if (! $found_any); my $out = join('',@out); @@ -463,6 +470,7 @@ } my $found = 0; + my $just_single = 1; my $eval_code; # remove eval{...} from beginning @@ -474,9 +482,14 @@ # do actual replacement of placeholders # repeatable fields - $format =~ s/v(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,$i,\$found)/ges; + if ($format =~ s/v(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,$i,\$found)/ges) { + $just_single = 0; + } + # non-repeatable fields - $format =~ s/s(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,0,\$found)/ges; + if ($format =~ s/s(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,0,\$found)/ges) { + return if ($i > 0 && $just_single); + } if ($found) { $log->debug("format: $format");