Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data FindMethods s = FindMethods {
- doesDirectoryExistDM :: s -> IO Bool
- listDirectoryDM :: s -> IO [s]
- combineDM :: s -> s -> s
- findMatches_ :: IsRegex re s => FindMethods s -> re -> s -> IO [s]
- findMatches_' :: IsRegex re s => FindMethods s -> ([s] -> [s]) -> (Match s -> Bool) -> re -> s -> IO [s]
- class Replace s => IsRegex re s where
- matchOnce :: re -> s -> Match s
- matchMany :: re -> s -> Matches s
- makeRegex :: (Functor m, Monad m, MonadFail m) => s -> m re
- makeRegexWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> s -> m re
- makeSearchReplace :: (Functor m, Monad m, MonadFail m, IsRegex re s) => s -> s -> m (SearchReplace re s)
- makeSearchReplaceWith :: (Functor m, Monad m, MonadFail m, IsRegex re s) => SimpleREOptions -> s -> s -> m (SearchReplace re s)
- makeEscaped :: (Functor m, Monad m, MonadFail m) => (s -> s) -> s -> m re
- makeEscapedWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> (s -> s) -> s -> m re
- regexSource :: re -> s
- data SearchReplace re s = SearchReplace {
- getSearch :: !re
- getTemplate :: !s
- searchReplaceAll :: IsRegex re s => SearchReplace re s -> s -> s
- searchReplaceFirst :: IsRegex re s => SearchReplace re s -> s -> s
- module Text.RE.Replace
Find
The Find toolkit traverses directory trees invoking actions for each file that matches a RE.
See the Regex Tools tutorial at http://re-tutorial-tools.regex.uk
data FindMethods s Source #
as we don't want the directory
and FilePath dependencies
we will abstract the three calls we need into this record type
FindMethods | |
|
findMatches_ :: IsRegex re s => FindMethods s -> re -> s -> IO [s] Source #
recursively list all files whose filename matches given RE,
sorting the list into ascending order; if the argument path has a
trailing /
then it will be removed
:: IsRegex re s | |
=> FindMethods s | the directory and filepath methods |
-> ([s] -> [s]) | result post-processing function |
-> (Match s -> Bool) | filtering function |
-> re | re to be matched against the leaf filename |
-> s | root directory of the search |
-> IO [s] |
recursively list all files whose filename matches given RE, using the given function to determine which matches to accept
IsRegex
class Replace s => IsRegex re s where Source #
the IsRegex
class allows polymorhic tools to be written that
will work with a variety of regex back ends and text types
matchOnce :: re -> s -> Match s Source #
finding the first match
matchMany :: re -> s -> Matches s Source #
finding all matches
makeRegex :: (Functor m, Monad m, MonadFail m) => s -> m re Source #
compiling an RE, failing if the RE is not well formed
makeRegexWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> s -> m re Source #
comiling an RE, specifying the SimpleREOptions
makeSearchReplace :: (Functor m, Monad m, MonadFail m, IsRegex re s) => s -> s -> m (SearchReplace re s) Source #
compiling a SearchReplace
template from the RE text and the template Text, failing if they are not well formed
makeSearchReplaceWith :: (Functor m, Monad m, MonadFail m, IsRegex re s) => SimpleREOptions -> s -> s -> m (SearchReplace re s) Source #
compiling a SearchReplace
template specifing the SimpleREOptions
for the RE
makeEscaped :: (Functor m, Monad m, MonadFail m) => (s -> s) -> s -> m re Source #
incorporate an escaped string into a compiled RE with the default options
makeEscapedWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> (s -> s) -> s -> m re Source #
incorporate an escaped string into a compiled RE with the specified SimpleREOptions
regexSource :: re -> s Source #
extract the text of the RE from the RE
Instances
data SearchReplace re s Source #
contains a compiled RE and replacement template
SearchReplace | |
|
Instances
Functor (SearchReplace re) Source # | |
Defined in Text.RE.ZeInternals.Types.SearchReplace fmap :: (a -> b) -> SearchReplace re a -> SearchReplace re b # (<$) :: a -> SearchReplace re b -> SearchReplace re a # | |
(Show re, Show s) => Show (SearchReplace re s) Source # | |
Defined in Text.RE.ZeInternals.Types.SearchReplace showsPrec :: Int -> SearchReplace re s -> ShowS # show :: SearchReplace re s -> String # showList :: [SearchReplace re s] -> ShowS # |
searchReplaceAll :: IsRegex re s => SearchReplace re s -> s -> s Source #
search and replace all matches in the argument text; e.g., this function will convert every YYYY-MM-DD format date in its argument text into a DD/MM/YYYY date:
searchReplaceAll [ed|${y}([0-9]{4})-0*${m}([0-9]{2})-0*${d}([0-9]{2})///${d}/${m}/${y}|]
searchReplaceFirst :: IsRegex re s => SearchReplace re s -> s -> s Source #
search and replace the first occurrence only (if any) in the input text
e.g., to prefix the first string of four hex digits in the imput text,
if any, with 0x
:
searchReplaceFirst [ed|[0-9A-Fa-f]{4}///0x$0|]
Replace
module Text.RE.Replace