adeiu, MissingH
Removed dependency on MissingH, instead depending on the split library. After laying groundwork for this since 2015, it was mostly straightforward. Added Utility.Tuple and Utility.Split. Eyeballed System.Path.WildMatch while implementing the same thing. Since MissingH's progress meter display was being used, I re-implemented my own. Bonus: Now progress is displayed for transfers of files of unknown size. This commit was sponsored by Shane-o on Patreon.
This commit is contained in:
parent
6dd806f1ad
commit
a1730cd6af
37 changed files with 230 additions and 101 deletions
|
@ -1,3 +1,5 @@
|
|||
{-# LANGUAGE PackageImports #-}
|
||||
|
||||
{- file globbing
|
||||
-
|
||||
- Copyright 2014 Joey Hess <id@joeyh.name>
|
||||
|
@ -14,10 +16,9 @@ module Utility.Glob (
|
|||
|
||||
import Utility.Exception
|
||||
|
||||
import System.Path.WildMatch
|
||||
|
||||
import "regex-tdfa" Text.Regex.TDFA
|
||||
import "regex-tdfa" Text.Regex.TDFA.String
|
||||
import Data.Char
|
||||
|
||||
newtype Glob = Glob Regex
|
||||
|
||||
|
@ -30,11 +31,31 @@ compileGlob glob globcase = Glob $
|
|||
Right r -> r
|
||||
Left _ -> giveup $ "failed to compile regex: " ++ regex
|
||||
where
|
||||
regex = '^':wildToRegex glob
|
||||
regex = '^' : wildToRegex glob ++ "$"
|
||||
casesentitive = case globcase of
|
||||
CaseSensative -> True
|
||||
CaseInsensative -> False
|
||||
|
||||
wildToRegex :: String -> String
|
||||
wildToRegex = concat . go
|
||||
where
|
||||
go [] = []
|
||||
go ('*':xs) = ".*" : go xs
|
||||
go ('?':xs) = "." : go xs
|
||||
go ('[':'!':xs) = "[^" : inpat xs
|
||||
go ('[':xs) = "[" : inpat xs
|
||||
go (x:xs)
|
||||
| isDigit x || isAlpha x = [x] : go xs
|
||||
| otherwise = esc x : go xs
|
||||
|
||||
inpat [] = []
|
||||
inpat (x:xs) = case x of
|
||||
']' -> "]" : go xs
|
||||
'\\' -> esc x : inpat xs
|
||||
_ -> [x] : inpat xs
|
||||
|
||||
esc c = ['\\', c]
|
||||
|
||||
matchGlob :: Glob -> String -> Bool
|
||||
matchGlob (Glob regex) val =
|
||||
case execute regex val of
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue