Permalink
Browse files

Documentation and cosmetic improvements

  • Loading branch information...
1 parent dd7971a commit d85b9480eb7421af04b7104b0f07862352210425 @ozataman ozataman committed Aug 8, 2012
Showing with 7 additions and 13 deletions.
  1. +0 −10 haskell/src/Web/UAParser.hs
  2. +7 −2 haskell/src/Web/UAParser/Core.hs
  3. +0 −1 haskell/ua-parser.cabal
@@ -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 Text.Regex.PCRE.Light
-------------------------------------------------------------------------------
import Paths_ua_parser
import Web.UAParser.Core
@@ -56,9 +56,10 @@ test =
-------------------------------------------------------------------------------
+-- | Parse a given User-Agent string
parseUA
:: UAConfig
- -- ^ Loaded parser data
+ -- ^ Loaded parser configuration data
-> ByteString
-- ^ User-Agent string to be parsed
-> Maybe UAResult
@@ -80,6 +81,7 @@ parseUA UAConfig{..} bs = foldr mplus Nothing $ map go uaParsers
-------------------------------------------------------------------------------
+-- | Results datatype for the parsed User-Agent
data UAResult = UAResult {
uarFamily :: Text
, uarV1 :: Maybe Text
@@ -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{..} =
T.intercalate "." . catMaybes . takeWhile isJust $ [uarV1, uarV2, uarV3]
@@ -107,6 +109,7 @@ instance Default UAResult where
-------------------------------------------------------------------------------
+-- | Parse OS from given User-Agent string
parseOS
:: UAConfig
-- ^ Loaded parser data
@@ -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
@@ -197,6 +201,7 @@ data DevParser = DevParser {
-------------------------------------------------------------------------------
+parseRegex :: Object -> Parser Regex
parseRegex v = flip compile [] `liftM` (v .: "regex")
@@ -12,7 +12,6 @@ Cabal-version: >=1.6
data-files:
./*.yaml
- test/test_resources/*.yaml
Library
hs-source-dirs: src

0 comments on commit d85b948

Please sign in to comment.