path-pieces-0.1.2/0000755000000000000000000000000012027767264012117 5ustar0000000000000000path-pieces-0.1.2/Setup.lhs0000644000000000000000000000016212027767264013726 0ustar0000000000000000#!/usr/bin/env runhaskell > module Main where > import Distribution.Simple > main :: IO () > main = defaultMain path-pieces-0.1.2/path-pieces.cabal0000644000000000000000000000204612027767264015307 0ustar0000000000000000name: path-pieces version: 0.1.2 license: BSD3 license-file: LICENSE author: Michael Snoyman maintainer: Michael Snoyman synopsis: Components of paths. category: Web, Yesod stability: unstable cabal-version: >= 1.8 build-type: Simple extra-source-files: test/main.hs library build-depends: base >= 4 && < 5 , text >= 0.5 && < 0.12 , time exposed-modules: Web.PathPieces ghc-options: -Wall test-suite test type: exitcode-stdio-1.0 main-is: main.hs hs-source-dirs: test ghc-options: -Wall build-depends: HUnit , hspec >= 1.3 , file-location >= 0.4 && < 0.5 , base >= 4 && < 5 , QuickCheck , path-pieces , text source-repository head type: git location: https://github.com/yesodweb/path-pieces path-pieces-0.1.2/LICENSE0000644000000000000000000000253012027767264013124 0ustar0000000000000000The following license covers this documentation, and the source code, except where otherwise indicated. Copyright 2009, Michael Snoyman. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. path-pieces-0.1.2/Web/0000755000000000000000000000000012027767264012634 5ustar0000000000000000path-pieces-0.1.2/Web/PathPieces.hs0000644000000000000000000000516112027767264015220 0ustar0000000000000000{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} module Web.PathPieces ( PathPiece (..) , PathMultiPiece (..) -- * Deprecated , toSinglePiece , toMultiPiece , fromSinglePiece , fromMultiPiece ) where import Data.Int (Int64) import qualified Data.Text as S import qualified Data.Text.Lazy as L import qualified Data.Text.Read import Data.Time (Day) class PathPiece s where fromPathPiece :: S.Text -> Maybe s toPathPiece :: s -> S.Text instance PathPiece String where fromPathPiece = Just . S.unpack toPathPiece = S.pack instance PathPiece S.Text where fromPathPiece = Just toPathPiece = id instance PathPiece L.Text where fromPathPiece = Just . L.fromChunks . return toPathPiece = S.concat . L.toChunks instance PathPiece Integer where fromPathPiece s = case Data.Text.Read.decimal s of Right (i, _) -> Just i Left _ -> Nothing toPathPiece = S.pack . show instance PathPiece Int where fromPathPiece s = case Data.Text.Read.decimal s of Right (i, _) -> Just i Left _ -> Nothing toPathPiece = S.pack . show instance PathPiece Int64 where fromPathPiece s = case Data.Text.Read.decimal s of Right (i, _) -> Just i Left _ -> Nothing toPathPiece = S.pack . show instance PathPiece Day where fromPathPiece t = case reads $ S.unpack t of [(a,"")] -> Just a _ -> Nothing toPathPiece = S.pack . show class PathMultiPiece s where fromPathMultiPiece :: [S.Text] -> Maybe s toPathMultiPiece :: s -> [S.Text] instance PathMultiPiece [String] where fromPathMultiPiece = Just . map S.unpack toPathMultiPiece = map S.pack instance PathMultiPiece [S.Text] where fromPathMultiPiece = Just toPathMultiPiece = id instance PathMultiPiece [L.Text] where fromPathMultiPiece = Just . map (L.fromChunks . return) toPathMultiPiece = map $ S.concat . L.toChunks {-# DEPRECATED toSinglePiece "Use toPathPiece instead of toSinglePiece" #-} toSinglePiece :: PathPiece p => p -> S.Text toSinglePiece = toPathPiece {-# DEPRECATED fromSinglePiece "Use fromPathPiece instead of fromSinglePiece" #-} fromSinglePiece :: PathPiece p => S.Text -> Maybe p fromSinglePiece = fromPathPiece {-# DEPRECATED toMultiPiece "Use toPathMultiPiece instead of toMultiPiece" #-} toMultiPiece :: PathMultiPiece ps => ps -> [S.Text] toMultiPiece = toPathMultiPiece {-# DEPRECATED fromMultiPiece "Use fromPathMultiPiece instead of fromMultiPiece" #-} fromMultiPiece :: PathMultiPiece ps => [S.Text] -> Maybe ps fromMultiPiece = fromPathMultiPiece path-pieces-0.1.2/test/0000755000000000000000000000000012027767264013076 5ustar0000000000000000path-pieces-0.1.2/test/main.hs0000644000000000000000000000422112027767264014355 0ustar0000000000000000{-# Language ScopedTypeVariables #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Main where import Test.Hspec import Test.Hspec.QuickCheck(prop) import Test.QuickCheck import Web.PathPieces import qualified Data.Text as T import Data.Maybe (fromJust) -- import FileLocation (debug) instance Arbitrary T.Text where arbitrary = fmap T.pack arbitrary main :: IO () main = hspec spec spec :: Spec spec = do describe "PathPiece" $ do prop "toPathPiece <=> fromPathPiece String" $ \(p::String) -> case (fromPathPiece . toPathPiece) p of Nothing -> null p Just pConverted -> p == pConverted prop "toPathPiece <=> fromPathPiece String" $ \(p::T.Text) -> case (fromPathPiece . toPathPiece) p of Nothing -> T.null p Just pConverted -> p == pConverted prop "toPathPiece <=> fromPathPiece String" $ \(p::Int) -> case (fromPathPiece . toPathPiece) p of Nothing -> p < 0 Just pConverted -> p == pConverted describe "PathMultiPiece" $ do prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[String]) -> p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[T.Text]) -> p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p describe "SinglePiece" $ do prop "toPathPiece <=> fromPathPiece String" $ \(p::String) -> case (fromPathPiece . toPathPiece) p of Nothing -> null p Just pConverted -> p == pConverted prop "toPathPiece <=> fromPathPiece String" $ \(p::T.Text) -> case (fromPathPiece . toPathPiece) p of Nothing -> T.null p Just pConverted -> p == pConverted prop "toPathPiece <=> fromPathPiece String" $ \(p::Int) -> case (fromPathPiece . toPathPiece) p of Nothing -> p < 0 Just pConverted -> p == pConverted describe "MultiPiece" $ do prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[String]) -> p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p prop "toPathMultiPiece <=> fromPathMultiPiece String" $ \(p::[T.Text]) -> p == (fromJust . fromPathMultiPiece . toPathMultiPiece) p