git.iko.soy/typeable/http-api-data
on master help sign in
Remove dependency on string-conversions package.

This commit replaces all uses of the `cs` function with functions like `pack`, `unpack`, `decodeUtf8`, etc.

commitacc2cd43565e7e47b511dea728a3ef63ee649b12 author(cdep)illabout <cdep.illabout@gmail.com> dateThu 25 Aug 2016, 17:56 (10 years ago) parentac72f9e
2 files changed+15−13
http-api-data.cabal+1−1 src/Web/HttpApiData/Internal/FormUrlEncoded.hs+14−12
http-api-data.cabal+1−1
@@ -30,7 +30,7 @@ library
3030 , time
3131 , time-locale-compat >=0.1.1.0 && <0.2
3232 , network-uri >= 2.6 && < 2.7
33− , string-conversions
33+ , utf8-string >= 1
3434 if flag(use-text-show)
3535 cpp-options: -DUSE_TEXT_SHOW
3636 build-depends: text-show >= 2
src/Web/HttpApiData/Internal/FormUrlEncoded.hs+14−12
@@ -16,17 +16,19 @@ module Web.HttpApiData.Internal.FormUrlEncoded where
1616import Control.Applicative
1717#endif
1818
19−import Control.Arrow (first, left, second)
19+import Control.Arrow (first, left, second)
2020import Control.Monad.State
21−import qualified Data.ByteString.Lazy as BSL
22−import qualified Data.Map as M
21+import qualified Data.ByteString.Lazy as BSL
22+import qualified Data.ByteString.Lazy.UTF8 as BSLUTF8
23+import qualified Data.Map as M
2324import Data.Monoid
24−import Data.String.Conversions (cs)
25−import qualified Data.Text as T
26−import GHC.Exts (IsList (..))
25+import qualified Data.Text as T
26+import Data.Text.Encoding (decodeUtf8With)
27+import Data.Text.Encoding.Error (lenientDecode)
28+import GHC.Exts (IsList (..))
2729import GHC.Generics
28−import Network.URI (escapeURIString, isUnreserved,
29− unEscapeString)
30+import Network.URI (escapeURIString, isUnreserved,
31+ unEscapeString)
3032
3133import Web.HttpApiData.Internal.HttpApiData
3234
@@ -137,7 +139,7 @@ instance (GFromForm f) => GFromForm (M1 C x f) where
137139encodeForm :: Form -> BSL.ByteString
138140encodeForm xs =
139141 let escape :: T.Text -> BSL.ByteString
140− escape = cs . escapeURIString isUnreserved . cs
142+ escape = BSLUTF8.fromString . escapeURIString isUnreserved . T.unpack
141143 encodePair :: (T.Text, T.Text) -> BSL.ByteString
142144 encodePair (k, "") = escape k
143145 encodePair (k, v) = escape k <> "=" <> escape v
@@ -147,7 +149,7 @@ decodeForm :: BSL.ByteString -> Either String Form
147149decodeForm "" = return mempty
148150decodeForm q = do
149151 let xs :: [T.Text]
150− xs = T.splitOn "&" . cs $ q
152+ xs = T.splitOn "&" . decodeUtf8With lenientDecode . mconcat . BSL.toChunks $ q
151153 parsePair :: T.Text -> Either String (T.Text, T.Text)
152154 parsePair p =
153155 case T.splitOn "=" p of
@@ -155,9 +157,9 @@ decodeForm q = do
155157 , unescape v
156158 )
157159 [k] -> return ( unescape k, "" )
158− _ -> Left $ "not a valid pair: " <> cs p
160+ _ -> Left $ "not a valid pair: " <> T.unpack p
159161 unescape :: T.Text -> T.Text
160− unescape = cs . unEscapeString . cs . T.intercalate "%20" . T.splitOn "+"
162+ unescape = T.pack . unEscapeString . T.unpack . T.intercalate "%20" . T.splitOn "+"
161163 toForm <$> mapM parsePair xs
162164
163165data Proxy3 a b c = Proxy3