Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
and `typetraits.get` to get the ith element of a type tuple.
- Added `typetraits.genericParams` to return a tuple of generic params from a generic instantiation

- Added `os.normalizePathEnd` for additional path sanitization.

## Library changes

- `asyncdispatch.drain` now properly takes into account `selector.hasPendingOperations`
Expand Down
9 changes: 9 additions & 0 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,18 @@ proc normalizePathEnd(path: var string, trailingSep = false) =
path = $DirSep

proc normalizePathEnd(path: string, trailingSep = false): string =
## outplace overload
runnableExamples:
when defined(posix):
assert normalizePathEnd("/lib//", trailingSep = true) == "/lib/"
assert normalizePathEnd("lib//", trailingSep = false) == "lib"
assert normalizePathEnd("", trailingSep = true) == "" # not / !
result = path
result.normalizePathEnd(trailingSep)

when (NimMajor, NimMinor) >= (1, 1):
export normalizePathEnd

proc joinPath*(head, tail: string): string {.
noSideEffect, rtl, extern: "nos$1".} =
## Joins two directory names to one.
Expand Down