git.iko.soy/typeable/http-api-data
on master help sign in
Initial version
commit14951c26e3b9c228d75fd95c549a51c15cf42ef9 authorMichael Snoyman <michael@snoyman.com> dateTue 19 Jul 2011, 08:37 (15 years ago) parentda9253e
4 files changed+109
LICENSE+25 Setup.lhs+7 Web/PathPieces.hs+55 path-pieces.cabal+22
LICENSEnew file+25
@@ -0,0 +1,25 @@
1+The following license covers this documentation, and the source code, except
2+where otherwise indicated.
3+
4+Copyright 2009, Michael Snoyman. All rights reserved.
5+
6+Redistribution and use in source and binary forms, with or without
7+modification, are permitted provided that the following conditions are met:
8+
9+* Redistributions of source code must retain the above copyright notice, this
10+ list of conditions and the following disclaimer.
11+
12+* Redistributions in binary form must reproduce the above copyright notice,
13+ this list of conditions and the following disclaimer in the documentation
14+ and/or other materials provided with the distribution.
15+
16+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR
17+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
20+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
22+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Setup.lhsnew file+7
@@ -0,0 +1,7 @@
1+#!/usr/bin/env runhaskell
2+
3+> module Main where
4+> import Distribution.Simple
5+
6+> main :: IO ()
7+> main = defaultMain
Web/PathPieces.hsnew file+55
@@ -0,0 +1,55 @@
1+{-# LANGUAGE FlexibleInstances #-}
2+{-# LANGUAGE TypeSynonymInstances #-}
3+module Web.PathPieces
4+ ( SinglePiece (..)
5+ , MultiPiece (..)
6+ ) where
7+
8+import Data.Int (Int64)
9+import qualified Data.Text as S
10+import qualified Data.Text.Lazy as L
11+import qualified Data.Text.Read
12+
13+class SinglePiece s where
14+ fromSinglePiece :: S.Text -> Maybe s
15+ toSinglePiece :: s -> S.Text
16+instance SinglePiece String where
17+ fromSinglePiece s = if S.null s then Nothing else Just (S.unpack s)
18+ toSinglePiece = S.pack
19+instance SinglePiece S.Text where
20+ fromSinglePiece s = if S.null s then Nothing else Just s
21+ toSinglePiece = id
22+instance SinglePiece L.Text where
23+ fromSinglePiece s = if S.null s then Nothing else Just (L.fromChunks [s])
24+ toSinglePiece = S.concat . L.toChunks
25+instance SinglePiece Integer where
26+ fromSinglePiece s =
27+ case Data.Text.Read.decimal s of
28+ Right (i, _) -> Just i
29+ Left _ -> Nothing
30+ toSinglePiece = S.pack . show
31+instance SinglePiece Int where
32+ fromSinglePiece s =
33+ case Data.Text.Read.decimal s of
34+ Right (i, _) -> Just i
35+ Left _ -> Nothing
36+ toSinglePiece = S.pack . show
37+instance SinglePiece Int64 where
38+ fromSinglePiece s =
39+ case Data.Text.Read.decimal s of
40+ Right (i, _) -> Just i
41+ Left _ -> Nothing
42+ toSinglePiece = S.pack . show
43+
44+class MultiPiece s where
45+ fromMultiPiece :: [S.Text] -> Maybe s
46+ toMultiPiece :: s -> [S.Text]
47+instance MultiPiece [String] where
48+ fromMultiPiece = Just . map S.unpack
49+ toMultiPiece = map S.pack
50+instance MultiPiece [S.Text] where
51+ fromMultiPiece = Just
52+ toMultiPiece = id
53+instance MultiPiece [L.Text] where
54+ fromMultiPiece = Just . map (L.fromChunks . return)
55+ toMultiPiece = map $ S.concat . L.toChunks
path-pieces.cabalnew file+22
@@ -0,0 +1,22 @@
1+name: path-pieces
2+version: 0.0.0
3+license: BSD3
4+license-file: LICENSE
5+author: Michael Snoyman <michael@snoyman.com>
6+maintainer: Michael Snoyman <michael@snoyman.com>
7+synopsis: Components of paths.
8+category: Web, Yesod
9+stability: unstable
10+cabal-version: >= 1.6
11+build-type: Simple
12+homepage: http://github.com/snoyberg/path-pieces
13+
14+library
15+ build-depends: base >= 4 && < 5
16+ , text >= 0.5 && < 0.12
17+ exposed-modules: Web.PathPieces
18+ ghc-options: -Wall
19+
20+source-repository head
21+ type: git
22+ location: git://github.com/snoyberg/path-pieces.git