From 52ab3372b8a5e3cbaf5364223ce112285ac41ed9 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 26 Nov 2008 03:46:23 +0000 Subject: [PATCH] add a regexp utility plus a dependency on regexpr, the sanest regexp library --- Ledger/Utils.hs | 10 ++++++++++ hledger.cabal | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Ledger/Utils.hs b/Ledger/Utils.hs index 0edd679bb..8f700ad9d 100644 --- a/Ledger/Utils.hs +++ b/Ledger/Utils.hs @@ -18,6 +18,7 @@ module Debug.Trace, module Ledger.Utils, module Text.Printf, module Text.Regex, +module Text.RegexPR, module Test.HUnit, module Ledger.Dates, ) @@ -36,6 +37,7 @@ import Test.HUnit -- import Test.QuickCheck hiding (test, Testable) import Text.Printf import Text.Regex +import Text.RegexPR import Text.ParserCombinators.Parsec (parse) import Ledger.Dates @@ -120,6 +122,14 @@ containsRegex r s = case matchRegex r s of Just _ -> True otherwise -> False +-- | Replace all occurrences of a regexp in string using the given replacement function +gsubRegexPRBy :: String -> (String -> String) -> String -> String +gsubRegexPRBy pat f str = + case (matchRegexPR pat str) of + Just ((match, (before,after)), _) -> before ++ f match ++ gsubRegexPRBy pat f after + Nothing -> str + + -- lists splitAtElement :: Eq a => a -> [a] -> [[a]] diff --git a/hledger.cabal b/hledger.cabal index 93a5c6f84..b8f1efb5d 100644 --- a/hledger.cabal +++ b/hledger.cabal @@ -19,7 +19,7 @@ Extra-Tmp-Files: Cabal-Version: >= 1.2 Executable hledger - Build-Depends: base, containers, haskell98, directory, parsec, regex-compat, + Build-Depends: base, containers, haskell98, directory, parsec, regex-compat, regexpr old-locale, time, HUnit Main-Is: hledger.hs Other-Modules: