Skip to content

Instantly share code, notes, and snippets.

@Varriount
Created April 23, 2014 23:05
Show Gist options
  • Save Varriount/11235621 to your computer and use it in GitHub Desktop.
Save Varriount/11235621 to your computer and use it in GitHub Desktop.
proc simplifyPath(path: string): string =
## /User/Tom/../Carl/../../ -> /
result = path
var
bounds = newSeq[int]()
writePos, readPos = 0
while readPos < path.len():
result[writePos] = path[readPos]
if path[readPos] == '/':
if path[readPos+1 .. readPos+3] == "../":
echo("Bounds len: ", bounds.len())
echo("Bounds: ", repr(bounds))
writePos = bounds[bounds.len()-1]
readPos.inc(3)
else:
bounds.add(readPos)
echo("Bound added: ", readPos)
writePos.inc
readPos.inc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment