Skip to content
This repository has been archived by the owner on Jul 19, 2018. It is now read-only.

Commit

Permalink
Documentation and cosmetic improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ozataman committed Aug 8, 2012
1 parent dd7971a commit d85b948
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
10 changes: 0 additions & 10 deletions haskell/src/Web/UAParser.hs
Expand Up @@ -19,17 +19,7 @@ module Web.UAParser




------------------------------------------------------------------------------- -------------------------------------------------------------------------------
import Control.Applicative
import Control.Monad
import Data.Aeson
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Data.Yaml
import System.FilePath.Posix import System.FilePath.Posix
import Text.Regex.PCRE.Light
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
import Paths_ua_parser import Paths_ua_parser
import Web.UAParser.Core import Web.UAParser.Core
Expand Down
9 changes: 7 additions & 2 deletions haskell/src/Web/UAParser/Core.hs
Expand Up @@ -56,9 +56,10 @@ test =




------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- | Parse a given User-Agent string
parseUA parseUA
:: UAConfig :: UAConfig
-- ^ Loaded parser data -- ^ Loaded parser configuration data
-> ByteString -> ByteString
-- ^ User-Agent string to be parsed -- ^ User-Agent string to be parsed
-> Maybe UAResult -> Maybe UAResult
Expand All @@ -80,6 +81,7 @@ parseUA UAConfig{..} bs = foldr mplus Nothing $ map go uaParsers




------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- | Results datatype for the parsed User-Agent
data UAResult = UAResult { data UAResult = UAResult {
uarFamily :: Text uarFamily :: Text
, uarV1 :: Maybe Text , uarV1 :: Maybe Text
Expand All @@ -89,7 +91,7 @@ data UAResult = UAResult {




------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- | Construct a browser versionstring from 'UAResult' -- | Construct a browser version-string from 'UAResult'
uarVersion :: UAResult -> Text uarVersion :: UAResult -> Text
uarVersion UAResult{..} = uarVersion UAResult{..} =
T.intercalate "." . catMaybes . takeWhile isJust $ [uarV1, uarV2, uarV3] T.intercalate "." . catMaybes . takeWhile isJust $ [uarV1, uarV2, uarV3]
Expand All @@ -107,6 +109,7 @@ instance Default UAResult where




------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- | Parse OS from given User-Agent string
parseOS parseOS
:: UAConfig :: UAConfig
-- ^ Loaded parser data -- ^ Loaded parser data
Expand Down Expand Up @@ -161,6 +164,7 @@ loadConfig fp = either error id `fmap` decodeFile' fp




------------------------------------------------------------------------------- -------------------------------------------------------------------------------
decodeFile' :: FromJSON a => FilePath -> IO (Either String a)
decodeFile' fp = decodeEither `fmap` B.readFile fp decodeFile' fp = decodeEither `fmap` B.readFile fp




Expand Down Expand Up @@ -197,6 +201,7 @@ data DevParser = DevParser {




------------------------------------------------------------------------------- -------------------------------------------------------------------------------
parseRegex :: Object -> Parser Regex
parseRegex v = flip compile [] `liftM` (v .: "regex") parseRegex v = flip compile [] `liftM` (v .: "regex")




Expand Down
1 change: 0 additions & 1 deletion haskell/ua-parser.cabal
Expand Up @@ -12,7 +12,6 @@ Cabal-version: >=1.6


data-files: data-files:
./*.yaml ./*.yaml
test/test_resources/*.yaml


Library Library
hs-source-dirs: src hs-source-dirs: src
Expand Down

0 comments on commit d85b948

Please sign in to comment.