on master help sign in
Switched out MissingH for an implementation using split
commit21e9c9f5c95dabd60090fdc39c58ddf3dd578a2f authorGeoffrey Roberts <groberts@anchor.net.au> dateThu 22 Jan 2015, 11:24 (12 years ago) parent745dbd0
2 files changed+10−7
servant-jquery.cabal+3−3 src/Servant/JQuery/Internal.hs+7−4
servant-jquery.cabal+3−3
@@ -32,10 +32,10 @@ library
3232 exposed-modules: Servant.JQuery
3333 other-modules: Servant.JQuery.Internal
3434 build-depends: base >=4.5 && <5
35− , servant >= 0.2.1
36− , lens >= 4
37− , MissingH
3835 , charset
36+ , lens >= 4
37+ , servant >= 0.2.1
38+ , split
3939 hs-source-dirs: src
4040 default-language: Haskell2010
4141 ghc-options: -Wall
src/Servant/JQuery/Internal.hs+7−4
@@ -12,9 +12,9 @@ import Data.Char (toLower)
1212import qualified Data.CharSet as Set
1313import qualified Data.CharSet.Unicode.Category as Set
1414import Data.List
15+import Data.List.Split
1516import Data.Monoid
1617import Data.Proxy
17−import Data.String.Utils
1818import GHC.TypeLits
1919import Servant.API
2020
@@ -68,14 +68,17 @@ data HeaderArg = HeaderArg
6868instance Show HeaderArg where
6969 show (HeaderArg n) = toValidFunctionName ("header" <> n)
7070 show (ReplaceHeaderArg n p)
71− | pn `startswith` p = pv <> " + \"" <> rp <> "\""
72− | pn `endswith` p = "\"" <> rp <> "\" + " <> pv
73− | pn `isInfixOf` p = "\"" <> (replace pn ("\" + " <> pv <> " + \"") p) <> "\""
71+ | pn `isPrefixOf` p = pv <> " + \"" <> rp <> "\""
72+ | pn `isSuffixOf` p = "\"" <> rp <> "\" + " <> pv
73+ | pn `isInfixOf` p = "\"" <> (replace pn ("\" + " <> pv <> " + \"") p)
74+ <> "\""
7475 | otherwise = p
7576 where
7677 pv = toValidFunctionName ("header" <> n)
7778 pn = "{" <> n <> "}"
7879 rp = replace pn "" p
80+ -- Nicked from Data.String.Utils, works on lists
81+ replace old new l = intercalate new . splitOn old $ l
7982
8083-- | Attempts to reduce the function name provided to that allowed by JS.
8184-- https://mathiasbynens.be/notes/javascript-identifiers