[commit: ghc] master: Documentation for substringCheck. (0acd70a)

git at git.haskell.org git at git.haskell.org
Mon Jul 21 16:14:37 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/0acd70ac496daac4edd15e82bddf8a59d24f3c82/ghc

>---------------------------------------------------------------

commit 0acd70ac496daac4edd15e82bddf8a59d24f3c82
Author: Edward Z. Yang <ezyang at cs.stanford.edu>
Date:   Mon Jul 21 16:22:13 2014 +0100

    Documentation for substringCheck.
    
    Signed-off-by: Edward Z. Yang <ezyang at cs.stanford.edu>


>---------------------------------------------------------------

0acd70ac496daac4edd15e82bddf8a59d24f3c82
 utils/ghc-pkg/Main.hs | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs
index 390873a..a1f30f6 100644
--- a/utils/ghc-pkg/Main.hs
+++ b/utils/ghc-pkg/Main.hs
@@ -326,6 +326,28 @@ runit verbosity cli nonopts = do
           where splitComma "" = Nothing
                 splitComma fs = Just $ break (==',') (tail fs)
 
+        -- | Parses a glob into a predicate which tests if a string matches
+        -- the glob.  Returns Nothing if the string in question is not a glob.
+        -- At the moment, we only support globs at the beginning and/or end of
+        -- strings.  This function respects case sensitivity.
+        --
+        -- >>> fromJust (substringCheck "*") "anything"
+        -- True
+        --
+        -- >>> fromJust (substringCheck "string") "string"
+        -- True
+        --
+        -- >>> fromJust (substringCheck "*bar") "foobar"
+        -- True
+        --
+        -- >>> fromJust (substringCheck "foo*") "foobar"
+        -- True
+        --
+        -- >>> fromJust (substringCheck "*ooba*") "foobar"
+        -- True
+        --
+        -- >>> fromJust (substringCheck "f*bar") "foobar"
+        -- False
         substringCheck :: String -> Maybe (String -> Bool)
         substringCheck ""    = Nothing
         substringCheck "*"   = Just (const True)



More information about the ghc-commits mailing list