Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "github.com/kr/pretty"
- import "strings"
- func simplifyPath(path string) string {
- paths, pathStk := strings.Split(path, "/"), []string{}
- for _, p := range paths[1 :] {
- if p == ".." && len(pathStk) > 0 {
- pathStk = pathStk[: len(pathStk) - 1]
- } else if p != "." {
- pathStk = append(pathStk, p)
- }
- }
- return "/" + strings.Join(pathStk, "/")
- }
- func main() {
- pretty.Println(simplifyPath("/home/./../allenwhale/../../"))
- }
Add Comment
Please, Sign In to add comment