feat(library/init/system/filepath): add dirName

This commit is contained in:
Leonardo de Moura 2019-07-26 14:53:54 -07:00
parent b902dc3dac
commit 2ddc797f65
2 changed files with 16 additions and 1 deletions

View file

@ -131,6 +131,16 @@ partial def posOfAux (s : String) (c : Char) (stopPos : Pos) : Pos → Pos
@[inline] def posOf (s : String) (c : Char) : Pos :=
posOfAux s c s.bsize 0
partial def revPosOfAux (s : String) (c : Char) : Pos → Option Pos
| pos :=
if s.get pos == c then some pos
else if pos == 0 then none
else revPosOfAux (s.prev pos)
def revPosOf (s : String) (c : Char) : Option Pos :=
if s.bsize == 0 then none
else revPosOfAux s c (s.prev s.bsize)
private def utf8ExtractAux₂ : List Char → Pos → Pos → List Char
| [] _ _ := []
| (c::cs) i e := if i = e then [] else c :: utf8ExtractAux₂ cs (i + csize c) e

View file

@ -5,7 +5,7 @@ Authors: Leonardo de Moura
-/
prelude
import init.system.platform
import init.data.char.basic
import init.data.string.basic
namespace System
namespace FilePath
@ -27,5 +27,10 @@ if isWindows then ';' else ':'
def extSeparator : Char :=
'.'
def dirName (fname : String) : String :=
match fname.revPosOf pathSeparator with
| none => "."
| some pos => { Substring . str := fname, startPos := 0, stopPos := pos }.toString
end FilePath
end System