class FileSystem {

	@Pure
	public static String basename(String filename) {
		if (filename == null) {
			return null;
		}
		if (isWindowsNativeFilename(filename)) {
			return basename(normalizeWindowsNativeFilename(filename));
		}

		try {
			return basename(new URL(filename));
		} catch (Exception exception) {
			// No log
		}
		int end = filename.length();
		int idx;
		do {
			end--;
			idx = filename.lastIndexOf(File.separatorChar, end);
		}
		while (idx >= 0 && end >= 0 && idx >= end);
		final String basename;
		if (idx < 0) {
			if (end < filename.length() - 1) {
				basename = filename.substring(0, end + 1);
			} else {
				basename = filename;
			}
		} else {
			basename = filename.substring(idx + 1, end + 1);
		}
		idx = basename.lastIndexOf(getFileExtensionCharacter());
		if (idx < 0) {
			return basename;
		}
		return basename.substring(0, idx);
	}

	private  FileSystem();

}