From 149a0470b73781022e584aaeaa7ce871d6f4173b Mon Sep 17 00:00:00 2001 From: Joris Date: Tue, 19 Jun 2018 22:49:16 +0200 Subject: Add automatic tests on remote pages --- src/parser/haskell/Parser/Utils.hs | 48 -------------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 src/parser/haskell/Parser/Utils.hs (limited to 'src/parser/haskell/Parser/Utils.hs') diff --git a/src/parser/haskell/Parser/Utils.hs b/src/parser/haskell/Parser/Utils.hs deleted file mode 100644 index 4768327..0000000 --- a/src/parser/haskell/Parser/Utils.hs +++ /dev/null @@ -1,48 +0,0 @@ -module Parser.Utils - ( getTagsBefore - , getTagsAfter - , getTagsBetween - , getTagAttributes - , getTagAttribute - , getTagTextAfter - ) where - -import Data.List (find, findIndex) -import Data.Maybe (catMaybes, listToMaybe) -import Data.Text (Text) -import qualified Data.Text as T -import Text.HTML.TagSoup - -getTagsBefore :: Text -> [Tag Text] -> [Tag Text] -getTagsBefore selector = takeWhile (~/= (T.unpack selector)) - -getTagsAfter :: Text -> [Tag Text] -> [Tag Text] -getTagsAfter selector = drop 1 . dropWhile (~/= (T.unpack selector)) - -getTagsBetween :: Text -> Text -> [Tag Text] -> [Tag Text] -getTagsBetween begin end = getTagsBefore end . getTagsAfter begin - -getTagAttributes :: Text -> Text -> [Tag Text] -> [Text] -getTagAttributes selector attribute = - catMaybes - . fmap (maybeTagAttribute attribute) - . filter (~== (T.unpack selector)) - -getTagAttribute :: Text -> Text -> [Tag Text] -> Maybe Text -getTagAttribute selector attribute = - listToMaybe - . getTagAttributes selector attribute - -getTagTextAfter :: Text -> [Tag Text] -> Maybe Text -getTagTextAfter selector tags = - case findIndex (~== (T.unpack selector)) tags of - Just index -> fmap T.strip $ safeGetAt (index + 1) tags >>= maybeTagText - Nothing -> Nothing - -maybeTagAttribute :: Text -> Tag Text -> Maybe Text -maybeTagAttribute name (TagOpen _ xs) = - fmap snd . find (\(x, _) -> x == name) $ xs -maybeTagAttribute _ _ = Nothing - -safeGetAt :: Int -> [a] -> Maybe a -safeGetAt index = listToMaybe . drop index -- cgit v1.2.3