String (@NotNull String path) { path = FileUtil.toSystemIndependentName(path); path = StringUtil.trimEnd(path, "/"); while (path.contains("/./")) { path = path.replace("/./", "/"); } path = StringUtil.trimStart(path, "./"); path = StringUtil.trimEnd(path, "/."); while (true) { int index = path.indexOf("/.."); if (index < 0) break; int slashIndex = path.substring(0, index).lastIndexOf('/'); if (slashIndex < 0) break; path = path.substring(0, slashIndex) + path.substring(index + 3); } return path; }