Remove the trailing extension.

extension usually starts with a dot but could be anything.

assert "file.txt".strip_extension(".txt")   == "file"
assert "file.txt".strip_extension("le.txt") == "fi"
assert "file.txt".strip_extension("xt")     == "file.t"

If extension == null, the rightmost extension is stripped, including the last dot.

assert "file.txt".strip_extension           == "file"

If extension is not present, self is returned unmodified.

assert "file.txt".strip_extension(".tar.gz")  == "file.txt"

Property definitions

core :: file $ Text :: strip_extension
	# Remove the trailing `extension`.
	#
	# `extension` usually starts with a dot but could be anything.
	#
	#     assert "file.txt".strip_extension(".txt")   == "file"
	#     assert "file.txt".strip_extension("le.txt") == "fi"
	#     assert "file.txt".strip_extension("xt")     == "file.t"
	#
	# If `extension == null`, the rightmost extension is stripped, including the last dot.
	#
	#     assert "file.txt".strip_extension           == "file"
	#
	# If `extension` is not present, `self` is returned unmodified.
	#
	#     assert "file.txt".strip_extension(".tar.gz")  == "file.txt"
	fun strip_extension(extension: nullable String): String
	do
		if extension == null then
			extension = file_extension
			if extension == null then
				return self.to_s
			else extension = ".{extension}"
		end

		if has_suffix(extension) then
			return substring(0, length - extension.length).to_s
		end
		return self.to_s
	end
lib/core/file.nit:926,2--954,4