bug 3614 Fix incorrect setting of indicator
authorColin Campbell <colin.campbell@ptfs-europe.com>
Mon, 14 Sep 2009 18:26:47 +0000 (19:26 +0100)
committerGalen Charlton <gmcharlt@gmail.com>
Tue, 15 Sep 2009 13:03:33 +0000 (09:03 -0400)
Pull the code into its own subr so that the dangers of
inaccurate copy & paste are avoided in future

Signed-off-by: Galen Charlton <gmcharlt@gmail.com>
C4/Biblio.pm

index cdb119f..b851bc0 100644 (file)
@@ -1707,10 +1707,8 @@ sub TransformHtmlToXml {
                         $first = 1;
                     }
                     else {
-                        my $ind1 = substr( @$indicator[$j], 0, 1 );
-                        my $ind2 = substr( @$indicator[$j], 1, 1 );
-                        $ind1 = " " if !defined($ind2) or $ind2 eq "";
-                        $ind2 = " " if !defined($ind2) or $ind2 eq "";
+                        my $ind1 = default_ind_to_space( substr( @$indicator[$j], 0, 1 ) );
+                        my $ind2 = default_ind_to_space( substr( @$indicator[$j], 1, 1 ) );
                         $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
                         $xml .= "<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
                         $first = 0;
@@ -1723,10 +1721,8 @@ sub TransformHtmlToXml {
             }
             else {
                 if ($first) {
-                    my $ind1 = substr( @$indicator[$j], 0, 1 );
-                    my $ind2 = substr( @$indicator[$j], 1, 1 );
-                    $ind1 = " " if !defined($ind2) or $ind2 eq "";
-                    $ind2 = " " if !defined($ind2) or $ind2 eq "";
+                    my $ind1 = default_ind_to_space( substr( @$indicator[$j], 0, 1 ) );
+                    my $ind2 = default_ind_to_space( substr( @$indicator[$j], 1, 1 ) );
                     $xml .= "<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
                     $first = 0;
                 }
@@ -1753,6 +1749,21 @@ sub TransformHtmlToXml {
     return $xml;
 }
 
+=head2 default_ind_to_space
+
+Passed what should be an indicator returns a space
+if its undefined or zero length
+
+=cut
+
+sub default_ind_to_space {
+    my $s = shift;
+    if (!defined $s || $s eq q{} ) {
+        return ' ';
+    }
+    return $s;
+}
+
 =head2 TransformHtmlToMarc
 
     L<$record> = TransformHtmlToMarc(L<$params>,L<$cgi>)