1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-28 08:03:07 +03:00

use encodeUtf8 instead of C8.pack

This commit is contained in:
Juan Bono 2017-07-08 21:38:07 -03:00
parent 7fb70a0f0d
commit 421ef0f986

View File

@ -119,8 +119,8 @@ import Data.Generics.Uniplate.Data (transform)
import qualified Codec.Binary.UTF8.String as UTF8 import qualified Codec.Binary.UTF8.String as UTF8
import qualified Network.URI as URI import qualified Network.URI as URI
-- needed for parsing urls -- needed for parsing urls
import qualified Data.ByteString.Char8 as C8 import Data.Text.Encoding (encodeUtf8, decodeUtf8)
import Network.HTTP.Types (Query, parseQuery) import Network.HTTP.Types (Query, parseQuery)
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- Lists -- Lists
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
@ -270,20 +270,22 @@ showKeyword (Just "") = ""
showKeyword (Just keyword) = " (\"" <> T.toString keyword <> "\")" showKeyword (Just keyword) = " (\"" <> T.toString keyword <> "\")"
showKeyword _ = "" showKeyword _ = ""
extractQueryList :: Url -> Query toBS :: String -> ByteString
extractQueryList url toBS = encodeUtf8 . T.pack
= parseQuery . fromJust
$ C8.pack . URI.uriQuery
<$> URI.parseURI (T.toString url)
extractKeyword :: Url -> String extractQuery :: Url -> Maybe Query
extractKeyword url = do extractQuery url = getQuery <$> parse url
let queryList = extractQueryList url where
e <- lst getQuery = parseQuery . toBS . URI.uriQuery
case lookup e queryList of parse = URI.parseURI . T.toString
Just r -> C8.unpack . fromJust $ r
Nothing -> "" extractKeyword :: Url -> Maybe Text
where lst = ["q", "p", "text"] extractKeyword url
= case extractQuery url of
Just query -> decodeUtf8 <$> lookupQuery query
Nothing -> Nothing
where
lookupQuery = join . (lookup "q" <> lookup "p" <> lookup "text")
toReferrerView :: Url -> ReferrerView toReferrerView :: Url -> ReferrerView
toReferrerView url toReferrerView url
@ -294,7 +296,7 @@ toReferrerView url
uri = URI.parseURI $ T.toString url uri = URI.parseURI $ T.toString url
uriAuth = fromJust $ uri >>= URI.uriAuthority uriAuth = fromJust $ uri >>= URI.uriAuthority
domain = T.pack $ URI.uriRegName uriAuth domain = T.pack $ URI.uriRegName uriAuth
keyword = Just . T.pack . extractKeyword $ url keyword = extractKeyword url
eqKeyOrUrl :: ReferrerView -> ReferrerView -> Bool eqKeyOrUrl :: ReferrerView -> ReferrerView -> Bool
eqKeyOrUrl (RefUrl u1) (RefUrl u2) = u1 == u2 eqKeyOrUrl (RefUrl u1) (RefUrl u2) = u1 == u2