9 if(!path.match(/#{SEPARATOR}/) || path.match(/^\.+#{SEPARATOR}+$/))
12 # strip the basename off the end and clean up the ending separators
13 path = path.sub(/#{SEPARATOR}*[^#{SEPARATOR}]*#{SEPARATOR}*$/,'')
22 def self.basename(path,ext)
23 path.gsub!(/([^#{SEPARATOR}])#{SEPARATOR}\z/, "\\1")
24 basename = if(m = path.match(/#{SEPARATOR}+([^#{SEPARATOR}]*)#{SEPARATOR}*$/))
25 m[1] == '' ? SEPARATOR : m[1]
29 ext = Regexp.quote(ext) # convert everything to literal characters
30 ext.sub!(/\\\*/,'[^\.]+?') # convert .*'s back into a general match expression
31 return basename.sub(/#{ext}$/,'')
34 # FIXME: this is awful
35 def self.expand_path(path, dir_string = nil)
36 path = StringValue(path)
40 dir_string = StringValue(dir_string)
43 path.gsub!(/~(#{ENV['USER']})/, "~/")
45 raise ArgumentError, "user #{path}" if path.match(/~([^\/])/)
49 elsif(dir_string[0].chr == '~')
50 dir_string = ENV['HOME'] + dir_string[1..-1]
51 elsif(dir_string[0].chr != '/')
52 dir_string = Dir.pwd + "/" + dir_string
55 dirs = path.split('/')
56 if path == '' || (dirs.empty? && path[0].chr != '/')
59 first = case dirs.first
60 when '..'; dir_string.split('/')[0...-1].join('/')
65 match = /(\/+)/.match(path)
66 prefix = match[0] if match
69 dir_string + '/' + dirs.first
73 paths = first.split('/')
75 next if dir == '.' || dir == ''
76 dir == '..' ? paths.pop : paths.push(dir)
78 string = paths.empty? ? '' : paths.join("/")
79 return !string.empty? && string[0].chr == '/' ? string : prefix || '/' +string