[project @ 2004-10-02 07:14:38 by dons]
[ghc-base.git] / Text / Regex.hs
index 62901a5..b440070 100644 (file)
@@ -6,13 +6,12 @@
 -- 
 -- Maintainer  :  libraries@haskell.org
 -- Stability   :  experimental
--- Portability :  non-portable (only on platforms that provide a regex lib)
+-- Portability :  portable
 --
 -- Regular expression matching.  Uses the POSIX regular expression
 -- interface in "Text.Regex.Posix".
 --
 -----------------------------------------------------------------------------
-
 module Text.Regex (
     -- * Regular expressions
     Regex,
@@ -24,11 +23,9 @@ module Text.Regex (
 
 import Prelude
 import qualified Text.Regex.Posix as RE
+import Text.Regex.Posix ( Regex )
 import System.IO.Unsafe
 
--- | A compiled regular expression
-type Regex = RE.Regex
-
 -- | Makes a regular expression with the default options (multi-line,
 -- case-sensitive).  The syntax of regular expressions is
 -- otherwise that of @egrep@ (i.e. POSIX \"extended\" regular
@@ -37,11 +34,11 @@ mkRegex :: String -> Regex
 mkRegex s = unsafePerformIO (RE.regcomp s RE.regExtended)
 
 -- | Makes a regular expression, where the multi-line and
--- case-sensitve options can be changed from the default settings.
+-- case-sensitive options can be changed from the default settings.
 mkRegexWithOpts
    :: String  -- ^ The regular expression to compile
-   -> Bool    -- ^ 'True' @\<=>@ '@^@' and '@$@' match the beginning and 
-             -- end of individual lines respectively, and '.' does /not/
+   -> Bool    -- ^ 'True' @\<=>@ @\'^\'@ and @\'$\'@ match the beginning and 
+             -- end of individual lines respectively, and @\'.\'@ does /not/
              -- match the newline character.
    -> Bool    -- ^ 'True' @\<=>@ matching is case-sensitive
    -> Regex   -- ^ Returns: the compiled regular expression
@@ -49,8 +46,8 @@ mkRegexWithOpts
 mkRegexWithOpts s single_line case_sensitive
    = unsafePerformIO (RE.regcomp s (RE.regExtended + newline + igcase))
    where
-       newline | single_line = 0
-               | otherwise   = RE.regNewline
+       newline | single_line = RE.regNewline
+               | otherwise   = 0
 
        igcase  | case_sensitive = 0 
                | otherwise      = RE.regIgnoreCase
@@ -81,4 +78,3 @@ matchRegexAll
                -- >         subexpression matches )
 
 matchRegexAll p str = unsafePerformIO (RE.regexec p str)
-