diff options
author | Araq <rumpf_a@web.de> | 2015-07-12 13:30:23 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-07-12 13:33:22 +0200 |
commit | 27f5c3ceb95e8946445b23f7b5ffd2791c01c6fc (patch) | |
tree | 780af030f724ba2907b072b7529624c13ec93cd7 | |
parent | 994d81461bbac0a7931436e03f8d419ef22014cb (diff) | |
download | Nim-27f5c3ceb95e8946445b23f7b5ffd2791c01c6fc.tar.gz |
added os.tailDir proc
-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 ------------------ |