lib: add String::/ for path jonction
authorJean Privat <jean@pryen.org>
Thu, 25 Sep 2014 04:15:44 +0000 (00:15 -0400)
committerJean Privat <jean@pryen.org>
Thu, 25 Sep 2014 04:15:44 +0000 (00:15 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/file.nit

index 06001df..3499c89 100644 (file)
@@ -348,6 +348,22 @@ redef class String
                return "{self}/{path}"
        end
 
+       # Alias for `join_path`
+       #
+       #     assert "hello" / "world"      ==  "hello/world"
+       #     assert "hel/lo" / "wor/ld"    ==  "hel/lo/wor/ld"
+       #     assert "" / "world"           ==  "world"
+       #     assert "/hello" / "/world"    ==  "/world"
+       #
+       # This operator is quite useful for chaining changes of path.
+       # The next one being relative to the previous one.
+       #
+       #     var a = "foo"
+       #     var b = "/bar"
+       #     var c = "baz/foobar"
+       #     assert a/b/c == "/bar/baz/foobar"
+       fun /(path: String): String do return join_path(path)
+
        # Create a directory (and all intermediate directories if needed)
        fun mkdir
        do