From 2575e84f0ed969897dc70b354109af8d5fe6ea5f Mon Sep 17 00:00:00 2001 From: Aaron Greenspan Date: Sun, 5 Jan 2020 23:42:43 -0700 Subject: [PATCH] cleans up read instance considerably --- src/Lib/Registry.hs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Lib/Registry.hs b/src/Lib/Registry.hs index 7df0616..9b42c91 100644 --- a/src/Lib/Registry.hs +++ b/src/Lib/Registry.hs @@ -14,8 +14,6 @@ import System.Directory import System.FilePath import Yesod.Core -import Data.Text (isSuffixOf) - import Constants import Lib.Semver import Lib.Types.Semver @@ -80,13 +78,16 @@ instance KnownSymbol a => Show (Extension a) where show e@(Extension file) = file <.> extension e 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 - m = length s + (fileName, fileExt) = splitExtension s ext' = extension (def :: Extension a) - n = if length ext' == 0 - then -1 - else length ext' + +withPeriod :: String -> String +withPeriod word@(a:_) = case a of + '.' -> word + _ -> "." <> word +withPeriod word = word instance KnownSymbol a => PathPiece (Extension a) where fromPathPiece = readMaybe . toS