path-pieces (empty) → 0.0.0
raw patch · 4 files changed
+109/−0 lines, 4 filesdep +basedep +textsetup-changed
Dependencies added: base, text
Files
- LICENSE +25/−0
- Setup.lhs +7/−0
- Web/PathPieces.hs +55/−0
- path-pieces.cabal +22/−0
+ LICENSE view
@@ -0,0 +1,25 @@+The 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.
+ Setup.lhs view
@@ -0,0 +1,7 @@+#!/usr/bin/env runhaskell++> module Main where+> import Distribution.Simple++> main :: IO ()+> main = defaultMain
+ Web/PathPieces.hs view
@@ -0,0 +1,55 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE TypeSynonymInstances #-}+module Web.PathPieces+ ( SinglePiece (..)+ , MultiPiece (..)+ ) where++import Data.Int (Int64)+import qualified Data.Text as S+import qualified Data.Text.Lazy as L+import qualified Data.Text.Read++class SinglePiece s where+ fromSinglePiece :: S.Text -> Maybe s+ toSinglePiece :: s -> S.Text+instance SinglePiece String where+ fromSinglePiece s = if S.null s then Nothing else Just (S.unpack s)+ toSinglePiece = S.pack+instance SinglePiece S.Text where+ fromSinglePiece s = if S.null s then Nothing else Just s+ toSinglePiece = id+instance SinglePiece L.Text where+ fromSinglePiece s = if S.null s then Nothing else Just (L.fromChunks [s])+ toSinglePiece = S.concat . L.toChunks+instance SinglePiece Integer where+ fromSinglePiece s =+ case Data.Text.Read.decimal s of+ Right (i, _) -> Just i+ Left _ -> Nothing+ toSinglePiece = S.pack . show+instance SinglePiece Int where+ fromSinglePiece s =+ case Data.Text.Read.decimal s of+ Right (i, _) -> Just i+ Left _ -> Nothing+ toSinglePiece = S.pack . show+instance SinglePiece Int64 where+ fromSinglePiece s =+ case Data.Text.Read.decimal s of+ Right (i, _) -> Just i+ Left _ -> Nothing+ toSinglePiece = S.pack . show++class MultiPiece s where+ fromMultiPiece :: [S.Text] -> Maybe s+ toMultiPiece :: s -> [S.Text]+instance MultiPiece [String] where+ fromMultiPiece = Just . map S.unpack+ toMultiPiece = map S.pack+instance MultiPiece [S.Text] where+ fromMultiPiece = Just+ toMultiPiece = id+instance MultiPiece [L.Text] where+ fromMultiPiece = Just . map (L.fromChunks . return)+ toMultiPiece = map $ S.concat . L.toChunks
+ path-pieces.cabal view
@@ -0,0 +1,22 @@+name: path-pieces+version: 0.0.0+license: BSD3+license-file: LICENSE+author: Michael Snoyman <michael@snoyman.com>+maintainer: Michael Snoyman <michael@snoyman.com>+synopsis: Components of paths.+category: Web, Yesod+stability: unstable+cabal-version: >= 1.6+build-type: Simple+homepage: http://github.com/snoyberg/path-pieces++library+ build-depends: base >= 4 && < 5+ , text >= 0.5 && < 0.12+ exposed-modules: Web.PathPieces+ ghc-options: -Wall++source-repository head+ type: git+ location: git://github.com/snoyberg/path-pieces.git