Guest User

Untitled

a guest
Apr 27th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. package main
  2. import "github.com/kr/pretty"
  3. import "strings"
  4. func simplifyPath(path string) string {
  5. paths, pathStk := strings.Split(path, "/"), []string{}
  6. for _, p := range paths[1 :] {
  7. if p == ".." && len(pathStk) > 0 {
  8. pathStk = pathStk[: len(pathStk) - 1]
  9. } else if p != "." {
  10. pathStk = append(pathStk, p)
  11. }
  12. }
  13. return "/" + strings.Join(pathStk, "/")
  14. }
  15. func main() {
  16. pretty.Println(simplifyPath("/home/./../allenwhale/../../"))
  17. }
Add Comment
Please, Sign In to add comment