fix a regexReplaceCI bug
This commit is contained in:
		
							parent
							
								
									bfedf367c4
								
							
						
					
					
						commit
						be9b637e0c
					
				| @ -32,7 +32,7 @@ module Hledger.Utils.Regex ( | |||||||
|   ,regexReplace |   ,regexReplace | ||||||
|   ,regexReplaceCI |   ,regexReplaceCI | ||||||
|   ,regexReplaceBy |   ,regexReplaceBy | ||||||
|   ,regexToCaseInsensitive |   -- ,regexpToCI | ||||||
|   ,regexSplit |   ,regexSplit | ||||||
|   ,toRegex |   ,toRegex | ||||||
|   ) |   ) | ||||||
| @ -52,9 +52,6 @@ type Replacement = String | |||||||
| containsRegex :: Regexp -> String -> Bool | containsRegex :: Regexp -> String -> Bool | ||||||
| containsRegex = regexMatchesCI | containsRegex = regexMatchesCI | ||||||
| 
 | 
 | ||||||
| regexToCaseInsensitive :: Regexp -> Regexp |  | ||||||
| regexToCaseInsensitive r = "(?i)"++ r |  | ||||||
| 
 |  | ||||||
| -- regexpr - may be slow | -- regexpr - may be slow | ||||||
| 
 | 
 | ||||||
| regexSplit :: Regexp -> String -> [Regexp] | regexSplit :: Regexp -> String -> [Regexp] | ||||||
| @ -64,19 +61,19 @@ regexSplit = splitRegexPR | |||||||
| -- regexMatch r s = matchRegexPR r s | -- regexMatch r s = matchRegexPR r s | ||||||
| 
 | 
 | ||||||
| -- regexMatchCI :: Regexp -> String -> MatchFun Maybe | -- regexMatchCI :: Regexp -> String -> MatchFun Maybe | ||||||
| -- regexMatchCI r s = regexMatch (regexToCaseInsensitive r) s | -- regexMatchCI r s = regexMatch (regexpToCI r) s | ||||||
| 
 | 
 | ||||||
| -- regexMatches :: Regexp -> String -> Bool | -- regexMatches :: Regexp -> String -> Bool | ||||||
| -- regexMatches r s = isJust $ matchRegexPR r s | -- regexMatches r s = isJust $ matchRegexPR r s | ||||||
| 
 | 
 | ||||||
| -- regexMatchesCI :: Regexp -> String -> Bool | -- regexMatchesCI :: Regexp -> String -> Bool | ||||||
| -- regexMatchesCI r s = regexMatches (regexToCaseInsensitive r) s | -- regexMatchesCI r s = regexMatches (regexpToCI r) s | ||||||
| 
 | 
 | ||||||
| -- regexReplace :: Regexp -> Replacement -> String -> String | -- regexReplace :: Regexp -> Replacement -> String -> String | ||||||
| -- regexReplace r repl s = gsubRegexPR r repl s | -- regexReplace r repl s = gsubRegexPR r repl s | ||||||
| 
 | 
 | ||||||
| -- regexReplaceCI :: Regexp -> Replacement -> String -> String | -- regexReplaceCI :: Regexp -> Replacement -> String -> String | ||||||
| -- regexReplaceCI r s = regexReplace (regexToCaseInsensitive r) s | -- regexReplaceCI r s = regexReplace (regexpToCI r) s | ||||||
| 
 | 
 | ||||||
| -- regexReplaceBy :: Regexp -> (String -> Replacement) -> String -> String | -- regexReplaceBy :: Regexp -> (String -> Replacement) -> String -> String | ||||||
| -- regexReplaceBy r replfn s = gsubRegexPRBy r replfn s | -- regexReplaceBy r replfn s = gsubRegexPRBy r replfn s | ||||||
| @ -101,18 +98,31 @@ regexMatches :: Regexp -> String -> Bool | |||||||
| regexMatches = flip (=~) | regexMatches = flip (=~) | ||||||
| 
 | 
 | ||||||
| regexMatchesCI :: Regexp -> String -> Bool | regexMatchesCI :: Regexp -> String -> Bool | ||||||
| regexMatchesCI r = match (makeRegexOpts compOpt{caseSensitive=False} execOpt r) | regexMatchesCI r = match (toRegexCI r) | ||||||
| 
 | 
 | ||||||
| regexReplace :: Regexp -> Replacement -> String -> String | regexReplace :: Regexp -> Replacement -> String -> String | ||||||
| regexReplace r repl = regexReplaceBy r (const repl) | regexReplace r repl = regexReplaceBy r (const repl) | ||||||
| 
 | 
 | ||||||
| regexReplaceCI :: Regexp -> Replacement -> String -> String | regexReplaceCI :: Regexp -> Replacement -> String -> String | ||||||
| regexReplaceCI r s = regexReplace (regexToCaseInsensitive r) s | regexReplaceCI r repl = regexReplaceByCI r (const repl) | ||||||
| 
 | 
 | ||||||
| regexReplaceBy :: Regexp -> (String -> Replacement) -> String -> String | regexReplaceBy :: Regexp -> (String -> Replacement) -> String -> String | ||||||
| regexReplaceBy r = replaceAll (toRegex r) | regexReplaceBy r = replaceAll (toRegex r) | ||||||
| 
 | 
 | ||||||
| -- from http://stackoverflow.com/questions/9071682/replacement-substition-with-haskell-regex-libraries | regexReplaceByCI :: Regexp -> (String -> Replacement) -> String -> String | ||||||
|  | regexReplaceByCI r = replaceAll (toRegexCI r) | ||||||
|  | 
 | ||||||
|  | toRegexCI :: Regexp -> Regex | ||||||
|  | toRegexCI = makeRegexOpts compOpt{caseSensitive=False} execOpt | ||||||
|  | 
 | ||||||
|  | -- regexpToCI :: Regexp -> Regexp | ||||||
|  | -- regexpToCI r = "(?i)"++ r | ||||||
|  | 
 | ||||||
|  | -- from | ||||||
|  | -- http://stackoverflow.com/questions/9071682/replacement-substition-with-haskell-regex-libraries | ||||||
|  | -- | Replace all occurrences of a regexp in a string using a replacer | ||||||
|  | -- function, which receives the matched string as its argument. | ||||||
|  | -- Does not support standard RE syntax such as \1. | ||||||
| replaceAll :: Regex -> (String -> Replacement) -> String -> String | replaceAll :: Regex -> (String -> Replacement) -> String -> String | ||||||
| replaceAll re f s = start end | replaceAll re f s = start end | ||||||
|   where |   where | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user