nitdoc: simplify filenames
authorJean Privat <jean@pryen.org>
Wed, 8 Feb 2012 16:20:11 +0000 (11:20 -0500)
committerJean Privat <jean@pryen.org>
Wed, 8 Feb 2012 19:54:23 +0000 (14:54 -0500)
This avoid some ugly path and html warnings.

Signed-off-by: Jean Privat <jean@pryen.org>

src/nitdoc.nit

index 104bfef..cac3298 100644 (file)
@@ -243,11 +243,11 @@ class DocContext
        do
                var s = opt_source.value
                if s == null then
-                       add("in #{l.file.filename}")
+                       add("in #{l.file.filename.simplify_path}")
                else
                        # THIS IS JUST UGLY ! (but there is no replace yet)
                        var x = s.split_with("%f")
-                       s = x.join(l.file.filename)
+                       s = x.join(l.file.filename.simplify_path)
                        x = s.split_with("%l")
                        s = x.join(l.line_start.to_s)
                        x = s.split_with("%L")
@@ -298,6 +298,25 @@ class DocContext
        end
 end
 
+redef class String
+       # Remove "/./", "//" and "bla/../"
+       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
+end
+
 # A virtual module is used to work as an implicit main module that combine unrelated modules
 # Since conflict may arrise in a virtual module (the main method for instance) conflicts are disabled
 class MMVirtualModule