Safe Haskell | None |
---|---|
Language | Haskell2010 |
- 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
- 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) => s -> m re Source #
compiling an RE, failing if the RE is not well formed
makeRegexWith :: (Functor m, Monad m) => SimpleREOptions -> s -> m re Source #
comiling an RE, specifying the SimpleREOptions
makeSearchReplace :: (Functor m, Monad 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, 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) => (s -> s) -> s -> m re Source #
incorporate an escaped string into a compiled RE with the default options
makeEscapedWith :: (Functor m, Monad 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
data SearchReplace re s Source #
contains a compiled RE and replacement template
SearchReplace | |
|
Functor (SearchReplace re) Source # | |
(Show s, Show re) => Show (SearchReplace re s) Source # | |
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