Changeset 16918

Show
Ignore:
Timestamp:
20.08.2008 17:32:04 (11 years ago)
Author:
ak19
Message:

Added methods url_to_filename and filename_to_url: Two utility subroutines to do with URL encoding: one converts from a filename--as it appears on the filesystem (which may be URL encoded of itself)--to a url referring to that file, and the other converts such a url ref back to the file(name) it referred to again.

Files:
1 modified

Legend:

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

    r16913 r16918  
    596596} 
    597597 
     598# When a filename on the filesystem is already URL-encoded, the 
     599# URL to it will have %25s in in place of every % sign, so that  
     600# URLs in html pages can refer to the URL-encoded filename. 
     601# This method changes the URL reference back into the actual  
     602# (URL-encoded) filename on the filesystem by replacing %25 with %.  
     603sub url_to_filename { 
     604    my ($text) =@_; 
     605    $text =~ s/%25/%/g; 
     606} 
     607 
     608# When a filename on the filesystem is already URL-encoded, the 
     609# URL to it will have %25s in in place of every % sign, so that  
     610# URLs in html pages can refer to the URL-encoded filename. 
     611# Given a (URL-encoded) filename on the filesystem, this subroutine 
     612# returns the URL reference string for it by replacing % with %25.  
     613# The output string will be the same as the input string if the input 
     614# already contains one or more %25s. This is to prevent processing  
     615# a url more than once this way. 
     616sub filename_to_url { 
     617    my ($text) =@_; 
     618     
     619    if($text !~ m/%25/) { 
     620    $text =~ s/%/%25/g; 
     621    } 
     622} 
     623 
     624 
    598625sub substr 
    599626{