From 9fa2aeb489c1fe9aa6ac8013d77002f3c129f88d Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 24 Mar 2022 11:38:55 -0700 Subject: RTF reader: more efficient parsing of command parameters. --- src/Text/Pandoc/Readers/RTF.hs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/RTF.hs b/src/Text/Pandoc/Readers/RTF.hs index 7caa3925f..30bbe6c07 100644 --- a/src/Text/Pandoc/Readers/RTF.hs +++ b/src/Text/Pandoc/Readers/RTF.hs @@ -30,7 +30,7 @@ import Text.Pandoc.Class.PandocMonad (PandocMonad (..), insertMedia) import Text.Pandoc.Definition import Text.Pandoc.Options import Text.Pandoc.Parsing -import Text.Pandoc.Shared (safeRead, tshow) +import Text.Pandoc.Shared (tshow) import Data.Char (isAlphaNum, chr, isAscii, isLetter, isSpace, ord) import qualified Data.ByteString.Lazy as BL import Data.Digest.Pure.SHA (sha1, showDigest) @@ -252,10 +252,18 @@ tok = do dat <- BL.pack . map (fromIntegral . ord) <$> count n anyChar return $ BinData dat parameter = do - hyph <- string "-" <|> pure "" + hyph <- option False $ True <$ char '-' rest <- many digit - let pstr = T.pack $ hyph <> rest - return $ safeRead pstr + if null rest + then return Nothing + else do + let pstr = T.pack rest + case TR.decimal pstr of + Right (i,_) -> + return $ Just $ if hyph + then (-1) * i + else i + _ -> return Nothing hexVal = do char '\'' x <- hexDigit -- cgit v1.2.3