[LON-CAPA-cvs] cvs: loncom /interface loncoursedata.pm

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 09 Oct 2002 17:25:23 -0000


matthew		Wed Oct  9 13:25:23 2002 EDT

  Modified files:              
    /loncom/interface	loncoursedata.pm 
  Log:
  Rewrite of ProcessFullName to be a little easier to understand and to 
  strip off leading and trailing whitespace from name components.
  
  
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.33 loncom/interface/loncoursedata.pm:1.34
--- loncom/interface/loncoursedata.pm:1.33	Fri Sep 20 18:33:54 2002
+++ loncom/interface/loncoursedata.pm	Wed Oct  9 13:25:23 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: loncoursedata.pm,v 1.33 2002/09/20 22:33:54 albertel Exp $
+# $Id: loncoursedata.pm,v 1.34 2002/10/09 17:25:23 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1084,37 +1084,22 @@
     my ($lastname, $generation, $firstname, $middlename)=@_;
     my $Str = '';
 
+    # Strip whitespace preceeding & following name components.
+    $lastname   =~ s/(\s+$|^\s+)//g;
+    $generation =~ s/(\s+$|^\s+)//g;
+    $firstname  =~ s/(\s+$|^\s+)//g;
+    $middlename =~ s/(\s+$|^\s+)//g;
+
     if($lastname ne '') {
-	$Str .= $lastname.' ';
-	if($generation ne '') {
-	    $Str .= $generation;
-	} else {
-	    chop($Str);
-	}
-	$Str .= ', ';
-	if($firstname ne '') {
-	    $Str .= $firstname.' ';
-	}
-	if($middlename ne '') {
-	    $Str .= $middlename;
-	} else {
-	    chop($Str);
-	    if($firstname eq '') {
-		chop($Str);
-	    }
-	}
+	$Str .= $lastname;
+	$Str .= ' '.$generation if ($generation ne '');
+	$Str .= ',';
+        $Str .= ' '.$firstname  if ($firstname ne '');
+        $Str .= ' '.$middlename if ($middlename ne '');
     } else {
-	if($firstname ne '') {
-	    $Str .= $firstname.' ';
-	}
-	if($middlename ne '') {
-	    $Str .= $middlename.' ';
-	}
-	if($generation ne '') {
-	    $Str .= $generation;
-	} else {
-	    chop($Str);
-	}
+        $Str .= $firstname      if ($firstname ne '');
+        $Str .= ' '.$middlename if ($middlename ne '');
+        $Str .= ' '.$generation if ($generation ne '');
     }
 
     return $Str;