Sha256: df77a1470802083525ace0e32b3bf0f49e504b16d439ebddb4c81396bf6dad59
Contents?: true
Size: 1.14 KB
Versions: 3
Compression:
Stored size: 1.14 KB
Contents
require 'cxxproject/utils/utils' class File SLASH = '/' def self.is_absolute?(filename) filename[0] == SLASH or filename[1] == ':' end def self.rel_from_to_project(from,to,endWithSlash = true) return nil if from.nil? or to.nil? toSplitted = to.split('/') fromSplitted = from.split('/') max = [toSplitted.length, fromSplitted.length].min return nil if max < 1 i = 0 # path letter in windows may be case different if toSplitted[0].length > 1 and fromSplitted[0].length > 1 i = 1 if toSplitted[0][1] == ':' and fromSplitted[0][1] == ':' and toSplitted[0].swapcase[0] == fromSplitted[0][0] end while i < max break if toSplitted[i] != fromSplitted[i] i += 1 end j = i res = [] while i < fromSplitted.length res << ".." i += 1 end while j < toSplitted.length res << toSplitted[j] j += 1 end if res.length == 0 return "" end res = res.join('/') res += "/" if endWithSlash res end def self.add_prefix(prefix, file) if not prefix or is_absolute?(file) file else prefix + file end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
cxxproject-0.6.31 | lib/cxxproject/ext/file.rb |
cxxproject-0.6.30 | lib/cxxproject/ext/file.rb |
cxxproject-0.6.29 | lib/cxxproject/ext/file.rb |