aboutsummaryrefslogtreecommitdiff
path: root/haddock-library/src/Documentation/Haddock
diff options
context:
space:
mode:
authorSimon Hengel <sol@typeful.net>2014-06-18 11:01:18 +0800
committerSimon Hengel <sol@typeful.net>2014-06-18 11:01:18 +0800
commitb973784c65c4d20c893b5377a7ced557d0a420cf (patch)
tree8b2adbcbe08d8ddbe97fe488160e0452f5ca04a4 /haddock-library/src/Documentation/Haddock
parentfc160334cbeea731301fc723d1da5577dc2e40a1 (diff)
Compatibility with older versions of base and bytestring
Diffstat (limited to 'haddock-library/src/Documentation/Haddock')
-rw-r--r--haddock-library/src/Documentation/Haddock/Parser.hs2
-rw-r--r--haddock-library/src/Documentation/Haddock/Parser/Util.hs19
2 files changed, 19 insertions, 2 deletions
diff --git a/haddock-library/src/Documentation/Haddock/Parser.hs b/haddock-library/src/Documentation/Haddock/Parser.hs
index 3d146d33..f0597462 100644
--- a/haddock-library/src/Documentation/Haddock/Parser.hs
+++ b/haddock-library/src/Documentation/Haddock/Parser.hs
@@ -437,7 +437,7 @@ autoUrl = mkLink <$> url
where
url = mappend <$> ("http://" <|> "https://" <|> "ftp://") <*> takeWhile1 (not . isSpace)
mkLink :: BS.ByteString -> DocH mod a
- mkLink s = case BS.unsnoc s of
+ mkLink s = case unsnoc s of
Just (xs, x) | x `elem` ",.!?" -> DocHyperlink (Hyperlink (decodeUtf8 xs) Nothing) <> DocString [x]
_ -> DocHyperlink (Hyperlink (decodeUtf8 s) Nothing)
diff --git a/haddock-library/src/Documentation/Haddock/Parser/Util.hs b/haddock-library/src/Documentation/Haddock/Parser/Util.hs
index 25dba2d5..ef2af140 100644
--- a/haddock-library/src/Documentation/Haddock/Parser/Util.hs
+++ b/haddock-library/src/Documentation/Haddock/Parser/Util.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
-- |
-- Module : Documentation.Haddock.Parser.Util
-- Copyright : (c) Mateusz Kowalczyk 2013-2014,
@@ -9,7 +10,14 @@
-- Portability : portable
--
-- Various utility functions used by the parser.
-module Documentation.Haddock.Parser.Util where
+module Documentation.Haddock.Parser.Util (
+ unsnoc
+, strip
+, takeUntil
+, makeLabeled
+, takeHorizontalSpace
+, skipHorizontalSpace
+) where
import Control.Applicative
import Control.Monad (mfilter)
@@ -18,6 +26,15 @@ import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS
import Prelude hiding (takeWhile)
+#if MIN_VERSION_bytestring(0,10,2)
+import Data.ByteString.Char8 (unsnoc)
+#else
+unsnoc :: ByteString -> Maybe (ByteString, Char)
+unsnoc bs
+ | BS.null bs = Nothing
+ | otherwise = Just (BS.init bs, BS.last bs)
+#endif
+
-- | Remove all leading and trailing whitespace
strip :: String -> String
strip = (\f -> f . f) $ dropWhile isSpace . reverse