mirror of
https://github.com/exaloop/codon.git
synced 2025-06-03 15:03:52 +08:00
stdlib/os/path.codon
This commit is contained in:
parent
808e932685
commit
928d2a0c56
@ -1,10 +1,13 @@
|
||||
# (c) 2022 Exaloop Inc. All rights reserved.
|
||||
|
||||
|
||||
def splitext(p: str) -> Tuple[str, str]:
|
||||
"""
|
||||
Split the extension from a pathname.
|
||||
Extension is everything from the last dot to the end, ignoring
|
||||
leading dots. Returns "(root, ext)"; ext may be empty."""
|
||||
sep = '/'
|
||||
extsep = '.'
|
||||
sep = "/"
|
||||
extsep = "."
|
||||
|
||||
sepIndex = p.rfind(sep)
|
||||
dotIndex = p.rfind(extsep)
|
||||
@ -12,7 +15,7 @@ def splitext(p: str) -> Tuple[str, str]:
|
||||
# skip all leading dots
|
||||
filenameIndex = sepIndex + 1
|
||||
while filenameIndex < dotIndex:
|
||||
if p[filenameIndex:filenameIndex+1] != extsep:
|
||||
if p[filenameIndex : filenameIndex + 1] != extsep:
|
||||
return p[:dotIndex], p[dotIndex:]
|
||||
filenameIndex += 1
|
||||
return p, p[:0]
|
||||
|
Loading…
x
Reference in New Issue
Block a user