summaryrefslogtreecommitdiff
path: root/lib/Paths.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Paths.hs')
-rw-r--r--lib/Paths.hs21
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/Paths.hs b/lib/Paths.hs
index 4082268..b628ee8 100644
--- a/lib/Paths.hs
+++ b/lib/Paths.hs
@@ -1,10 +1,11 @@
+{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
-- | Paths are horrible, so they have their own module now.
-- I just hope you are running this on some kind of Unix
module Paths where
-import Data.Text (Text)
+import Data.Text (Text, isPrefixOf)
import qualified Data.Text as T
import System.FilePath (splitPath)
import System.FilePath.Posix ((</>))
@@ -18,21 +19,17 @@ data RelPath = Path Int Text (Maybe Text)
deriving (Show, Eq, Ord)
-extractDomain :: Text -> Maybe Text
-extractDomain url =
- let (_,_,_,matches) = url =~ ("^https://([^/]+)/?.*$" :: Text) :: (Text,Text,Text,[Text])
- in case matches of
- [domain] -> Just domain
- _ -> Nothing
-
+data PathResult = OkRelPath RelPath | AbsolutePath | NotAPath | UnderscoreMapLink | AtMapLink
-- | horrible regex parsing for filepaths that is hopefully kinda safe
-parsePath :: Text -> Maybe RelPath
+parsePath :: Text -> PathResult
parsePath text =
- if rest =~ ("^([^/]*[^\\./]/)*[^/]*[^\\./]$" :: Text) :: Bool
- then Just $ Path up path fragment
- else Nothing
+ if | rest =~ ("^([^/]*[^\\./]/)*[^/]*[^\\./]$" :: Text) -> OkRelPath (Path up path fragment)
+ | "/_/" `isPrefixOf` text -> UnderscoreMapLink
+ | "/@/" `isPrefixOf` text -> AtMapLink
+ | "/" `isPrefixOf` text -> AbsolutePath
+ | otherwise -> NotAPath
where
(_, prefix, rest, _) =
text =~ ("^((\\.|\\.\\.)/)*" :: Text) :: (Text, Text, Text, [Text])