From 4969c6442ee0021e79c362effccc07343bbebebf Mon Sep 17 00:00:00 2001 From: Tissevert Date: Fri, 28 Feb 2020 18:14:27 +0100 Subject: [PATCH] Simple String aliasing to prepare the day when we'll be able to have more complex Component than just PDF Names (and access elements in an array) --- src/PDF/Object/Navigation.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/PDF/Object/Navigation.hs b/src/PDF/Object/Navigation.hs index 18a62d7..cabfeec 100644 --- a/src/PDF/Object/Navigation.hs +++ b/src/PDF/Object/Navigation.hs @@ -41,6 +41,7 @@ newtype Error a = Error { } deriving (Alternative, Functor, Applicative, Monad, MonadPlus) instance MonadFail Error where fail = Error . Left +type Component = String getDictionary :: PDFContent m => Object -> m Dictionary getDictionary (Direct (Dictionary aDict)) = return aDict @@ -64,21 +65,21 @@ objectById objectId = do layer <- ask return (objects layer ! objectId) -(./) :: PDFContent m => m Object -> String -> m Object +(./) :: PDFContent m => m Object -> Component -> m Object (./) object key = (object >>= getDictionary >>= getField key >>= castObject) where castObject (Reference (IndirectObjCoordinates {objectId})) = objectById objectId castObject directObject = return $ Direct directObject -(//) :: PDFContent m => m Object -> [String] -> m Object +(//) :: PDFContent m => m Object -> [Component] -> m Object (//) object [] = object (//) object (key:keys) = object ./ key // keys -(>./) :: PDFContent m => Object -> String -> m Object +(>./) :: PDFContent m => Object -> Component -> m Object (>./) object = (return object ./) -(>//) :: PDFContent m => Object -> [String] -> m Object +(>//) :: PDFContent m => Object -> [Component] -> m Object (>//) object = (return object //) origin :: PDFContent m => m Object