diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-01-15 06:03:06 -0800 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2020-01-15 15:03:06 +0100 |
commit | 51c072bd379dfb4bc82de643b6dac7abe6809e33 (patch) | |
tree | 24bb1c0dff76288fb8c554f9064091f8bf55d5b5 | |
parent | e708d5de75c0cccba666f19390ee1ac8e3df8a7a (diff) | |
download | Nim-51c072bd379dfb4bc82de643b6dac7abe6809e33.tar.gz |
export normalizePathEnd (#13152)
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | lib/pure/os.nim | 9 |
2 files changed, 11 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md index 17eedb3a1..34ecd66a0 100644 --- a/changelog.md +++ b/changelog.md @@ -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` diff --git a/lib/pure/os.nim b/lib/pure/os.nim index ba6405621..a329d232a 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -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. |