Changeset 25093

Show
Ignore:
Timestamp:
16.02.2012 15:06:36 (8 years ago)
Author:
kjdon
Message:

added filepath_regex_to_url_format method. like filepath_to_url_format, but assumes already a regex, so need to look for \ not \ for windows dirsep. added url_fileparse which splits into leading dirs and final filename. like File::Basename::fileparse, but assumes url style, ie always / for dirsep

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/util.pm

    r24971 r25093  
    11001100} 
    11011101 
     1102# regex filepaths on windows may include \\ as path separator. Convert \\ to / 
     1103sub filepath_regex_to_url_format 
     1104{ 
     1105    my ($filepath) = @_; 
     1106    if ($ENV{'GSDLOS'} =~ /^windows$/i) { 
     1107    # Only need to worry about Windows, as Unix style directories already in url-format 
     1108    # Convert Windows style \\ => / 
     1109    $filepath =~ s@\\\\@/@g;         
     1110    } 
     1111    return $filepath; 
     1112     
     1113} 
     1114 
     1115# Like File::Basename::fileparse, but expects filepath in url format (ie only / slash for dirsep) 
     1116# and ignores trailing / 
     1117# returns (file, dirs) dirs will be empty if no subdirs 
     1118sub url_fileparse 
     1119{ 
     1120    my ($filepath) = @_; 
     1121    # remove trailing / 
     1122    $filepath =~ s@/$@@; 
     1123    if ($filepath !~ m@/@) { 
     1124    return ($filepath, ""); 
     1125    }  
     1126    my ($dirs, $file) = $filepath =~ m@(.+/)([^/]+)@; 
     1127    return ($file, $dirs); 
     1128     
     1129} 
     1130 
    11021131 
    11031132sub filename_within_collection