Merge branch 'nitdoc2' into wip
authorJean Privat <jean@pryen.org>
Wed, 15 Feb 2012 21:06:09 +0000 (16:06 -0500)
committerJean Privat <jean@pryen.org>
Wed, 15 Feb 2012 21:06:09 +0000 (16:06 -0500)
Conflicts:
lib/standard/file.nit
src/nitdoc.nit

1  2 
lib/standard/file.nit
lib/standard/string_search.nit
src/compiling/compiling_base.nit
src/metamodel/inheritance.nit
src/program.nit
src/syntax/mmbuilder.nit

@@@ -229,6 -225,45 +229,35 @@@ redef class Strin
                end
        end
  
 -      fun file_path: String
 -      do
 -              var l = _length
 -              var pos = last_index_of_from('/', l - 1)
 -              if pos >= 0 then
 -                      return substring(0, pos)
 -              end
 -              return "."
 -      end
 -
+       # Simplify a file path by remove useless ".", removing "//", and resolving ".."
+       # ".." are not resolved if they start the path
+       # starting "/" is not removed
+       # trainling "/" is removed
+       #
+       # Note that the method only wonrk on the string:
+       #  * no I/O access is performed
+       #  * the validity of the path is not checked
+       #
+       #     "some/./complex/../../path/from/../to/a////file//".simplify_path  # -> "path/to/a/file"
+       #     "../dir/file" # -> "../dir/file"
+       #     "dir/../../" # -> ".."
+       #     "//absolute//path/" # -> "/absolute/path"
+       fun simplify_path: String
+       do
+               var a = self.split_with("/")
+               var a2 = new Array[String]
+               for x in a do
+                       if x == "." then continue
+                       if x == "" and not a2.is_empty then continue
+                       if x == ".." and not a2.is_empty then
+                               a2.pop
+                               continue
+                       end
+                       a2.push(x)
+               end
+               return a2.join("/")
+       end
        # Create a directory (and all intermediate directories if needed)
        fun mkdir
        do
Simple merge
Simple merge
Simple merge
diff --cc src/program.nit
Simple merge
Simple merge