Handle leading or trailing  's as leading or trailing spaces.

Make sure they are all trimmed off.

$re_end_entity is now used (by the above); there are &nbsp's (no ;)
in our templates.
This commit is contained in:
acli 2004-02-13 03:49:26 +00:00
parent 69589b31f1
commit a10bb7062a
1 changed files with 13 additions and 3 deletions

View File

@ -224,6 +224,15 @@ sub debug_dump (*) { # for testing only
###############################################################################
sub trim ($) {
my($s) = @_;
$s =~ s/^(?:\s|\&nbsp$re_end_entity)+//os;
$s =~ s/(?:\s|\&nbsp$re_end_entity)+$//os;
return $s;
}
###############################################################################
sub text_extract (*) {
my($h) = @_;
my %text = ();
@ -232,7 +241,7 @@ sub text_extract (*) {
last unless defined $s;
my($kind, $t, $attr) = @$s; # FIXME
if ($kind eq KIND_TEXT) {
$t =~ s/\s+$//s;
$t = trim $t;
$text{$t} = 1 if $t =~ /\S/s;
} elsif ($kind eq KIND_TAG && %$attr) {
# value [tag=input], meta
@ -243,7 +252,7 @@ sub text_extract (*) {
next if $a eq 'value' && ($tag ne 'input'
|| (ref $attr->{'type'} && $attr->{'type'}->[1] eq 'hidden')); # FIXME
my($key, $val, $val_orig, $order) = @{$attr->{$a}}; #FIXME
$val =~ s/\s+$//s;
$val = trim $val;
$text{$val} = 1 if $val =~ /\S/s;
}
}
@ -251,7 +260,8 @@ sub text_extract (*) {
}
# Emit all extracted strings. Don't emit pure whitespace or pure numbers.
for my $t (keys %text) {
printf "%s\n", $t unless $t =~ /^(?:\s|\ )*$/s || $t =~ /^\d+$/;
printf "%s\n", $t
unless $t =~ /^(?:\s|\&nbsp$re_end_entity)*$/os || $t =~ /^\d+$/;
}
}