add dropFromEnd
This commit is contained in:
parent
acb4bcf2db
commit
850d19d038
5 changed files with 10 additions and 6 deletions
|
@ -26,8 +26,7 @@ isRemoteKey k = "remote." `isPrefixOf` k && ".url" `isSuffixOf` k
|
||||||
|
|
||||||
{- Get a remote's name from the config key that specifies its location. -}
|
{- Get a remote's name from the config key that specifies its location. -}
|
||||||
remoteKeyToRemoteName :: String -> RemoteName
|
remoteKeyToRemoteName :: String -> RemoteName
|
||||||
remoteKeyToRemoteName k = intercalate "." $
|
remoteKeyToRemoteName k = intercalate "." $ dropFromEnd 1 $ drop 1 $ splitc '.' k
|
||||||
reverse $ drop 1 $ reverse $ drop 1 $ splitc '.' k
|
|
||||||
|
|
||||||
{- Construct a legal git remote name out of an arbitrary input string.
|
{- Construct a legal git remote name out of an arbitrary input string.
|
||||||
-
|
-
|
||||||
|
|
|
@ -16,6 +16,7 @@ module Types.Export (
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Git.FilePath
|
import Git.FilePath
|
||||||
|
import Utility.Split
|
||||||
|
|
||||||
import qualified System.FilePath.Posix as Posix
|
import qualified System.FilePath.Posix as Posix
|
||||||
|
|
||||||
|
@ -50,4 +51,4 @@ exportDirectories (ExportLocation f) =
|
||||||
subs ps (d:ds) = (d:ps) : subs (d:ps) ds
|
subs ps (d:ds) = (d:ps) : subs (d:ps) ds
|
||||||
|
|
||||||
dirs = map Posix.dropTrailingPathSeparator $
|
dirs = map Posix.dropTrailingPathSeparator $
|
||||||
reverse $ drop 1 $ reverse $ Posix.splitPath f
|
dropFromEnd 1 $ Posix.splitPath f
|
||||||
|
|
|
@ -30,6 +30,7 @@ import Utility.Data
|
||||||
import Utility.PartialPrelude
|
import Utility.PartialPrelude
|
||||||
import Utility.Misc
|
import Utility.Misc
|
||||||
import Utility.Tuple
|
import Utility.Tuple
|
||||||
|
import Utility.Split
|
||||||
|
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Time.Clock
|
import Data.Time.Clock
|
||||||
|
@ -265,7 +266,7 @@ toRecurrance s = case words s of
|
||||||
constructor "month" = Just Monthly
|
constructor "month" = Just Monthly
|
||||||
constructor "year" = Just Yearly
|
constructor "year" = Just Yearly
|
||||||
constructor u
|
constructor u
|
||||||
| "s" `isSuffixOf` u = constructor $ reverse $ drop 1 $ reverse u
|
| "s" `isSuffixOf` u = constructor $ dropFromEnd 1 u
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
withday sd u = do
|
withday sd u = do
|
||||||
c <- constructor u
|
c <- constructor u
|
||||||
|
|
|
@ -28,3 +28,7 @@ splitc c s = case break (== c) s of
|
||||||
-- | same as Data.List.Utils.replace
|
-- | same as Data.List.Utils.replace
|
||||||
replace :: Eq a => [a] -> [a] -> [a] -> [a]
|
replace :: Eq a => [a] -> [a] -> [a] -> [a]
|
||||||
replace old new = intercalate new . split old
|
replace old new = intercalate new . split old
|
||||||
|
|
||||||
|
-- | Only traverses the list once while dropping the last n characters.
|
||||||
|
dropFromEnd :: Int -> [a] -> [a]
|
||||||
|
dropFromEnd n l = zipWith const l (drop n l)
|
||||||
|
|
|
@ -278,8 +278,7 @@ getUrlInfo url uo = case parseURIRelaxed url of
|
||||||
contentDispositionFilename :: String -> Maybe FilePath
|
contentDispositionFilename :: String -> Maybe FilePath
|
||||||
contentDispositionFilename s
|
contentDispositionFilename s
|
||||||
| "attachment; filename=\"" `isPrefixOf` s && "\"" `isSuffixOf` s =
|
| "attachment; filename=\"" `isPrefixOf` s && "\"" `isSuffixOf` s =
|
||||||
Just $ reverse $ drop 1 $ reverse $
|
Just $ dropFromEnd 1 $ drop 1 $ dropWhile (/= '"') s
|
||||||
drop 1 $ dropWhile (/= '"') s
|
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
|
|
||||||
headRequest :: Request -> Request
|
headRequest :: Request -> Request
|
||||||
|
|
Loading…
Reference in a new issue