1
0
mirror of https://github.com/exaloop/codon.git synced 2025-06-03 15:03:52 +08:00
codon/stdlib/os/path.codon
A. R. Shajii 0e42fded1a
2024 updates (#548)
* Update copyright dates in stdlib

* Update copyright dates in cpp files

* Update copyright dates in h files

* Update copyright dates in py files

* Bump version

* Update LICENSE

* Update release notes
2024-03-02 16:30:03 -05:00

21 lines
673 B
Python

# Copyright (C) 2022-2024 Exaloop Inc. <https://exaloop.io>
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 = "."
sepIndex = p.rfind(sep)
dotIndex = p.rfind(extsep)
if dotIndex > sepIndex:
# skip all leading dots
filenameIndex = sepIndex + 1
while filenameIndex < dotIndex:
if p[filenameIndex : filenameIndex + 1] != extsep:
return p[:dotIndex], p[dotIndex:]
filenameIndex += 1
return p, p[:0]