fix #8255 numerous issues with splitFile
This commit is contained in:
parent
c129107b32
commit
656770402c
2 changed files with 28 additions and 4 deletions
|
|
@ -349,19 +349,28 @@ proc splitFile*(path: string): tuple[dir, name, ext: string] {.
|
|||
## If `path` has no extension, `ext` is the empty string.
|
||||
## If `path` has no directory component, `dir` is the empty string.
|
||||
## If `path` has no filename component, `name` and `ext` are empty strings.
|
||||
if path.len == 0 or path[path.len-1] in {DirSep, AltSep}:
|
||||
result = (path, "", "")
|
||||
if path.len == 0 or path[^1] in {DirSep, AltSep}:
|
||||
if path.len == 1:
|
||||
# issue #8255
|
||||
result = (path[0 .. ^1], "", "")
|
||||
else:
|
||||
result = (path[0 ..< ^1], "", "")
|
||||
else:
|
||||
var sepPos = -1
|
||||
var dotPos = path.len
|
||||
for i in countdown(len(path)-1, 0):
|
||||
if path[i] == ExtSep:
|
||||
if dotPos == path.len and i > 0 and
|
||||
path[i-1] notin {DirSep, AltSep}: dotPos = i
|
||||
path[i-1] notin {DirSep, AltSep, ExtSep}: dotPos = i
|
||||
elif path[i] in {DirSep, AltSep}:
|
||||
sepPos = i
|
||||
break
|
||||
result.dir = substr(path, 0, sepPos-1)
|
||||
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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue