From 6cecbb890f829e30e533e58287867981ca04d78a Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Tue, 25 Jan 2011 20:56:10 +0100 Subject: Add `fromCaptureString` function --- src/Hakyll/Core/Identifier/Pattern.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/Hakyll/Core/Identifier') diff --git a/src/Hakyll/Core/Identifier/Pattern.hs b/src/Hakyll/Core/Identifier/Pattern.hs index 0590387..7c88356 100644 --- a/src/Hakyll/Core/Identifier/Pattern.hs +++ b/src/Hakyll/Core/Identifier/Pattern.hs @@ -35,6 +35,7 @@ module Hakyll.Core.Identifier.Pattern , doesMatch , matches , fromCapture + , fromCaptureString , fromCaptures ) where @@ -122,9 +123,29 @@ match' (m : ms) (s : ss) = case m of -- | Create an identifier from a pattern by filling in the captures with a given -- string -- +-- Example: +-- +-- > fromCapture (parsePattern "tags/*") (parseIdentifier "foo") +-- +-- Result: +-- +-- > "tags/foo" +-- fromCapture :: Pattern -> Identifier -> Identifier fromCapture pattern = fromCaptures pattern . repeat +-- | Simplified version of 'fromCapture' which takes a 'String' instead of an +-- 'Identifier' +-- +-- > fromCaptureString (parsePattern "tags/*") "foo" +-- +-- Result: +-- +-- > "tags/foo" +-- +fromCaptureString :: Pattern -> String -> Identifier +fromCaptureString pattern = fromCapture pattern . parseIdentifier + -- | Create an identifier from a pattern by filling in the captures with the -- given list of strings -- -- cgit v1.2.3