mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
Fix searchExtPos so that it returns -1 when the path is not a file ext (#22245)
* Fix searchExtPos so that it returns -1 when the path is not a file ext * fix comparision expression * Remove splitDrive from searchExtPos
This commit is contained in:
@@ -584,15 +584,28 @@ proc searchExtPos*(path: string): int =
|
||||
assert searchExtPos("c.nim") == 1
|
||||
assert searchExtPos("a/b/c.nim") == 5
|
||||
assert searchExtPos("a.b.c.nim") == 5
|
||||
assert searchExtPos(".nim") == -1
|
||||
assert searchExtPos("..nim") == -1
|
||||
assert searchExtPos("a..nim") == 2
|
||||
|
||||
# BUGFIX: do not search until 0! .DS_Store is no file extension!
|
||||
# Unless there is any char that is not `ExtSep` before last `ExtSep` in the file name,
|
||||
# it is not a file extension.
|
||||
const DirSeps = when doslikeFileSystem: {DirSep, AltSep, ':'} else: {DirSep, AltSep}
|
||||
result = -1
|
||||
for i in countdown(len(path)-1, 1):
|
||||
var i = path.high
|
||||
while i >= 1:
|
||||
if path[i] == ExtSep:
|
||||
break
|
||||
elif path[i] in DirSeps:
|
||||
return -1 # do not skip over path
|
||||
dec i
|
||||
|
||||
for j in countdown(i - 1, 0):
|
||||
if path[j] in DirSeps:
|
||||
return -1
|
||||
elif path[j] != ExtSep:
|
||||
result = i
|
||||
break
|
||||
elif path[i] in {DirSep, AltSep}:
|
||||
break # do not skip over path
|
||||
|
||||
proc splitFile*(path: string): tuple[dir, name, ext: string] {.
|
||||
noSideEffect, rtl, extern: "nos$1".} =
|
||||
|
||||
Reference in New Issue
Block a user