diff options
-rw-r--r-- | lib/pure/os.nim | 14 | ||||
-rw-r--r-- | web/news.txt | 3 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 1739718f6..48d255dca 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -621,6 +621,20 @@ proc parentDir*(path: string): string {. else: result = "" +proc tailDir*(path: string): string {. + noSideEffect, rtl, extern: "nos$1".} = + ## Returns the tail part of `path`.. + ## + ## | Example: ``tailDir("/usr/local/bin") == "local/bin"``. + ## | Example: ``tailDir("usr/local/bin/") == "local/bin"``. + ## | Example: ``tailDir("bin") == ""``. + var q = 1 + if len(path) >= 1 and path[len(path)-1] in {DirSep, AltSep}: q = 2 + for i in 0..len(path)-q: + if path[i] in {DirSep, AltSep}: + return substr(path, i+1) + result = "" + proc isRootDir*(path: string): bool {. noSideEffect, rtl, extern: "nos$1".} = ## Checks whether a given `path` is a root directory diff --git a/web/news.txt b/web/news.txt index cffffffee..cdb503ef6 100644 --- a/web/news.txt +++ b/web/news.txt @@ -47,7 +47,8 @@ News - The nre module has been added, providing a better interface to PCRE than re. - - The ``expandSymlink`` procedure has been added to the ``os`` module. + - The ``expandSymlink`` proc has been added to the ``os`` module. + - The ``tailDir`` proc has been added to the ``os`` module. Language Additions ------------------ |