mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-30 19:54:47 +00:00
cleans up read instance considerably
This commit is contained in:
@@ -14,8 +14,6 @@ import System.Directory
|
|||||||
import System.FilePath
|
import System.FilePath
|
||||||
import Yesod.Core
|
import Yesod.Core
|
||||||
|
|
||||||
import Data.Text (isSuffixOf)
|
|
||||||
|
|
||||||
import Constants
|
import Constants
|
||||||
import Lib.Semver
|
import Lib.Semver
|
||||||
import Lib.Types.Semver
|
import Lib.Types.Semver
|
||||||
@@ -80,13 +78,16 @@ instance KnownSymbol a => Show (Extension a) where
|
|||||||
show e@(Extension file) = file <.> extension e
|
show e@(Extension file) = file <.> extension e
|
||||||
|
|
||||||
instance KnownSymbol a => Read (Extension a) where
|
instance KnownSymbol a => Read (Extension a) where
|
||||||
readsPrec _ s = [(Extension . take (m - n - 1) $ s, "") | toS ext' `isSuffixOf` toS s]
|
readsPrec _ s = [(Extension fileName, "") | ("" <.> fileExt) == ("" <.> ext')]
|
||||||
where
|
where
|
||||||
m = length s
|
(fileName, fileExt) = splitExtension s
|
||||||
ext' = extension (def :: Extension a)
|
ext' = extension (def :: Extension a)
|
||||||
n = if length ext' == 0
|
|
||||||
then -1
|
withPeriod :: String -> String
|
||||||
else length ext'
|
withPeriod word@(a:_) = case a of
|
||||||
|
'.' -> word
|
||||||
|
_ -> "." <> word
|
||||||
|
withPeriod word = word
|
||||||
|
|
||||||
instance KnownSymbol a => PathPiece (Extension a) where
|
instance KnownSymbol a => PathPiece (Extension a) where
|
||||||
fromPathPiece = readMaybe . toS
|
fromPathPiece = readMaybe . toS
|
||||||
|
|||||||
Reference in New Issue
Block a user