Title: RE: [boost] Re: relative/absolute paths in filesystem library

I'm dealing with filesystem paths and urls and the way we ended up implementing it is with the following functions (we are not currently using boost::filesystem, these are from an internal library):

current_directory() - returns the current directory (and drive if windows)

make_absolute() - prepends current drive if no drive is defined, inserts current directory after the drive if it is not an absolute path

is_absolute() - true if the directory (sans drive) starts with a / (c:/, /, /blah are absolute; c:blah, blah, ../blah are not)

resolve(base, rel) - returns a path that is 'rel' resolved relative to 'base' according to the following table:
base     rel      result    
-----------------------------
base     rel      base/rel  
base     /rel     /rel      
base     c:rel    ... throws exception  
base     c:/rel   c:/rel    
/base    rel      /base/rel 
/base    /rel     /rel      
/base    c:rel    ... throws exception  
/base    c:/rel   c:/rel    
c:base   rel      c:base/rel
c:base   /rel     c:/rel    
c:base   c:rel    c:base/rel
c:base   c:/rel   c:/rel    
c:base   a:rel    ... throws exception  
c:base   a:/rel   a:/rel    
c:/base  rel      c:/base/rel
c:/base  /rel     c:/rel    
c:/base  c:rel    c:/base/rel
c:/base  c:/rel   c:/rel    
c:/base  a:rel    ... throws exception  
c:/base  a:/rel   a:/rel    

This attempts to follow the same phliosophy as the url resolution rules and has worked out well so far. During the review I argued for make_absolute to behave like resolve(current_directory(), rel) but now I believe that two separate functions is the best way to do this.

Just wanted to get this off before it was too late,
Glen

Reply via email to