Extract the dirname of a path

assert "/path/to/a_file.ext".dirname         == "/path/to"
assert "path/to/a_file.ext".dirname          == "path/to"
assert "path/to".dirname                     == "path"
assert "path/to/".dirname                    == "path"
assert "path".dirname                        == "."
assert "/path".dirname                       == "/"
assert "/".dirname                           == "/"
assert "".dirname                            == "."

On Windows, '' are replaced by '/':

assert "C:\\path\\to\\a_file.ext".dirname        == "C:/path/to"
assert "C:\\file".dirname                        == "C:"

Property definitions

core :: file $ Text :: dirname
	# Extract the dirname of a path
	#
	#     assert "/path/to/a_file.ext".dirname         == "/path/to"
	#     assert "path/to/a_file.ext".dirname          == "path/to"
	#     assert "path/to".dirname                     == "path"
	#     assert "path/to/".dirname                    == "path"
	#     assert "path".dirname                        == "."
	#     assert "/path".dirname                       == "/"
	#     assert "/".dirname                           == "/"
	#     assert "".dirname                            == "."
	#
	# On Windows, '\' are replaced by '/':
	#
	# ~~~nitish
	# assert "C:\\path\\to\\a_file.ext".dirname        == "C:/path/to"
	# assert "C:\\file".dirname                        == "C:"
	# ~~~
	fun dirname: String
	do
		var s = self
		if is_windows then s = s.replace("\\", "/")

		var l = length - 1 # Index of the last char
		while l > 0 and s.chars[l] == '/' do l -= 1 # remove all trailing `/`
		var pos = s.chars.last_index_of_from('/', l)
		if pos > 0 then
			return s.substring(0, pos).to_s
		else if pos == 0 then
			return "/"
		else
			return "."
		end
	end
lib/core/file.nit:995,2--1027,4