(path string)
| 10 | } |
| 11 | |
| 12 | func simplifyPath(path string) string { |
| 13 | start := 0 |
| 14 | var ret []string |
| 15 | for start < len(path) { |
| 16 | for ; start < len(path) && path[start] == '/'; start++ { |
| 17 | } |
| 18 | end := start |
| 19 | for ; end < len(path) && path[end] != '/'; end++ { |
| 20 | } |
| 21 | s := path[start:end] |
| 22 | if s == ".." { |
| 23 | if len(ret) > 0 { |
| 24 | ret = ret[:len(ret)-1] |
| 25 | } |
| 26 | } else { |
| 27 | if s != "." && s != "" { |
| 28 | ret = append(ret, s) |
| 29 | } |
| 30 | } |
| 31 | start = end + 1 |
| 32 | } |
| 33 | |
| 34 | if len(ret) == 0 { |
| 35 | return "/" |
| 36 | } |
| 37 | answ := "" |
| 38 | for _, el := range ret { |
| 39 | answ += "/" + el |
| 40 | } |
| 41 | return answ |
| 42 | } |
| 43 | |
| 44 | // func putInRet(path, str &string, start, end int) { |
| 45 | // path + |