Fixes splitfile (#11918) [bugfix]
This commit is contained in:
parent
b095203f28
commit
296dfae8af
2 changed files with 18 additions and 26 deletions
|
|
@ -508,32 +508,23 @@ proc splitFile*(path: string): tuple[dir, name, ext: string] {.
|
||||||
assert name == ""
|
assert name == ""
|
||||||
assert ext == ""
|
assert ext == ""
|
||||||
|
|
||||||
if path.len == 0:
|
var namePos = 0
|
||||||
result = ("", "", "")
|
var dotPos = 0
|
||||||
elif path[^1] in {DirSep, AltSep}:
|
for i in countdown(len(path) - 1, 0):
|
||||||
if path.len == 1:
|
if path[i] in {DirSep, AltSep} or i == 0:
|
||||||
# issue #8255
|
if path[i] in {DirSep, AltSep}:
|
||||||
result = ($path[0], "", "")
|
result.dir = substr(path, 0, max(0, i - 1))
|
||||||
else:
|
namePos = i + 1
|
||||||
result = (path[0 ..< ^1], "", "")
|
if dotPos > i:
|
||||||
else:
|
result.name = substr(path, namePos, dotPos - 1)
|
||||||
var sepPos = -1
|
result.ext = substr(path, dotPos)
|
||||||
var dotPos = path.len
|
else:
|
||||||
for i in countdown(len(path)-1, 0):
|
result.name = substr(path, namePos)
|
||||||
if path[i] == ExtSep:
|
break
|
||||||
if dotPos == path.len and i > 0 and
|
elif path[i] == ExtSep and i > 0 and i < len(path) - 1 and
|
||||||
path[i-1] notin {DirSep, AltSep, ExtSep}: dotPos = i
|
path[i - 1] notin {DirSep, AltSep} and
|
||||||
elif path[i] in {DirSep, AltSep}:
|
path[i + 1] != ExtSep and dotPos == 0:
|
||||||
sepPos = i
|
dotPos = i
|
||||||
break
|
|
||||||
if sepPos-1 >= 0:
|
|
||||||
result.dir = substr(path, 0, sepPos-1)
|
|
||||||
elif path[0] in {DirSep, AltSep}:
|
|
||||||
# issue #8255
|
|
||||||
result.dir = $path[0]
|
|
||||||
|
|
||||||
result.name = substr(path, sepPos+1, dotPos-1)
|
|
||||||
result.ext = substr(path, dotPos)
|
|
||||||
|
|
||||||
proc extractFilename*(path: string): string {.
|
proc extractFilename*(path: string): string {.
|
||||||
noSideEffect, rtl, extern: "nos$1".} =
|
noSideEffect, rtl, extern: "nos$1".} =
|
||||||
|
|
|
||||||
|
|
@ -237,6 +237,7 @@ block splitFile:
|
||||||
doAssert splitFile("abc/.") == ("abc", ".", "")
|
doAssert splitFile("abc/.") == ("abc", ".", "")
|
||||||
doAssert splitFile("..") == ("", "..", "")
|
doAssert splitFile("..") == ("", "..", "")
|
||||||
doAssert splitFile("a/..") == ("a", "..", "")
|
doAssert splitFile("a/..") == ("a", "..", "")
|
||||||
|
doAssert splitFile("/foo/abc....txt") == ("/foo", "abc...", ".txt")
|
||||||
|
|
||||||
# execShellCmd is tested in tosproc
|
# execShellCmd is tested in tosproc
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue