From 87b8a8d6afc6d2a9bc9330bf463d859806aeba40 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 8 Feb 2012 11:20:11 -0500 Subject: [PATCH] nitdoc: simplify filenames This avoid some ugly path and html warnings. Signed-off-by: Jean Privat --- src/nitdoc.nit | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/nitdoc.nit b/src/nitdoc.nit index 104bfef..cac3298 100644 --- a/src/nitdoc.nit +++ b/src/nitdoc.nit @@ -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 -- 1.7.9.5