Changeset 18337

Show
Ignore:
Timestamp:
08.01.2009 18:32:09 (10 years ago)
Author:
ak19
Message:

1. Spaces replaced with underscore in the subroutine rename_file instead of in unicode::url_encode. 2. Now the subroutine takes an optional third parameter which is set when given only a tailname: no suffix to the given filename. This is useful for when the filename contains period marks in the middle, none of which are the one separating tailname from the suffix. The testcase with the 'ridiculous' filename (containing period marks and spaces) is successfully handled again.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/util.pm

    r18329 r18337  
    995995} 
    996996 
    997 # returns the given filename converted using either URL encoding or  
    998 # base64 encoding, as specified by $rename_method 
     997# Returns the given filename converted using either URL encoding or base64 
     998# encoding, as specified by $rename_method. If the given filename has no suffix 
     999# (if it is just the tailname), then $no_suffix should be some defined value.  
    9991000sub rename_file { 
    1000     my ($filename, $rename_method)  = @_; 
    1001  
    1002     if(!$filename) { # for example, empty string 
     1001    my ($filename, $rename_method, $no_suffix)  = @_; 
     1002 
     1003    if(!$filename) { # undefined or empty string 
    10031004    return $filename; 
    10041005    } 
    1005    
    1006     my ($tailname,$dirname,$suffix) = File::Basename::fileparse($filename, "\\.[^\\.]+\$"); 
     1006 
     1007    # Replace spaces with underscore. 
     1008    # Do this first else it can go wrong below when getting tailname 
     1009    $filename =~ s/ /_/g; 
     1010 
     1011    # Should we do this???? 
     1012    # DM safing would have replaced underscores with character entity _ 
     1013    $filename =~ s/&\#095;/_/g; 
     1014 
     1015    my ($tailname,$dirname,$suffix);  
     1016    if($no_suffix) { # given a tailname, no suffix 
     1017    $suffix = ""; 
     1018    ($tailname,$dirname) = File::Basename::fileparse($filename); 
     1019    }  
     1020    else { 
     1021    ($tailname,$dirname,$suffix) = File::Basename::fileparse($filename, "\\.(?:[^\\.]+?)\$"); 
     1022    } 
    10071023 
    10081024    if (!$rename_method) { 
     
    10101026    # Debugging information 
    10111027    my ($cpackage,$cfilename,$cline,$csubr,$chas_args,$cwantarray) = caller(1); 
    1012     print STDERR "Calling method; $cfilename:$cline $cpackage->$csubr\n"; 
     1028    print STDERR "Calling method: $cfilename:$cline $cpackage->$csubr\n"; 
    10131029    } 
    10141030