Handle leading or trailing  's as leading or trailing spaces.
authoracli <acli>
Fri, 13 Feb 2004 03:49:26 +0000 (03:49 +0000)
committeracli <acli>
Fri, 13 Feb 2004 03:49:26 +0000 (03:49 +0000)
Make sure they are all trimmed off.

$re_end_entity is now used (by the above); there are &nbsp's (no ;)
in our templates.

misc/translator/text-extract2.pl

index 513a140..250ac25 100755 (executable)
@@ -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|\&nbsp;)*$/s || $t =~ /^\d+$/;
+       printf "%s\n", $t
+           unless $t =~ /^(?:\s|\&nbsp$re_end_entity)*$/os || $t =~ /^\d+$/;
     }
 }