module Attoparsec.Data.Explicit
(
char,
text,
utf8Bytes,
bool,
signedIntegral,
unsignedIntegral,
A.double,
A.scientific,
B.timeOfDayInISO8601,
B.dayInISO8601,
B.timeZoneInISO8601,
B.utcTimeInISO8601,
B.diffTime,
B.nominalDiffTime,
)
where
import Attoparsec.Data.Prelude hiding (bool)
import qualified Data.Attoparsec.Text as A
import qualified Attoparsec.Time as B
import qualified Data.Text.Encoding as C
char :: A.Parser Char
char =
A.anyChar
text :: A.Parser Text
text =
A.takeText
utf8Bytes :: A.Parser ByteString
utf8Bytes =
C.encodeUtf8 <$> A.takeText
bool :: A.Parser Bool
bool =
A.anyChar >>= \case
'0' -> return False
'1' -> return True
'f' -> A.asciiCI "alse" $> False <|> pure False
'F' -> A.asciiCI "alse" $> False <|> pure False
't' -> A.asciiCI "rue" $> True <|> pure True
'T' -> A.asciiCI "rue" $> True <|> pure True
'n' -> A.satisfy (A.inClass "oO") $> False <|> pure False
'N' -> A.satisfy (A.inClass "oO") $> False <|> pure False
'y' -> A.asciiCI "es" $> True <|> pure True
'Y' -> A.asciiCI "es" $> True <|> pure True
_ -> empty
signedIntegral :: Integral a => A.Parser a
signedIntegral =
A.signed A.decimal
unsignedIntegral :: Integral a => A.Parser a
unsignedIntegral =
A.decimal