file: fix useless var warnings
[nit.git] / lib / standard / file.nit
index d9d6cd9..60f5f69 100644 (file)
@@ -16,7 +16,7 @@
 module file
 
 intrude import stream
-intrude import string
+intrude import ropes
 import string_search
 import time
 
@@ -38,6 +38,7 @@ abstract class FStream
        # The FILE *.
        private var file: nullable NativeFile = null
 
+       # The status of a file. see POSIX stat(2).
        fun file_stat: FileStat do return _file.file_stat
 
        # File descriptor of this file
@@ -64,7 +65,7 @@ class IFStream
 
        redef fun close
        do
-               var i = _file.io_close
+               _file.io_close
                _buffer.clear
                end_reached = true
        end
@@ -94,8 +95,6 @@ class IFStream
                end
        end
 
-       private init do end
-       private init without_file do end
 end
 
 # File output stream
@@ -115,7 +114,7 @@ class OFStream
 
        redef fun close
        do
-               var i = _file.io_close
+               _file.io_close
                _is_writable = false
        end
 
@@ -142,17 +141,15 @@ class OFStream
                self.path = path
                _is_writable = true
        end
-       
-       private init do end
-       private init without_file do end
 end
 
 ###############################################################################
 
+# Standard input stream.
 class Stdin
        super IFStream
 
-       private init do
+       init do
                _file = new NativeFile.native_stdin
                path = "/dev/stdin"
                prepare_buffer(1)
@@ -161,18 +158,20 @@ class Stdin
        redef fun poll_in: Bool is extern "file_stdin_poll_in"
 end
 
+# Standard output stream.
 class Stdout
        super OFStream
-       private init do
+       init do
                _file = new NativeFile.native_stdout
                path = "/dev/stdout"
                _is_writable = true
        end
 end
 
+# Standard error stream.
 class Stderr
        super OFStream
-       private init do
+       init do
                _file = new NativeFile.native_stderr
                path = "/dev/stderr"
                _is_writable = true
@@ -328,24 +327,30 @@ redef class String
 
        # Correctly join two path using the directory separator.
        #
-       # Using a standard "{self}/{path}" does not work when `self` is the empty string.
-       # This method ensure that the join is valid.
+       # Using a standard "{self}/{path}" does not work in the following cases:
+       #
+       # * `self` is empty.
+       # * `path` ends with `'/'`.
+       # * `path` starts with `'/'`.
        #
-       #     assert "hello".join_path("world")      ==  "hello/world"
-       #     assert "hel/lo".join_path("wor/ld")      ==  "hel/lo/wor/ld"
-       #     assert "".join_path("world")      ==  "world"
-       #     assert "/hello".join_path("/world")      ==  "/world"
+       # This method ensures that the join is valid.
        #
-       # Note: you may want to use `simplify_path` on the result
+       #     assert "hello".join_path("world")   == "hello/world"
+       #     assert "hel/lo".join_path("wor/ld") == "hel/lo/wor/ld"
+       #     assert "".join_path("world")        == "world"
+       #     assert "hello".join_path("/world")  == "/world"
+       #     assert "hello/".join_path("world")  == "hello/world"
+       #     assert "hello/".join_path("/world") == "/world"
        #
-       # Note: I you want to join a great number of path, you can write
+       # Note: You may want to use `simplify_path` on the result.
        #
-       #     [p1, p2, p3, p4].join("/")
+       # Note: This method works only with POSIX paths.
        fun join_path(path: String): String
        do
                if path.is_empty then return self
                if self.is_empty then return path
                if path.chars[0] == '/' then return path
+               if self.last == '/' then return "{self}{path}"
                return "{self}/{path}"
        end