Code Improvement : C4/Matcher.pm
authorHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Tue, 29 Sep 2009 12:57:52 +0000 (14:57 +0200)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Mon, 5 Oct 2009 05:48:52 +0000 (07:48 +0200)
substr dans act when passed only subfield offset

C4/Matcher.pm

index c9a1e46..ae6fb7d 100644 (file)
@@ -774,26 +774,23 @@ sub _get_match_keys {
             last FIELD if $j > 0 and $check_only_first_repeat;
             last FIELD if $i > 0 and $j > $#keys;
             my $key = "";
+                       my $string;
             if ($field->is_control_field()) {
-                if ($component->{'length'}) {
-                    $key = _normalize(substr($field->data(), $component->{'offset'}, $component->{'length'}))
-                            # FIXME normalize, substr
-                } else {
-                    $key = _normalize($field->data());
-                }
+                               $string=$field->data();
             } else {
                 foreach my $subfield ($field->subfields()) {
                     if (exists $component->{'subfields'}->{$subfield->[0]}) {
-                        $key .= " " . $subfield->[1];
+                        $string .= " " . $subfield->[1];
                     }
                 }
-                $key = _normalize($key);
-                if ($component->{'length'}){
-                   if (length($key) > $component->{'length'}){
-                     $key = _normalize(substr($key,$component->{'offset'},$component->{'length'}));
-                   }
-                }
+                       }
+            if ($component->{'length'}>0) {
+                    $string= substr($string, $component->{'offset'}, $component->{'length'});
+                            # FIXME normalize, substr
+            } elsif ($component->{'offset'}) {
+                    $string= substr($string, $component->{'offset'});
             }
+            $key = _normalize($string);
             if ($i == 0) {
                 push @keys, $key if $key;
             } else {
@@ -802,7 +799,6 @@ sub _get_match_keys {
         }
     }
     return @keys;
-    
 }